Event manager
Posted: Wed Apr 17, 2013 7:41 am
I dont know if its any interest but due to some discussions w. admin/lisa I've made an event manager as a userfunction.
It replaces the static event management in RoM with a subscription based one which enables multiple callbacks.
Well I started off making detectors, like "is there any players close by" or "has boss spawned" and discovered I had code stashed away in multiple userfuntions which wanted to check errors and execute stuff at exit of scripts.
So, solution is this event manager, I can register a callback on specific events independently in userfunctions without messing up other userfunctions.
Example is detection that other players are close by, if I detect a player around I might want to do some actions, if its all clear again I want other actions, if I suspend a script I want the character to sit down, when I activate it it should stand up and Yell "Jipiii"...or someting, and when script terminates due to error ot normally I would like to have character sit down again. (just silly samples...)
Using the event manager is somewhat simple:
Using this I made a userfunction to detect if players are close and fire off an event, to use in your waypoint:
The included event handler only prints out some text on console, to do anything else you need to register your own event handler. Ex:
The predefined events from micromacro are:
Hope this is usefull for some1
-dx
It replaces the static event management in RoM with a subscription based one which enables multiple callbacks.
- Subscription on micromacro and user events
- Multiple priority based callbacks per event
- Integrates into RoMBot, subscribes on systems events for all original callback handlers
Well I started off making detectors, like "is there any players close by" or "has boss spawned" and discovered I had code stashed away in multiple userfuntions which wanted to check errors and execute stuff at exit of scripts.
So, solution is this event manager, I can register a callback on specific events independently in userfunctions without messing up other userfunctions.
Example is detection that other players are close by, if I detect a player around I might want to do some actions, if its all clear again I want other actions, if I suspend a script I want the character to sit down, when I activate it it should stand up and Yell "Jipiii"...or someting, and when script terminates due to error ot normally I would like to have character sit down again. (just silly samples...)
Using the event manager is somewhat simple:
Code: Select all
function myCallback(event)
if event.name == "USER_EVENT_SAMPLE" then
print("Something")
end
end
Events:define("USER_EVENT_SAMPLE")
Events:register("USER_EVENT_SAMPLE", myCallback)
.
.
Events:throw("USER_EVENT_SAMPLE")
Code: Select all
-- range: how far away we should detect players (max for client is typically 5-600)
-- cooldown: how long should we wait after all players have gone until we get a all clear event
PlayerDetection(range, cooldown)
Code: Select all
function handleEvent(event)
end
Events:register(USER_PLAYERCLOSE, handleEvent)
Events:register(USER_PLAYERGONE, handleEvent)
Code: Select all
SYS_EXIT - at tertmination of script
SYS_RESUME - at resume after a pause
SYS_SUSPEND - at suspension of script
SYS_ERROR - at errors in script
-dx