1. SPS Accounts:
    Do you find yourself coming back time after time? Do you appreciate the ongoing hard work to keep this community focused and successful in its mission? Please consider supporting us by upgrading to an SPS Account. Besides the warm and fuzzy feeling that comes from supporting a good cause, you'll also get a significant number of ever-expanding perks and benefits on the site and the forums. Click here to find out more.
    Dismiss Notice
Dismiss Notice
You are currently viewing Boards o' Magick as a guest, but you can register an account here. Registration is fast, easy and free. Once registered you will have access to search the forums, create and respond to threads, PM other members, upload screenshots and access many other features unavailable to guests.

BoM cultivates a friendly and welcoming atmosphere. We have been aiming for quality over quantity with our forums from their inception, and believe that this distinction is truly tangible and valued by our members. We'd love to have you join us today!

(If you have any problems with the registration process or your account login, please contact us. If you've forgotten your username or password, click here.)

Script Wizard

Discussion in 'Neverwinter Nights (Classic)' started by Steeze, Jan 25, 2006.

  1. Steeze Gems: 10/31
    Latest gem: Zircon


    Joined:
    Oct 19, 2004
    Messages:
    374
    Likes Received:
    0
    [​IMG] Hey. I've been playing around with the toolset awhile now and I think i've got most of the basic things down and can do them pretty easily. So now i've started playing with the script wizard, i've done a few things like get said item and your journal is updated, but I had help with that aswell. So just asking for any tips or pointers in the script wizrd. Or if you wanted to you could post (or PM) me a detailed message telling me alot or everything about it :p that would be great.
     
  2. Alavin

    Alavin If I wanted your view, I'd read your entrails Veteran

    Joined:
    Aug 26, 2003
    Messages:
    930
    Likes Received:
    0
    Explaining the whole of the script editor would take a very long time. But I can explain the most important stuff, and understanding that will make the rest of it easier to work out through experimentation.

    Data Types

    Integers (int): whole numbers.
    Floats: real numbers; ie they have a decimal point, even if it's just .0 on the end.
    Strings: a length of characters. They are placed withing " ". They have no numerical value by default.
    Booleans: either TRUE or FALSE. The two states must be in caps for it to work. If they go blue, it's fine. They are much like integers, with 1 as True and 0 as False.
    Objects: physical parts of your module, such as creatures, placeables and waypoints.
    Effects: as implied. An effect on an object.
    Locations: an area of the module, anything from a single point to a large area.

    Assigning objects in scripts

    <Type> <Name> = <Identifier>;
    Type: as above. This can be int, float, string or object. Booleans, as implied above, come under int.

    Name: a name for the object. It has to be unique to this script, but the same name can be used for different things in different scripts.

    Identifier: something that returns a value of the type. The return is the first word in the function description, for example:
    int GetAC(object oObject, int nForFutureUse=0)
    returns an integer.

    The <>s are not necessary, but the ; is!

    An example:

    object oCharacter = GetObjectByTag("Character");

    Understanding Function Documentation

    When you click on a function in the menu on the right, the information about it will appear at the bottom. It's very important to read this, since it tells you the order the information you pass in should be, and what types are needed.

    Example:

    object CreateObject(int nObjectType, string sTemplate, location lLocation, int bUseAppearAnimation=FALSE, string sNewTag="")

    int nObjectType: From reading the text above, you'll see it needs a constant of the appropriate type. There's no real need to go into them; it tells you all the options you have. Just click the Constants tab and select the one you want.

    string sTemplate: A string representing the template of the object, also often referred to as the resref. Put it in ""s.

    location lLocation: Where the object should appear.

    int bUseAppearAnimation=FALSE: Note the equals sign. If you don't assign it a value, this is what it will default to. If it has no equals sign, something is required.

    string sNewTag="": As above.

    So, if I wanted to create a creature with template "monster" at the waypoint "Here", I would type
    CreateObject(OBJECT_TYPE_CREATURE, "monster", GetLocation(GetWaypointByTag("HERE")));

    It's fine to put functions inside each other, as long as the inputs fulfil the requirements.

    Variables

    One of the most important bits. These are values that are attached to various objects that are stored persistently within a module; that is, when the scripts stop running, the value stands. There are three types of variables that can be assigned: integers (assigned by SetLocalInt), strings (SetLocalString) and floats (SetLocalFloat). Floats are just real numbers; ie they contain a decimal point.

    That was all just waffle. If it made no sense to you, it doesn't really matter. This matters though:

    To set an integer on an object, use the SetLocalInt function. The editor tells you its parameters:
    SetLocalInt(object oObject, string sVarName, int nValue)
    The oObject is the thing you're assigning the variable to.
    sVarName is the name you've assigned to it. Do not use the same VarName unless you really intend to overwrite the variable already assigned.
    nValue: The value of the variable.

    I hope I'm not understating their importance. An example of their use is in conversation. When you speak to an NPC for the first time, set a variable on the PC saying that they've spoken to him. Then, when they return, check that variable (with GetLocalInt) and if it's been set that they've already met, the NPC can make a different reply.

    ***

    I know that doesn't cover everything. Barely a fraction, really. But it's a hard thing to explain to someone completely new to scripting. The best thing to do would be to mess around with it, and just try to accomplish things. It's what I did; I almost completely self-taught myself over two years through experimentation. And as a result I'm on the fast-track programme for java in my university. NWN is helping with my education. :)

    I've probably completely dissuaded you from ever scripting again. :) But it's really the basics that are hardest to grasp. Once you understand why things work, it's much easier to do it yourself. If you do decide to continue, post here, or send me a PM, and I'll be happy to help you.

    EDIT: Well, that's my longest post ever...
     
  3. Steeze Gems: 10/31
    Latest gem: Zircon


    Joined:
    Oct 19, 2004
    Messages:
    374
    Likes Received:
    0
    Thanks Alavin, just skimmed throught the post (i'll have to read it all later) but it looks very helpful, just what I was looking for I think.
     
  4. Alavin

    Alavin If I wanted your view, I'd read your entrails Veteran

    Joined:
    Aug 26, 2003
    Messages:
    930
    Likes Received:
    0
    Please, tell me if that's too confusing or whatever. I've not tried to explain the basics before. And, really, don't give up if it is too confusing. Scripting's a lot of fun, and I can clarify bits you don't get.
     
  5. Steeze Gems: 10/31
    Latest gem: Zircon


    Joined:
    Oct 19, 2004
    Messages:
    374
    Likes Received:
    0
    Hmm well I've read through it now and it is a bit confusing, but i'm just picking through it slowly. Could you try to clarify the varibles more please.
     
  6. Alavin

    Alavin If I wanted your view, I'd read your entrails Veteran

    Joined:
    Aug 26, 2003
    Messages:
    930
    Likes Received:
    0
    Variables are just bits of data that are attached to objects. They're either integers, strings or floats, and they exist to be read later by another script.

    SetLocalInt(GetPCSpeaker(), "Talked", 1) will set a variable of name "Talked" to one on the PC who is in the conversation that calls the script.
    GetLocalInt(GetPCSpeaker(), "Talked") would return the value 1.
    This is useful for If statements.

    if(GetLocalInt(GetPCSpeaker(), "Talked") == 1)
    return TRUE;
    else return FALSE;

    This is an example of a script that can be used in a conversation to check when a particular chain of dialogue should be executed. When Talked is 1, the chain is activated, or ignored when it's not. Although it's slightly off the subject, remember that in the line of an If statement, there's no ; at the end. The same goes for While and For statements.

    If there is a variable called Talked already when you try to set it as something else, it will be overwritten. The default value is always 0, so if you haven't set a variable when you call it, that's what it'll be.

    SetLocalFloat(GetFirstPC(), "Var", 1.5) is an example of setting a float variable.
    SetLocalString(GetFirstPC(), "Var", "String") is an example of setting a string variable.

    I hope that's explained better. I've written a 2000 line morale system for my RTS module, and most of it is just checking and setting variables. They're very important, so if that's still not clear, please tell me.
     
  7. Steeze Gems: 10/31
    Latest gem: Zircon


    Joined:
    Oct 19, 2004
    Messages:
    374
    Likes Received:
    0
    sorry, but no. They seem to be what i'm stuck on. Could you give me an example of how I would use them if I wanted to make a dialouge where when you first talked to the character he would give you a quest, but after that just greet you? If you get me.
     
  8. Alavin

    Alavin If I wanted your view, I'd read your entrails Veteran

    Joined:
    Aug 26, 2003
    Messages:
    930
    Likes Received:
    0
    In the conversation editor, go to the part where the character accepts the quest, and type in the Actions Taken field, click the Edit button (this can all be done in the wizard, denoted by the hat, but it's better to write it yourself - less ugly junk), and type (within the curly brackets)

    SetLocalInt(GetPCSpeaker(), "QuestAccept", 1);

    For the dialogue you want to fire after the quest is accepted, go to the new dialogue's root node and, under Text Appears When type

    if(GetLocalInt(GetPCSpeaker(), "QuestAccept") == 1)
    return TRUE;
    else return FALSE;

    And that should work.
     
  9. Late Gems: 4/31
    Latest gem: Sunstone


    Joined:
    Mar 6, 2006
    Messages:
    81
    Media:
    1
    Likes Received:
    0
    http://www.nwnlexicon.com holds VERY useful tutorials, especially Celowin's tutorials can teach even those not familiar with any scripting. Take the lyceum link from the upper right corner.
     
Sorcerer's Place is a project run entirely by fans and for fans. Maintaining Sorcerer's Place and a stable environment for all our hosted sites requires a substantial amount of our time and funds on a regular basis, so please consider supporting us to keep the site up & running smoothly. Thank you!

Sorcerers.net is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on amazon.com, amazon.ca and amazon.co.uk. Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.