I've written a custom timer registry to enable pausing/unpausing arcade maps from code.
This does not count towards actual game pauses from the main menu (usually 3 per player).
This has been tested and proven on a 10mb+ map with hundreds of timers running.
The only thing it does not pause is missile animations. They will continue on their path, but the effect at the end of it will still apply when it should, and not immediately after the game is unpaused.
You will obviously have to hide any custom dialogs manually in the Pause/Resume actions, and many of the things there (like stopping and starting AI time) might not be necessary in all maps.
The main thing is just to use the provided API for elapsed or periodic timers instead of Blizzards. This ensures all custom timers are added to a pool that can be iterated and paused at will.
If you look closely at the main loop trigger for periodic events, you will see that it waits 0.97 game time seconds between firing, and that it staggers a bit if it cant find any triggers to run. This is a failsafe against network latency and such, which means that sometimes things will not fire exactly to the split-second when you want it to, but trust me this has exactly zero impact on a game in the real world.
The two custom event definitions are:
Periodic(time) - runs the trigger every time seconds, recurring.
Elapsed(time) - runs the trigger after time seconds, one time.
The main action definitions are:
Toggle Periodic Trigger(onoff, trigger)
Set Periodic Time(trigger, time) - to change how often an already-registered periodic trigger should fire
Oneshot(time, trigger) - fires a new oneshot timer and executes the given trigger after the given time in seconds
Register Timer for Pause(timer) - if you have any timers that are created with Blizzards API, register it for pausing using this. Do not call this for any timers created with my API.
Pause Registered Timers() - pauses all oneshot and periodic timers
Unpause Registered Timers() - Starts them again
The functions are:
Get Oneshot Timer for Trigger(trigger) - returns the registered Timer for the given trigger
All in all it's very simple to use, just look at the triggers in the attached map.
Please feel free to use this code however you wish, I am releasing it under CC-BY-NC-SA 4.0 or later which means you just need to mention my nick or name somewhere.
Please consider uploading your map UNLOCKED to Battle.net. What on earth are you trying to hide anyway? This is how we learn from eachother. We all write crappy code, dont be ashamed of yours. Show it!
I thought about the same concept in the past, but at that time i wasn't certain whether it'll work good. Glad to see it does.
Now, in LotV campaign there's Orbital Strike ability, that pauses the game to let user aim the targets. I wonder if they as well register all the timers manually. Or perhaps there's better way to do it?
That's interesting, I didnt think of that. Anyway this work started long before lotv.
But I checked, and they use a cutscene that apparently stops game time. I did not investigate further, and I have no idea how cutscenes work, but here is the relevant code from VoidCampaignMissionLib:
Hi,
I've written a custom timer registry to enable pausing/unpausing arcade maps from code.
This does not count towards actual game pauses from the main menu (usually 3 per player).
This has been tested and proven on a 10mb+ map with hundreds of timers running.
The only thing it does not pause is missile animations. They will continue on their path, but the effect at the end of it will still apply when it should, and not immediately after the game is unpaused.
You will obviously have to hide any custom dialogs manually in the Pause/Resume actions, and many of the things there (like stopping and starting AI time) might not be necessary in all maps.
The main thing is just to use the provided API for elapsed or periodic timers instead of Blizzards. This ensures all custom timers are added to a pool that can be iterated and paused at will.
If you look closely at the main loop trigger for periodic events, you will see that it waits 0.97 game time seconds between firing, and that it staggers a bit if it cant find any triggers to run. This is a failsafe against network latency and such, which means that sometimes things will not fire exactly to the split-second when you want it to, but trust me this has exactly zero impact on a game in the real world.
The two custom event definitions are:
The main action definitions are:
The functions are:
All in all it's very simple to use, just look at the triggers in the attached map.
Please feel free to use this code however you wish, I am releasing it under CC-BY-NC-SA 4.0 or later which means you just need to mention my nick or name somewhere.
Please consider uploading your map UNLOCKED to Battle.net. What on earth are you trying to hide anyway? This is how we learn from eachother. We all write crappy code, dont be ashamed of yours. Show it!
Good stuff.
I thought about the same concept in the past, but at that time i wasn't certain whether it'll work good. Glad to see it does.
Now, in LotV campaign there's Orbital Strike ability, that pauses the game to let user aim the targets. I wonder if they as well register all the timers manually. Or perhaps there's better way to do it?
setting global time scale to 0.01 doesnt work?
@FunkyUserName: Go
No, timers still run then. Setting it to 0 or 0.01 has no effect.
@SomeoneTookMyNameTT: Go
That's interesting, I didnt think of that. Anyway this work started long before lotv.
But I checked, and they use a cutscene that apparently stops game time. I did not investigate further, and I have no idea how cutscenes work, but here is the relevant code from VoidCampaignMissionLib: