GetScriptParam(string)

From NWN Lexicon
Revision as of 22:41, 29 July 2020 by Jasperre (talk | contribs) (Created page with "{{DISPLAYTITLE:GetScriptParam(string)}}__NOTOC__ Returns the script parameter value for a given parameter name. <nwscript> void GetScriptParam( string sParamName ); </nwsc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Returns the script parameter value for a given parameter name.

void GetScriptParam(
    string sParamName
);

Parameters

sParamName
The script parameter to retrieve

Description

Returns the script parameter value for a given parameter name.

Script parameters can be set for conversation scripts in the toolset's Conversation Editor, or for any script with SetScriptParam.

Will return "" if a parameter with the given name does not exist.

Remarks

This integrates well into the toolset changes in the patch which introduce a way to add variables to pass to scripts. This makes hundreds, if not thousands, of conditional and action scripts in conversations a thing of the past. A simple example is provided below.

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.

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
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:

SetScriptParam