• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Need Help How to use #event_handler GetEventData()?

Kahenraz

Landlubber
It's unclear to me how #event_handler works and the behavior of GetEventData() is nebulous. Is it possible to create my own event handlers or is this something that is hard-coded?

Also, where are the values from GetEventData() coming from?
 
How exactly this works I am not sure; but I know I've used them in the past by copying existing code and adapting it.

As an example, there is this trigger in PROGRAM\SEA_AI\AIShip.c:
Code:
PostEvent("CreateCursedPearlFog", delay, "i", rCharacter);
This then triggers this event from PROGRAM\NK.c:
Code:
#event_handler("CreateCursedPearlFog", "CursedPearlFog");
void CursedPearlFog()
{
   aref rCharacter = GetEventData();
   float fX, fY, fZ, fAY;
   fX = 0; fY = 0; fZ = 0;

   if(CheckAttribute(rCharacter,"Ship.pos.x")) fX=stf(rCharacter.Ship.pos.x);
       else return;
   if(CheckAttribute(rCharacter,"Ship.pos.y")) fY=stf(rCharacter.Ship.pos.y);
       else return;
   if(CheckAttribute(rCharacter,"Ship.pos.z")) fZ=stf(rCharacter.Ship.pos.z);
       else return;
   if(CheckAttribute(rCharacter,"Ship.Ang.y")) fAY=stf(rCharacter.Ship.Ang.y);
       else return;
   float gX, gY, gZ;
   gX = 0; // Width
   gY = 0; // Height
   gZ = 10; // Length
   CreateParticleSystemX("pearlfog",fX - gX*cos(fAY) + gZ*sin(fAY), fY + gY, fZ + gX*sin(fAY) + gZ*cos(fAY), 0.0, 0.0, 0.0, 2);
}

There are ways to pass multiple variables to such an event (in addition to just the 'rCharacter' one used here).
These can be added as additional inputs to 'PostEvent' and can then be read in the order they come in using 'GetEventData()'.

A quick search for an example shows me this:
Code:
PostEvent(SHIP_ACTIVATE_FIRE_PLACE, rand(10000), "ialsf", rShipObject, rCharacter, i, "ship_onfire", 30.0);
Different variable types require a different character in that first string.
I'm not sure what means what, but it looks that "i" or "a" works for a character reference; and I suspect "s" is a string and "f" a float.
"l" then could be an integer...?
 
These are the formatting chars used in TEHO:

'a': AttributePointer
'b': Byte
'c': Vector
'e': ScriptVariablePointer
'd': Double
'f': Float
'i': EntityID
'l': Long
'p': pointer
's': string
'u': Unsigned long
'w': Unsigned short

And if you pass the wrong signature string to an event things will explode.
 
Back
Top