I was making new hero in my map and i wanted to create shield spell for him about after 3 hours of hard work i done something that WORKS.. but not rly.. at first cast everythings fine shield absorbs damage how it should but after it ends or is destroyed after recast absorption gets messed up and for every recast shield absorbs less and less damage (eg. at level 4 shield absorbs 400 damage, at 1st cast it absorbs 400 damage, at 2nd cast it absorbs about 200 damage... and so on)
Heres the code(its not perfect because im new on vJass and because I haven't finished it yet(still need to make MUI)):
Heres the code(its not perfect because im new on vJass and because I haven't finished it yet(still need to make MUI)):
JASS:
scope darkShield initializer start
globals
private timer time=CreateTimer()
private unit target
private real shieldMax
private real shieldLeft
private trigger trig2=CreateTrigger()
private integer count=0
endglobals
private function b takes nothing returns nothing
set count=count+1
if count>=500 then
set target=null
set shieldLeft=0
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Shield timedout") //Debug Message
call PauseTimer(time)
endif
endfunction
private function a takes nothing returns nothing
local real damage=GetEventDamage()
if GetUnitAbilityLevel(target,'B035') > 0 then //Checks if target has buff
if shieldLeft>=damage then
set shieldLeft=shieldLeft-damage
call SetUnitState(target,UNIT_STATE_LIFE,GetUnitState(target,UNIT_STATE_LIFE)+damage)
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Shield left "+R2S(shieldLeft))//Debug Message
call DisplayTextToPlayer(GetLocalPlayer(),0,0,GetUnitName(target))//Debug Message
elseif shieldLeft<damage then
set shieldLeft=0
call SetUnitState(target,UNIT_STATE_LIFE,GetUnitState(target,UNIT_STATE_LIFE)+(damage-shieldLeft))
call UnitRemoveAbility(target, 'B035')
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Shield gone")//Debug Message
set target=null
call PauseTimer(time)
endif
endif
endfunction
private function s takes nothing returns boolean
local unit dummy
if GetSpellAbilityId()=='A09L' then
set target=GetSpellTargetUnit()
set shieldMax=I2R(GetUnitAbilityLevel(GetTriggerUnit(),'A09L'))*100
set shieldLeft=shieldMax
set dummy=CreateUnit(GetOwningPlayer(target),'h004',GetUnitX(target),GetUnitY(target),0)
call UnitApplyTimedLife(dummy,'BTLF',3)
call UnitAddAbility(dummy,'A09M')
call SetUnitAbilityLevel(dummy,'A09M',GetUnitAbilityLevel(GetTriggerUnit(),'A09L'))
call IssueTargetOrder(dummy,"innerfire",target)
call TriggerRegisterUnitEvent( trig2, target, EVENT_UNIT_DAMAGED )
call TriggerAddAction(trig2, function a)
call TimerStart(time,0.03,true,function b)
set count=0
endif
return false
endfunction
private function start takes nothing returns nothing
local trigger trig=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(trig,Condition(function s))
set trig=null
endfunction
endscope