Difference between revisions of "GetCurrentlyRunningEvent"

From NWN Lexicon
Jump to: navigation, search
(Example)
m
Line 2: Line 2:
 
Retrieves the currently running event.
 
Retrieves the currently running event.
 
<nwscript>
 
<nwscript>
void GetCurrentlyRunningEvent();
+
int GetCurrentlyRunningEvent();
 
</nwscript>
 
</nwscript>
  

Revision as of 16:54, 27 May 2021

Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.

Retrieves the currently running event.

int GetCurrentlyRunningEvent();

Description

Returns the currently executing event (EVENT_SCRIPT_*) or 0 if not determinable.

Note: Will return 0 in DelayCommand/AssignCommand. ExecuteScript/ExecuteScriptChunk will inherit their event ID from their parent event.


Remarks

This can be useful for determining the event the script is running from to have one script be used for multiple events; this really helps simplify some systems so you only have 1 script to edit not 10 (eg; treasure generation, such as the below example).

These scripts types cannot be retrieved since they're not true events:

  • Conversation: Action
  • Conversation: Conditional
  • Spell Script
  • Disease payload
  • nwscript console run scripts
  • Console dm_runscript run scripts


Version

This function was added in 1.83.8193.21 of NWN:EE.


Example

// Script for both OnOpen and OnDeath
// Generate treasure in the case of opening (after it's unlocked) OR destruction, but if destroyed only generate half
// Only do this once - track with a local
void main()
{
    // Don't generate twice
    if(GetLocalInt(OBJECT_SELF, "DONE_LOOT")) return;
    SetLocalInt(OBJECT_SELF, "DONE_LOOT", TRUE);
 
    // Generate 3d20 gold
    int nGoldAmount = d20(3);
 
    int nEvent = GetCurrentlyRunningEvent();
    if(nEvent == EVENT_SCRIPT_PLACEABLE_ON_DEATH)
    {
        // Half amount
        nGoldAmount /= 2;
 
        // Feed back damage to killer
        SendMessageToPC(GetLastKiller(), "Your reckless destruction of " + GetName(OBJECT_SELF) + " has damaged some of the contents.");
    }
 
    // Create the gold
    CreateItemOnObject("nw_it_gold001", OBJECT_SELF, nGoldAmount);
}

See Also

functions:

DelayCommand

AssignCommand

ExecuteScript

ExecuteScriptChunk

constants:

EVENT_SCRIPT_*

events: