Open Dreae opened 10 months ago
The way this currently is worked around is by always cancelling your event timers before starting them, much like unsubscribing event handlers in other languages before subscribing. Cancelling a nonexistent event timer is a no-op.
So, dirty fix:
function SayHello()
print("Hello there")
end
MP.RegisterEvent("TestTimer", "SayHello")
+ MP.CancelEventTimer("TestTimer")
MP.CreateEventTimer("TestTimer", 2000)
Fixing this would require the following changes to be made to the lua/plugin engine:
You could also potentially add an event for onBeforeReload or something, but nobody would end up using that IMO.
OS (windows, linux, ...): windows BeamMP-Server Version: master
Describe the bug Plugin auto-reloading on file changes does not clear timers created with
CreateEventTimer
causing duplicate timers to be created every time the plugin reloads. This also causes a crash if the event handler function changes name when the plugin reloads.To Reproduce Steps to reproduce the behavior:
CreateEventTimer
Expected behavior Reloading plugins clears existing event timers so they will be recreated cleanly when the plugin restarts
Logs
Additional Context Lua file used to reproduce the issue: