- Joined
- Oct 9, 2015
- Messages
- 721
Code:
//TESH.scrollpos=0
//TESH.alwaysfold=0
library UnitPause /* v1.0 By IcemanBo (credits to Maker)
Alternative for the PauseUnit() function without known site effects.
A paused unit will be completly unuseable until unpaused.
Unit's current order will be forgetten.
API
¯¯¯¯¯¯
function UnitPause(unit, boolean) returns nothing
function UnitPaused(unit) returns boolean
Instructions:
¯¯¯¯¯¯¯¯¯¯¯¯¯¯
After copying the library save the map and restart the editor.
When done, then comment out the next line:*/
//! external ObjectMerger w3a ANcl paus Ncl6 1 "defend" anam "Channel Pause" acat "" atat "" aher 0 alev 1 Ncl1 1 10000 aani "stand" aeat "" |
/*
Credits:
¯¯¯¯¯¯¯¯¯
This method was used by Maker.
*/
globals
private constant integer PAUSE = 'paus'
private constant integer DEFEND = 852055
endglobals
function UnitPause takes unit u, boolean b returns nothing
if (b) then
call UnitAddAbility(u, PAUSE)
call IssueImmediateOrderById(u, DEFEND)
else
call UnitRemoveAbility(u, PAUSE)
endif
endfunction
function UnitPaused takes unit u returns boolean
return (UnitRemoveAbility(u, PAUSE) and UnitAddAbility(u, PAUSE) and IssueImmediateOrderById(u, DEFEND))
endfunction
endlibrary
Code:
//TESH.scrollpos=0
//TESH.alwaysfold=0
struct PauseTest extends array
private static unit tester
private static method onSelect takes nothing returns boolean
if (UnitPaused(tester)) then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "paused")
else
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "not paused")
endif
return false
endmethod
private static method onEscape takes nothing returns boolean
call UnitPause(tester, not(UnitPaused(tester)))
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
set tester = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
call TriggerRegisterUnitEvent(t, tester, EVENT_UNIT_SELECTED )
call TriggerAddCondition(t, Filter(function thistype.onSelect))
set t = CreateTrigger()
call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddCondition(t, Filter(function thistype.onEscape))
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Press 'Esc' to pause/unpause.")
endmethod
endstruct