Difference between revisions of "Event override"

From Dragon Age Toolset Wiki
Jump to: navigation, search
m
Line 38: Line 38:
 
                 DisplayFloatyMessage(oOwner, GetName(oItem) + " added", FLOATY_MESSAGE, 14654488, 10.0);
 
                 DisplayFloatyMessage(oOwner, GetName(oItem) + " added", FLOATY_MESSAGE, 14654488, 10.0);
 
             }
 
             }
             //Now we didn't handle the event itsel but just displayed a floaty --> let the original event handler take over.
+
             //Now we didn't handle the event itself but just displayed a floaty --> let the original event handler take over.
 
             //HandleEvent(ev,R"player_core.ncs"); <-- this is bad because the inventory_added event doesn't just fire for players
 
             //HandleEvent(ev,R"player_core.ncs"); <-- this is bad because the inventory_added event doesn't just fire for players
 
             HandleEvent(ev); // this is correct, it passes the event to the default handler for the event's target object
 
             HandleEvent(ev); // this is correct, it passes the event to the default handler for the event's target object

Revision as of 13:56, 17 November 2009

How to override an event?

still needs some polishing but the basics should be there

Its pretty simple:

Create a Events M2DA File:

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(OBJECT_SELF)) // 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,R"player_core.ncs"); <-- this is bad because the inventory_added event doesn't just fire for players
            HandleEvent(ev); // this is correct, it passes the event to the default handler for the event's target object
            break;
        }

    }
}

// --- script end ---