- Joined
- Oct 12, 2011
- Messages
- 3,449
I wonder does this system work for everyone? The system name is very self explanatory. There are some requirements to make it work tho. Read in documentation.
Code:
Code:
JASS:
library UnpauseEvent initializer init
/*
Unpause Event v1.1
Provides unpause event which fires a moment after
the game is paused. This is only a workaround that
means it has several cons:
- Can't detect "quick" pause event
- Requires sound effect enabled (in option menu)
- Requires working sound system (available sound device)
- Requires a sound file (6 KB)
User API
1. Add the unpause event to your own trigger
| function TriggerRegisterUnpauseEvent takes trigger trig returns nothing
2. Register a function to the unpause event
| function RegisterUnpauseEvent takes code func returns triggercondition
3. Remove a function from the unpause event
| function RemoveUnpauseEvent takes triggercondition whichCondition returns nothing
How to import
1. Copy UnpauseEvent trigger
2. Import the sound file (PauseChecker.mp3) to your map
3. Edit the FILE_PATH below if necessary
*/
globals
private constant real CHECK_INTERVAL = 0.05 // Pretty much needless to change
private constant string FILE_PATH = "war3mapImported\\PauseChecker.mp3"
private real Trigger = 0
private trigger Eval = CreateTrigger()
private timer Checker = CreateTimer()
private sound Sound
private boolean Available
endglobals
function TriggerRegisterUnpauseEvent takes trigger trig returns nothing
call TriggerRegisterVariableEvent(trig, SCOPE_PRIVATE + "Trigger", EQUAL, 1)
endfunction
function RegisterUnpauseEvent takes code func returns triggercondition
return TriggerAddCondition(Eval, Condition(func))
endfunction
function RemoveUnpauseEvent takes triggercondition whichCondition returns nothing
call TriggerRemoveCondition(Eval, whichCondition)
endfunction
private function check takes nothing returns nothing
if (Available) then
if (not GetSoundIsPlaying(Sound)) then
set Trigger = 1
set Trigger = 0
call TriggerEvaluate(Eval)
else
call StopSound(Sound, false, false)
endif
endif
call StartSound(Sound)
set Available = GetSoundIsPlaying(Sound) // Check if sound effect is enabled
call TimerStart(Checker, CHECK_INTERVAL, false, function check)
endfunction
private function preload takes nothing returns nothing
call StartSound(Sound)
if (GetSoundIsPlaying(Sound)) then // Keep preloading until the sound is ready
set Available = false
call StopSound(Sound, false, false)
call TimerStart(Checker, CHECK_INTERVAL, false, function check)
else
call TimerStart(Checker, CHECK_INTERVAL, false, function preload)
endif
endfunction
private function init takes nothing returns nothing
set Sound = CreateSound(FILE_PATH, false, false, false, 0, 0, "")
call TimerStart(Checker, 0, false, function preload)
endfunction
endlibrary