Event override

From Dragon Age Toolset Wiki
Revision as of 11:19, 15 February 2011 by Proleric1 (Talk | contribs)

Jump to: navigation, search
Scripting

How to override an event?

Via a wrapper script

The safest and most common way to override an event is to create an event script for the resource whose event-handling you want to override, and use that script to handle the specific event you want to override while passing on all other events to the core script to handle.

For example, if you have a creature called a "Death Tyrant" that does something special when it receives EVENT_TYPE_DEATH, you could create a script named death_tyrant_events with the following layout:

#include "utility_h"
#include "wrappers_h" 
#include "events_h"
 
void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    string sDebug;     
    object oPC = GetHero();
    object oParty = GetParty(oPC);   
    int nEventHandled = FALSE;
 
    switch(nEventType)
    {
         case EVENT_TYPE_DEATH:
         {
             ...
             nEventHandled = TRUE; //set this if no further action is required for this event
             break;
         }
    }
    if (!nEventHandled) //If this event wasn't handled by this script, let the core script try
    {
        HandleEvent(ev, RESOURCE_SCRIPT_CREATURE_CORE);
    }
}

And set this script as the event-handling script for Death Tyrants. When the game sends the Death Tyrant any event other than EVENT_TYPE_DEATH, it'll get sent to the core creature_core event-handling script by the function call HandleEvent(ev, RESOURCE_SCRIPT_CREATURE_CORE). EVENT_TYPE_DEATH, on the other hand, will get intercepted and handled by your own code.

Via the Events 2DA

This is how you can do the same thing on a global scale, catching and overriding an event for all resources in the game.

Create a Events M2DA File - for instructions look here:

Events.png

In this case i used the "EVENT_TYPE_INVENTORY_ADDED" Event and Handle it in my custom Event-Handler-Script: my_event_override

Now just handle the event in your script as you like.

For example i want to have a screen-message every time i pick up an item (or steal one):

// --- script start ---
// file: my_event_override.nss
// author: Pheelon
 
#include "utility_h"
#include "wrappers_h"
#include "events_h"
void main()
{
    event ev   = GetCurrentEvent();
    int nEvent = GetEventType(ev);
    object oOwner = GetEventCreator(ev);
 
    switch (nEvent)
    {
        case EVENT_TYPE_INVENTORY_ADDED:
        {
            object oItem = GetEventObject(ev, 0);
            if (IsPartyMember(oOwner)) // only show if the item went into the player's inventory
            {
                DisplayFloatyMessage(oOwner, GetName(oItem) + " added", FLOATY_MESSAGE, 14654488, 10.0);
            }
            //Now we didn't handle the event itself but just displayed a floaty --> let the original event handler take over.
            HandleEvent(ev); // this passes the event to the default handler of the event's target object
            break;
        }
 
    }
}
 
// --- script end ---

Note that the "default handler" is the script specified on the resource template. So, even if events.xls is used to make a global change, HandleEvent(ev) ensures that any custom script on an object template is still executed.

This is especially useful for compatibility purposes. If mods that affect all campaigns use events.xls, while custom campaigns use custom scripts on resource templates, the two can coexist.

Language: English  • русский