wraithseeker
Tired.
- Reaction score
- 122
Requires AutoIndex, TimerUtils
Here is the documention
JASS:
CustomStun uses AutoIndex, TimerUtils
v1.04
Made by wraithseeker
Changelog v1.01
Fixed many issues and now works like a charm.
Changelog v1.02
Ported to AutoIndex and added spell immune function.
Changelog v1.03
Ported to use TimerUtils
Changelog v1.04
- Added a function to check for Mechanical units.
- Fixed spell immune bug.
function StunUnit takes unit target, real duration returns nothing
unit target refers to the unit who is going to get stunned
real duration is how long do you want the unit to be stunned.
call StunUnit(target,3)
It means that the unit target will get stunned for 3 seconds.
function StopStun takes unit target returns nothing
call StopStun(whichUnit)
Stops the stun for the targeted unit.
function IsStunned takes unit target returns boolean
call IsStunned(whichUnit)
It tells you whether the unit is stunned or not.
Creation of the ability
The objectmerger calls are available for you to use to create them automatically, after creation,
uncomment the objectmerger calls to make saving your map faster.
JASS:
library CustomStun initializer Init uses AutoIndex, TimerUtils
//! external ObjectMerger w3h BPSE STNB fnam "Custom Stun"
//! external ObjectMerger w3a AHtb STUN anam "Stun" alev 1 Htb1 1 0 acdn 1 0 amcs 1 0 amat " " abuf 1 STNB atar 1 notself aran 1 999999 aani "" ahdu 1 0 adur 1 0 amsp 0
// Use this to create the abilities and uncomment it after it is created
globals
private constant integer StunDummyId = 039;h003039; //Dummy ID
private constant integer BoltId = 039;STUN039; //Storm bolt ID
private constant integer BuffId = 039;STNB039; //Stun buff ID
private constant string StunOrderId = "thunderbolt" // string order of StormBolt Id
endglobals
globals
private unit stunner = null
private group Stunned = CreateGroup()
endglobals
struct stun
unit target
timer T
static method Periodic takes nothing returns nothing
call stun(GetTimerData(GetExpiredTimer())).destroy()
endmethod
static method create takes unit target, real duration returns stun
local stun d = stun.allocate()
set d.target = target
set d.T = NewTimer()
call GroupAddUnit(Stunned,target)
call SetUnitX(stunner,GetUnitX(target))
call SetUnitY(stunner,GetUnitY(target))
call IssueTargetOrder(stunner,StunOrderId,target)
call SetTimerData(d.T,d)
call TimerStart(d.T,duration,false,function stun.Periodic)
return d
endmethod
private method onDestroy takes nothing returns nothing
call UnitRemoveAbility(.target, BuffId)
call GroupRemoveUnit(Stunned,.target)
call ReleaseTimer(.T)
endmethod
implement AutoData
endstruct
function IsStunned takes unit target returns boolean
return IsUnitInGroup(target,Stunned)
endfunction
function StopStun takes unit target returns nothing
local stun d = stun[target]
if IsUnitInGroup(target,Stunned) then
call d.destroy()
endif
endfunction
function StunUnit takes unit target, real duration returns nothing
local stun d
local real remaining = 0.
if not IsUnitInGroup(target,Stunned) then
set stun[target] = stun.create(target,duration)
else
set d = stun[target]
set remaining = TimerGetRemaining(d.T)
if duration > remaining then
set remaining = duration
endif
call ReleaseTimer(d.T)
set d.T = NewTimer()
call SetTimerData(d.T,d)
call TimerStart(d.T,remaining,false,function stun.Periodic)
endif
endfunction
function StunUnitEx takes unit target, real duration, boolean Immune, boolean organic returns nothing
local stun d
local real remaining = 0.
local boolean b = false
local boolean organ = false
if not IsUnitInGroup(target,Stunned) then
if Immune and IsUnitType(target,UNIT_TYPE_MAGIC_IMMUNE) then
set b = true
endif
if organic and IsUnitType(target,UNIT_TYPE_MECHANICAL) then
set organ = true
endif
if not b and not organ then
set stun[target] = stun.create(target,duration)
endif
else
set d = stun[target]
set remaining = TimerGetRemaining(d.T)
if duration > remaining then
set remaining = duration
endif
call ReleaseTimer(d.T)
set d.T = NewTimer()
call SetTimerData(d.T,d)
call TimerStart(d.T,remaining,false,function stun.Periodic)
endif
endfunction
private function Init takes nothing returns nothing
set stunner = CreateUnit(Player(12),StunDummyId,0,0,0)
call UnitAddAbility(stunner,BoltId )
endfunction
endlibrary