Yet another post involving triggers. I have already tried to make timers using different unorthodox methods in my past attempts. This time I think I have a slightly improved version of a callback timer. Based on trigger countdown, this is fairly straight forward implementation. One peculiar thing about it is that the trigger never executes OnActivation statement, only OnDeactivation. Was a pretty unexpected finding as well. It seems that if the timeout is set to interruptible and the trigger is reset before it has the chance to execute OnActivation, the trigger considers that it has been deactivated. Here is the code:
A few things. You don’t want to create triggers on clients in Multiplayer, this is why I restricted it to server only. So this function is to be used on server only or in single player, sorry about that. OnDeactivation statement, from which your function is called will be executed in unscheduled environment, so if you have lots of things happening in it, consider rather spawning and managing scheduled environment scopes from it.
timer = [function, interval, force] call KK_fnc_setTimerCallback;
- function: STRING – name of the function to be executed upon timeout. The trigger object is passed to the function in _this variable in case you would like to remove the trigger and stop further executions.
- interval: NUMBER – desired interval in seconds. 0.5 seems to be the minimum interval possible.
- force: BOOLEAN – will also execute the function immediately upon the timer setup.
- timer: OBJECT – trigger object.
Because of trigger default refresh rate, the actual interval could be on average 0.5 seconds longer than passed interval. If you need more precise timer, you can construct something in FSM.