dao::events
The scripts’ events (damage, perception, death and the rest), as callbacks.
Declared in dao/Events.h.
Type aliases
ScriptEventCallback
using ScriptEventCallback = std::function<void(ObjectId target, const CScriptEvent &event)>
A callback for a script event.
It receives the object, area or module the event is for, and the event itself, which is valid only during the call.
Functions
OnScriptEvent()
void OnScriptEvent(script::EventType type, ScriptEventCallback callback)
Calls callback for script events of one type only.
Otherwise it works like the overload above.
For EVENT_TYPE_DAMAGED, Float(0) is the damage, Int(0) its DAMAGE_TYPE_* value, Int(1) the ability, and the creator is the attacker. The event comes only for a blow that does not kill; a fatal blow sends the death event instead.
OnScriptEvent()
void OnScriptEvent(ScriptEventCallback callback)
Calls callback for every script event, whether it was queued or sent straight to its target.
Call it when the plugin loads or later. Callbacks run on the game thread and can only watch: they cannot change or stop the event. EVENT_TYPE_DEATH arrives about 1.5 to 5 seconds after the creature dies; dao::creatures::OnDeath (dao/Creatures.h) is the moment itself.
OnScriptEventHandled()
void OnScriptEventHandled(script::EventType type, std::function<void(ObjectId target)> callback)
Calls callback once an object’s own scripts have handled an event of one type: after the script ran, with what it changed in place.
Only for events the object’s scripts run (not an area’s or the module’s), and the event itself is gone by then.
dao::events::OnScriptEventHandled(dao::script::EventType::Spawn, [](dao::ObjectId object) {
// the object's spawn script has set it up
});