Neverwinter Nights Forum Update
Posted Friday, June 28, 2002 - 19:27 CET by Z-Layrex

David Gaider, Designer

Templates: I think that's one of the scripts used for the generic script templates. There are a number of templates which we used which form an easy base for a number of basic quests... there's a fetch quest, rescue quest, assassination quest, etc. These have template dialogues, template NPCs and use a set of scripts which you will see all over the script database (nw_c2_assvict1 for the assassination victim, nw_d2_j_assa01 for one of the assassination plotgiver's dialog scripts, nw_d2_j_fetch01 for one of the fetch plotiver's dialog scripts, etc.) These scripts are set up to work in a very specific manner, with the user only needing to plug values in a few places and adjust the template dialogue to suit them. They won't work well otherwise... that escort script, for example, is setting a variable which is looked for by the rescued prisoner's template dialogue file. Not much use to you unless you have that. The description on the script should probably mention that it's not a general 'follow the PC' script and just for a specific plot where an NPC follows the PC, but it's not incorrect. (Incidentally, I imagine these template plots are being prepped-up with sufficient documentation and will be released for you all to use at some point. I don't know that for sure, but it'd be a waste of all the work we did on 'em otherwise.)

Follow Scripts: I don't know how to do follow scripts, I'm afraid. We used to have an ActionFollow command, but it was probably taken out because it didn't work very well. All I could suggest is that you use the OnHeartbeat event to have the NPC check if GetDistanceToObject (the PC) is greater than a certain amount... if so, then ActionMoveToObject.Might also want to add in there, that if that distance becomes too large, then ActionJumpToObject (like the henchmen do sometimes). Otherwise, I'd suggest opening up the henchmen scripts and see how they follow.

Generic AI: I wouldn't suggest altering the generic AI include unless you really, really have to. It shouldn't be necessary, anyway. If you go into your NPC's OnSpawn script, copy it and save it under a different name. Then uncomment the line 'SetSpawnInCondition (NW_FLAG_ON_DIALOGUE_EVENT);' and recompile the script. This sets up your NPC to fire a UserDefinedEvent # 1004 whenever someone 'shouts' near him. Now if I wanted that NPC to respond to the shout 'Come Here' when stated by the NPC's PC master (the identity of which is stored in an object variable on the NPC), I have to do the following:

1) First, you need to tell your NPC which verbal commands to listen to. This would be added to the OnSpawn script using the SetListenPattern command.

2) Then, in the OnUserDefined script, you want to GetListenPatternNumber() and see if it matches up with the integer set in the OnSpawn.

So, for 'Come Here', I'd need to make sure that the proper SetSpawnInCondition line was uncommented for the OnDialogue event and the following line added:

SetListenPattern (OBJECT_SELF, "Come Here", 100);

Then I could add this as my OnUserDefined script:

void main()
{
int nEvent = GetUserDefinedEventNumber();
if (nEvent == 1004) // OnDialogue Event
{
int nMatch = GetListenPatternNumber();
object oMaster = GetLocalInt(OBJECT_SELF, "Master");
object oShouter = GetLastSpeaker();
if(nMatch != -1 && GetIsObjectValid(oShouter) && GetIsPC(oShouter) && (oShouter == oMaster))
{
if (nMatch == 100) // Come Here: NPC moves to PC
{
ClearAllActions();
ActionMoveToObject(oShouter, TRUE, 2.0);
}
}
}
}


Sharing Variables: First you have to use a SetLocal command to actually set the variable on an object... then you can use a GetLocal command from any script to retrieve it. Let's say you wanted to set the "Alive" string variable to be equal to the PC's name (not sure why you're using GetAttackTarget, but I'll go with that). Let's say you want it to be set module-wide. You would set it by doing this:

SetLocalString (GetModule(), "Alive", GetName(OBJECT_SELF));

Then from any other script, you could retrieve that string from the module:

GetLocalString (GetModule(), "Alive");

Generally, however, when getting a variable, you want to use it in the context of a definition:

string sName = GetLocalString (GetModule(), "Alive");

That way in the new script the variable sName would be equal to the name of the PC in the original script.

Scripting: If I wanted a wolf to flee when it reached a certain damage point:

1) Copy it's OnSpawn script and re-save it under a new name. Uncomment the 'OnDamaged' flag (the 'SetSpawnInCondition (NW_FLAG_DAMAGED_EVENT);' line).

2) In the OnUserDefined section, put a script that does something like the following:

(nwscript)
void main()
{
int nEvent = GetUserDefinedEventNumber();
if (nEvent == 1006) // OnDamaged event
{
int nCurHP = GetCurrentHitPoints();
int nMaxHP = GetMaxHitPoints();
if ((nMaxHP/2) < nCurHP) // if at less that 50% HP
{
// clear actions and flee to exit waypoint
ClearAllActions();
ActionMoveToObject (GetWaypointByTag("oExit"), TRUE);
// don't accept any more input from AI scripts
SetCommandable (FALSE);
}
}
}


Custom Tokens:

Quote: i.e. You have a SetCustomToken( int nToken, string sText ), but no GetCustomToken(int nToken). Can I, instead call GetLocalInt(GetModule(), "CUSTOM" + nToken), or is there some other cunning incantation?

No, there is no GetCustomToken. Custom tokens are only for use in dialogue. Once set, they are global, but it's up to you to track what custom tokens you have.


Dragons: It should be easier to use the special abilities in possession with the 1.19 patch (and the regular AI should have your creatures using them normally, as well). Would have been nice to have the DM faction/PvP bug fixed for 1.19, as well, but we're still working on it. That one's a very high priority to get fixed asap.


Name:
Email:
Password:
Comment: