fire a recurrring event from an item
Posted: Sun Feb 27, 2011 4:06 pm
I had an idea on how to fire a recurring event from anywhere in code, in particular I was interested to fire a recurring event from an item in a simple way, without the need to create a station and/or ship to handle the recurring event.
Don't get me wrong, the spawned station idea proved to be flexible and stable, this is another solution to it, and I like it for its simplicity.
The idea is to use an event handler on the playership :
and then fire the event that is in the virtual handler:
Event handlers are stackable, so multiple mods can run their recurring events without clashing.
This can work on the playership, or on any other spaceobject.
when the player installs an item
<OnInstall>
add the event handler and fire the recurring event
<OnUninstall>
stop the recurring event
What do you think ?
Don't get me wrong, the spawned station idea proved to be flexible and stable, this is another solution to it, and I like it for its simplicity.
The idea is to use an event handler on the playership :
Code: Select all
(block Nil
(objSetEventHandler gPLayership &evtest;)
(objFireEvent gPLayership "IMTESTEVENT")
)
Code: Select all
<ShipClass UNID="&evtest;"
class= "(test)"
virtual= "true"
>
<Events>
<IMTESTEVENT>
(dbglog "IT WORKS!!!!!!!!!!!!!!")
</IMTESTEVENT>
</Events>
</ShipClass>
This can work on the playership, or on any other spaceobject.
when the player installs an item
<OnInstall>
add the event handler and fire the recurring event
<OnUninstall>
stop the recurring event
What do you think ?