Commonly Asked Neverwinter Scripting Questions
Total Page:16
File Type:pdf, Size:1020Kb
COMMONLY ASKED QUESTIONS. – By David Gaider (BIOWARE) COMPILED BY: Elmer The Destroyer (AKA Preston M.) Last Updated: Tuesday, July 02, 2002 I felt this document could help some people out it’s actually a post but this is a bit more readable and printable. This was taken verbatim from the sticky post on the NWN website. I did this in a couple minutes sorry if its not perfect o Animations o Waypoints o The userdefined event is your friend o Creating objects o Rewarding gold and XP o Making skill checks o Making unique items o Finding an object o Setting variables o A simple example quest dialogue o How do I make NPC’s initiate dialogue on their own o Using the Trigger Method for starting a Conversation o How do I make my NPC attack the PC he is talking to? o Using module events o Module Event List I know that there are plans to post some more scripting information for you all to digest. For the moment, however, there are some basic questions that seem to be commonly repeated in the forum. I'm going to post some information I put up previously on the NWVault scripting forum found at this site as well as some other basic stuff for people to peruse. ---------- If you see a question that gets repeated a lot or a problem that comes up a lot that bears notice here, please send me a message and I will get it up, here. When the official information is put up, then this thread can be removed. NOTE: Should I make an error somewhere (god forbid ) or if something is not very clear in its wording, please let me know. 1 REGARDING ANIMATIONS You basically have two choices when adding animations to your creatures in the game. Adding them directly or using the automatic functions in the generic AI. Adding Animations Directly The first thing to realize when you are dealing with scripting animations is that not all creatures have all animations. As a rule of thumb, if the creature is a PC race (human, elf, dwarf, half-orc, gnome or halfling), then it will have all the animations. If the creature is a humanoid monster (bugbear, goblin, etc.) then very likely it has most if not all animations. Non-humanoid monsters and especially birds will be very limited in their animations. The Action Queue The second thing to know when scripting animations is how to use the action queue. There are a number of scripting commands which start with the word 'Action'... when a creature calls these commands on themselves, it places the action into a queue. It will finish one action completely and then move onto the next in line... up until the point there are no more actions or a ClearAllActions() command is issued. The reason this is important is that there are two main commands that deal with animations: ActionPlayAnimation and just PlayAnimation. ActionPlayAnimation places the command to perform the animation in the queue... PlayAnimation tells the creature to do the animation immediately as soon as it is reached in the script, overriding anything else going on in the queue. If I wanted to script someone to move to a particular waypoint and then meditate for 6 seconds, it would look like this: NWScript: void main() { object oTarget = GetNearestObjectByTag("WAYPOINT1"); ActionMoveToObject(oTarget); ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE, 1.0, 6.0); } 2 The creature would then move to the waypoint and wait until he got there before he began playing his meditation animation. If I wanted to set a variable when he was finished all that, I would also have to add it into the queue. You can do this with the ActionDoCommand(). This places a non-Action command into the queue. NWScript: void main() { object oTarget = GetNearestObjectByTag("WAYPOINT1"); ActionMoveToObject(oTarget); ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE, 1.0, 6.0); ActionDoCommand(SetLocalInt OBJECT_SELF, "Done_Meditation", 1); } If I did the SetLocalInt command without putting it into the queue, then it would fire as soon as that point in the script was reached... probably well before the creature even reached the waypoint. The two commands for animations are as follows: void ActionPlayAnimation (int nAnimation, float fSpeed=1.0, float fSeconds=0.0) - The 'nAnimation' is Constant for the animation being played. - 'fSpeed' is the speed at which the animation is played... you could have a creature turn its head very slowly or very quickly, for instance... 1.0 is normal speed. - 'fSeconds' is only used for looping animations (like the meditation)... it determines how long you wish the animation to be played. If left blank on a looping animation, it will play that animation until told to do something else. void PlayAnimation (int nAnimation, float fSpeed=1.0, float fSeconds=0.0) As mentioned, this is the same as the ActionPlayAnimation command, except that the animation is not placed in the queue... it is played immediately. Animation Constants You can find a list of all the animation constants (used in the 'nAnimation' portion of the command) by selecting the 'Constants' button in your script editor... all the constants begin with ANIMATION_*. 3 There are two types of animations: 'fire-and-forget' (or FNF), which only plays once and no duration is needed, and 'looping' which play as long as needed and a duration is required for. A reminder once again: NOT ALL MODELS HAVE ALL ANIMATIONS. Just to mention, too, that the animations listed in the constants are not every animation that a model is capable of (there is a dying animation, after all, as well as combat animations and others)... this is just the current list of the ones that can be played via script. (continued from above) Using Generic AI Animations For a quick and easy solution to adding some life to your placed creatures, the generic AI has two functions that you can use. In the generic OnSpawn script ("nw_c2_default9"), there is a whole list of commands that are all commented out (they are preceded with a '//' double slash that colors them green and prevents them from being compiled). To use the built- in animations, you simply need to comment back in (remove the '//') one of the following commands: NWScript: SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS); SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATI ONS); Don't worry about the comments that are on the same line with these commands... that just tells what they do. Simply erase the double-slash at the beginning of the line. Then you re-compile the script and save it as a different file. And that's it... that's all you have to do. What do these do? Basically they are called in the OnHeartbeat event (meaning the script will 'activate' every 6 seconds). The script checks to make sure that the creature is not asleep, not in combat, not in conversation and no enemy is in sight... if all those are okay, it plays the animations. 4 'ambient animations' means that the creature will move about randomly, occasionally stopping to turn to nearby friends (creatures with a friendly reputation) and play what social animations it has (and, yes, this will work on any type of creature.. it will do what it can for those creatures who don't have the full range). 'immobile ambient animation' does the same thing... without the random movement. The creature stays in place. So you can put down several of these types of creatures, for instance, and they will turn to each other at random intervals and seem to chat, laugh, argue... and even mill around and mingle, with the ambient animations. Do the placeable object animations work the same way? Yes. You can tell a chest to open by having it run its ANIMATION_PLACEABLE_OPEN, or a lamp post to turn off using ANIMATION_PLACEABLE_DEACTIVATE. A few things to keep in mind: 1) For placeable objects that are sources of illumination (such as the lamp post), it is not enough to just use its ANIMATION_PLACEABLE_DEACTIVATE or ANIMATION_PLACEABLE_ACTIVATE. That just affects the glowing part of the animation, itself. You must also use the SetPlaceableIllumination command set to TRUE and tell the area it's in to RecomputeStaticLighting. The following is an example of placeable illumination use: NWScript: // will turn the lightable object on and off when selected // placed in its OnUsed event void main() { if (GetLocalInt (OBJECT_SELF,"NW_L_AMION") == 0) { SetLocalInt (OBJECT_SELF,"NW_L_AMION",1); PlayAnimation (ANIMATION_PLACEABLE_ACTIVATE); SetPlaceableIllumination (OBJECT_SELF, TRUE); RecomputeStaticLighting (GetArea(OBJECT_SELF)); } else { SetLocalInt (OBJECT_SELF,"NW_L_AMION",0); PlayAnimation (ANIMATION_PLACEABLE_DEACTIVATE); SetPlaceableIllumination (OBJECT_SELF, FALSE); RecomputeStaticLighting (GetArea(OBJECT_SELF)); 5 } } 2) Doors are not placeable objects. First thing you should know about them is that if the door is unlocked, a creature who is told to move to a point on the other side of one will automatically open it. Bayond that, the commands for doors are as follows: - ActionOpenDoor: If used in the script of a creature, it will move to the door and open it (if it is unlocked). If used in the script of the door (or the command is sent to the door object via AssignCommand), then the door will open itself. - ActionCloseDoor: As above, only the door is closed. - ActionLockObject: If used in the script of a creature, it will move to the object (can be a door or placeable) and attempt to use its Open Locks skill to unlock it. ONLY call it in the script of a creature! - ActionUnlockObject: As above, except the door or object is unlocked. - SetLocked: This is the command you use if you want a door or object to be set to locked or unlocked without the aid of a creature or skill. If 'bLocked' is set to TRUE, the object will be locked..