Conversation Action Script

From NWN Lexicon
Jump to: navigation, search

A conversation node can have a action script attached under the Actions Taken panel of the conversation editor in the toolset.


Trigger

If the node is selected (or chosen by the game for an NPC to respond with) the Action script will fire.


Function(s)

  • GetScriptParam will be able to retrieve any parameters set on the conversation node
  • GetPCSpeaker the PC who is conversing with the NPC
  • OBJECT_SELF is the NPC who is conversing with the player, or it will be the player themselves if they're talking to themselves.


Remarks

The clever use of GetScriptParam can now cut down the amount of conversation action scripts dramatically. See the function for some examples.

The action script should be combined with a Conversation Conditional Script when giving quest rewards. For instance if you only check the PC conditional node for the quest item, they can drop it inbetween it appearing and it being selected, meaning the reward is granted when the item isn't present, possibly leading to abuse for XP or rewards or creating breaking game bugs (eg; 2 separate quest givers having the item "given" to them).


Example

// Example of a multi-use script for conversation actions.
// We will do several things to the PC speaker based on the parameters passed in. More than one can happen at once:
// * hostile = If set to anything, we attack
// * gold = we grant them this amount of gold
// * xp = we grant them this amount of xp
// * item = we create 1 of this item on them
void main()
{
    object oPC = GetPCSpeaker();
 
    // Check each parameter in turn (we could have more than one)
    string sParameter = GetScriptParam("hostile");
    if(sParameter != "")
    {
        SetIsTemporaryEnemy(oPC);
        ActionAttack(oPC);
    }
    sParameter = GetScriptParam("gold");
    if(sParameter != "")
    {
        GiveGoldToCreature(oPC, StringToInt(sParameter));
    }
    sParameter = GetScriptParam("xp");
    if(sParameter != "")
    {
        GiveXPToCreature(oPC, StringToInt(sParameter));
    }
    sParameter = GetScriptParam("item");
    if(sParameter != "")
    {
        object oItem = CreateItemOnObject(sParameter, oPC, 1);
        if(!GetIsObjectValid(oItem))
        {
            SpeakString("ERROR: Item parameter invalid: " + sParameter, TALKVOLUME_SHOUT);
        }
    }
}

See Also

functions:

GetScriptParam