- Joined
- Jul 28, 2008
- Messages
- 211
Haven't been using the editor or WC3 for some time and I decided to come back. I started a project and I'm having troubles with my first spell.
The spell should prevent any damage done to the target. It's probably badly coded and stuff but as I said I have been away from the editor for some time.
Can anyone tell what's wrong with it?
Thanks in advance.
JASS:
scope Spell initializer Init
globals
timer Timer
endglobals
private struct spell
unit target
real life
integer c
static spell array arr
static integer count
static method Heal takes nothing returns nothing
local spell s
local integer i = 0
loop
exitwhen i > s.count
set s = s.arr[i]
if GetUnitState(s.target, UNIT_STATE_LIFE) <= 0 then
call ReviveHero(s.target, GetUnitX(s.target), GetUnitY(s.target), false)
endif
call SetWidgetLife(s.target, s.life)
set s.c = s.c + 1
if s.c >= 250 then
call s.destroy()
set s.count = s.count - 1
set s.arr[i] = s.arr[s.count]
endif
set i = i + 1
endloop
if s.count == 0 then
call PauseTimer(Timer)
endif
endmethod
static method Start takes unit u returns nothing
local spell s = spell.allocate()
set s.target = u
set s.life = GetWidgetLife(u)
if s.count == 0 then
call TimerStart(Timer, 0.04, true, function spell.Heal)
endif
set s.arr[s.count] = s
set s.count = s.count + 1
endmethod
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
private function Actions takes nothing returns nothing
call spell.Start(GetSpellTargetUnit())
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function Conditions))
call TriggerAddAction(t, function Actions)
set Timer = CreateTimer()
endfunction
endscope
The spell should prevent any damage done to the target. It's probably badly coded and stuff but as I said I have been away from the editor for some time.
Can anyone tell what's wrong with it?
Thanks in advance.