Difference between revisions of "SetScriptParam"

From NWN Lexicon
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:SetScriptParam(string, string)}}__NOTOC__ Set a script parameter value for the next script to be run. <nwscript> void GetScriptParam( string sParamName,...")
 
Line 26: Line 26:
 
This gives even more power to the toolset integrations into the toolset, since a general purpose script can be used in a conversation (a usual default) but a parameter could be set beforehand to use it in other ways, for instance rewarding a PC with gold an experience.
 
This gives even more power to the toolset integrations into the toolset, since a general purpose script can be used in a conversation (a usual default) but a parameter could be set beforehand to use it in other ways, for instance rewarding a PC with gold an experience.
  
Given [[SetScriptParam]] it also allows a single script to be reused with [[ExecuteScript]]. For instance you can have a quest reward script that tests a parameter for if it is in a conversation or not - eg: GetScriptParam("NO_CONVERSATION") - and if it detects it acts as if the object it is being executed on, or some other person (eg: an object stored in a variable), is to be referenced instead of [[GetPCSpeaker]] for, say, rewarding experience or advancing a quest. See example below.
+
For instance as in the example below you can have a quest reward script that tests a parameter for if it is in a conversation or not - eg: GetScriptParam("NO_CONVERSATION") - and if it detects it acts as if the object it is being executed on, or some other person (eg: an object stored in a variable), is to be referenced instead of [[GetPCSpeaker]] for, say, rewarding experience or advancing a quest. See example below.
  
 
===Version===
 
===Version===
Line 50: Line 50:
 
         // (PC's don't have a tag so we can't GetObjectByTag(GetScriptParam()) here)
 
         // (PC's don't have a tag so we can't GetObjectByTag(GetScriptParam()) here)
 
         oPC = GetLocalObject(OBJECT_SELF, "TARGET");
 
         oPC = GetLocalObject(OBJECT_SELF, "TARGET");
 +
        // If not valid we assume the thing it is executed on is the target
 +
        if(!GetIsObjectValid(oPC)) oPC = OBJECT_SELF;
 
     }
 
     }
 
     else
 
     else

Revision as of 23:03, 29 July 2020

Set a script parameter value for the next script to be run.

void GetScriptParam(
    string sParamName,
    string sParamValue
);

Parameters

sParamName
The script parameter to set
sParamValue
The value to set sParamName to

Description

Set a script parameter value for the next script to be run.

Call this function to set parameters right before calling ExecuteScript.

Remarks

This gives even more power to the toolset integrations into the toolset, since a general purpose script can be used in a conversation (a usual default) but a parameter could be set beforehand to use it in other ways, for instance rewarding a PC with gold an experience.

For instance as in the example below you can have a quest reward script that tests a parameter for if it is in a conversation or not - eg: GetScriptParam("NO_CONVERSATION") - and if it detects it acts as if the object it is being executed on, or some other person (eg: an object stored in a variable), is to be referenced instead of GetPCSpeaker for, say, rewarding experience or advancing a quest. See example below.

Version

This function was added in 1.80.8193.14 of NWN:EE.

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
// If "NO_CONVERSATION" is set we instead use the variable "TARGET" on ourselves to target the object retrieved.
void main()
{
    object oPC;
    if(GetScriptParam("NO_CONVERSATION") != "")
    {
        // Get local object to use which should have been set just before executing this script
        // (PC's don't have a tag so we can't GetObjectByTag(GetScriptParam()) here)
        oPC = GetLocalObject(OBJECT_SELF, "TARGET");
        // If not valid we assume the thing it is executed on is the target
        if(!GetIsObjectValid(oPC)) oPC = OBJECT_SELF;
    }
    else
    {
        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:

SetScriptParam