Difference between revisions of "Event override"

From Dragon Age Toolset Wiki
Jump to: navigation, search
m (Category:Events)
m (dascript tags)
Line 53: Line 53:
 
For example i want to have a screen-message every time i pick up an item (or steal one):
 
For example i want to have a screen-message every time i pick up an item (or steal one):
  
<pre>
+
<dascript>
 
// --- script start ---
 
// --- script start ---
 
// file: my_event_override.nss
 
// file: my_event_override.nss
Line 85: Line 85:
  
 
// --- script end ---
 
// --- script end ---
</pre>
+
</dascript>
  
 
[[Category:Events]]
 
[[Category:Events]]

Revision as of 01:08, 19 January 2010

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