- Joined
- May 12, 2018
- Messages
- 145
I'm making Disarm struct and function, I want the duration of disarm will be reset if same ability used on same target,
but reset duration is not working. It doesn't reset to the specified duration and the effect is immediately turned off when the spell effect stacked.
this is my script.
i made this referring to How to develop spells with effects over time - WC3 Modding Information Center
and using TimerUtils.
but reset duration is not working. It doesn't reset to the specified duration and the effect is immediately turned off when the spell effect stacked.
this is my script.
JASS:
scope Disarm
//Helped by Derdan
globals
private constant string model = "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl"
endglobals
struct DisarmData
static integer index = 0
static group IsDisarmed
unit disarmtarget
real disarmdur
effect eff
static method onInit takes nothing returns nothing
set DisarmData.IsDisarmed = CreateGroup()
endmethod
static method create takes unit target, real duration returns DisarmData
local DisarmData D = DisarmData.allocate()
set D.disarmtarget = target
set D.eff = AddSpecialEffectTarget(model, D.disarmtarget, "head")
set D.disarmdur = duration
call BlzSetUnitWeaponBooleanField(target, UNIT_WEAPON_BF_ATTACKS_ENABLED, 0, false)
call BlzSetUnitWeaponBooleanField(target, UNIT_WEAPON_BF_ATTACKS_ENABLED, 1, false)
call GroupAddUnit(DisarmData.IsDisarmed, target)
if integer(D) > DisarmData.index then
set DisarmData.index = integer(D)
endif
return D
endmethod
method onDestroy takes nothing returns nothing
call BlzSetUnitWeaponBooleanField(.disarmtarget, UNIT_WEAPON_BF_ATTACKS_ENABLED, 0, true)
call BlzSetUnitWeaponBooleanField(.disarmtarget, UNIT_WEAPON_BF_ATTACKS_ENABLED, 1, true)
call DestroyEffect(.eff)
set .eff = null
call GroupRemoveUnit(.IsDisarmed, .disarmtarget)
if integer(this) == DisarmData.index then
set DisarmData.index = DisarmData.index - 1
set this.disarmtarget = null
endif
endmethod
static method SetTarget takes unit target, real duration returns nothing
local integer i = 0
local DisarmData D
local real h = duration
loop
exitwhen i > DisarmData.index
set D = DisarmData(i)
if D.disarmtarget == target and IsUnitInGroup(D.disarmtarget, D.IsDisarmed) then
if D.disarmdur < h then
if duration < 600 then
set D.disarmdur = 0.6
return
else
set D.disarmdur = h
return
endif
endif
endif
set i = i + 1
endloop
endmethod
endstruct
private function Loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local DisarmData D = DisarmData(GetTimerData(t))
if D.disarmdur > 0 and UnitAlive(D.disarmtarget) then
set D.disarmdur = D.disarmdur - 0.5
elseif D.disarmdur <= 0 or GetUnitTypeId(D.disarmtarget) == 0 or IsUnitType(D.disarmtarget, UNIT_TYPE_DEAD) then
call D.destroy()
call ReleaseTimer(t)
endif
set t = null
endfunction
function DisarmAction takes unit u, real duration returns nothing
local DisarmData D
local timer t
local unit target = u
if not IsUnitInGroup(target, DisarmData.IsDisarmed) then
set D = DisarmData.create(target,duration)
set t = NewTimer()
call SetTimerData(t, integer(D))
call TimerStart(t, 0.5, true, function Loop)
else
call DisarmData.SetTarget(target, duration)
endif
set target = null
set t = null
endfunction
endscope
i made this referring to How to develop spells with effects over time - WC3 Modding Information Center
and using TimerUtils.
Last edited: