/*
=====StunMe v1.4
=====by Mckill2009
A very simple Stun System...
REQUIRES:
- CTL by Nesthaurus
INSTRUCTIONS:
- Copy ALL that is in the "StunMe" folder into your map.
- Copy ALL the custom unit/ability/buff to your map.
- Change the DUMMY_ID, STUN_ID and STUN_BUFF raw code if needed.
- DONE!
API:
static method stun takes unit target, real duration returns nothing
- Stuns the target unit
- Stacking is OK
static method stop takes unit target returns nothing
- Oviously stops the stun
*/
library StunMe uses CTL
globals
private constant integer DUMMY_ID = 'xdmx'
private constant integer STUN_ID = 'ab01'
private constant integer STUN_BUFF = 'bu01'
private constant integer STUN_OID = 852095
private constant string RESTORE_ANIMATION = "stand"
private unit StunCaster = null
endglobals
struct StunMe extends array
private unit target
private static hashtable ht = InitHashtable()
implement CTL
local real dur
local integer id
implement CTLExpire
set id = GetHandleId(.target)
set dur = LoadReal(ht, id, 0)
if dur > 0 and not IsUnitType(.target, UNIT_TYPE_DEAD) then
call SaveReal(ht, id, 0, dur-0.03125)
else
call UnitRemoveAbility(.target, STUN_BUFF)
call SetUnitTimeScale(.target, 1)
call SetUnitAnimation(.target, RESTORE_ANIMATION)
set .target = null
call .destroy()
endif
implement CTLEnd
private static method onInit takes nothing returns nothing
set StunCaster = CreateUnit(Player(15), DUMMY_ID, 0, 0, 0)
call UnitAddAbility(StunCaster, STUN_ID)
call UnitRemoveAbility(StunCaster, 'Amov')
endmethod
//API:
static method stun takes unit target, real duration returns nothing
local thistype this
local integer id = GetHandleId(target)
if LoadReal(ht, id, 0)==0 then
set this = create()
call SetUnitTimeScale(target, 0)
call SetUnitX(StunCaster, GetUnitX(target))
call SetUnitY(StunCaster, GetUnitY(target))
call IssueTargetOrderById(StunCaster, STUN_OID, target)
set .target = target
call SaveReal(ht, id, 0, duration)
else
call SaveReal(ht, id, 0, duration+LoadReal(ht, id, 0))
endif
endmethod
static method stop takes unit target returns nothing
call SaveReal(ht, GetHandleId(target), 0, 0)
endmethod
endstruct
endlibrary