waaaks!
Zinctified
- Reaction score
- 256
ive got a vjass spell, tried it and it works correctly, but sometimes it behaves strangely and different from what i want
spell description
cast spell, buff the target, run timer for 5 seconds, after 5 seconds if the target still has the buff, deal damage if it is an enemy, do nothing if it is an ally, if the shield is still active, the target will not be damaged, the buff will be automatically removed after 5 seconds, or if the shield is destroyed, the shield has only (40 * level of ability) hit points, meaning if the shield is level 1, it can only block 40 damage then it will be destroyed, if it is level 5 the shield will have 200 hp and can only block 200 damage
the spell didnt work well, sometimes when i casted the spell at level 5 (200 hp shield), and attack the target, it will still take damage even though i only deal 100 attack damage, and when i casted the spell in my self i get healed each time i take damage, instead of just blocking it
now the code
spell description
the spell works like thisCreates a shield with negative energy to the target unit, making it immune to all damage, after the duration has finished while the shield is still active, the shield will be absorbed, dealing damage to the target unit if it is an enemy
cast spell, buff the target, run timer for 5 seconds, after 5 seconds if the target still has the buff, deal damage if it is an enemy, do nothing if it is an ally, if the shield is still active, the target will not be damaged, the buff will be automatically removed after 5 seconds, or if the shield is destroyed, the shield has only (40 * level of ability) hit points, meaning if the shield is level 1, it can only block 40 damage then it will be destroyed, if it is level 5 the shield will have 200 hp and can only block 200 damage
the spell didnt work well, sometimes when i casted the spell at level 5 (200 hp shield), and attack the target, it will still take damage even though i only deal 100 attack damage, and when i casted the spell in my self i get healed each time i take damage, instead of just blocking it
now the code
JASS:
scope ShieldofDeath initializer init
globals
private constant integer spell = 039;A024039;
private constant integer buffid = 039;B00H039;
endglobals
private struct data
unit cast
unit targ
integer level
real life
real counter
real dmg
method onDestroy takes nothing returns nothing
if GetUnitAbilityLevel(this.targ, buffid) > 0 then
if IsUnitEnemy(this.targ, GetOwningPlayer(this.cast)) then
call UnitDamageTargetEx(this.cast, this.targ, this.dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DARK, true)
endif
endif
call UnitRemoveAbility(this.targ, buffid)
endmethod
endstruct
private function boom takes nothing returns nothing
local timer t = GetExpiredTimer()
local data d = GetTimerStructA(t)
call ClearTimerStructA(t)
call DestroyTimer(t)
call d.destroy()
set t = null
endfunction
private function sodc takes nothing returns boolean
return GetUnitAbilityLevel(GetTriggerUnit(), buffid) > 0
endfunction
private function soda takes nothing returns nothing
local trigger trig = GetTriggeringTrigger()
local data d = GetTriggerStructA(trig)
local real dmg = GetEventDamage()
set d.counter = d.counter + dmg
if d.counter >= d.life then
set dmg = 0
set d.counter = 0
call UnitRemoveAbility(d.targ, buffid)
call ClearTriggerStructA(trig)
call DisableTrigger(trig)
set trig = null
else
call SetUnitState(d.targ, UNIT_STATE_LIFE, GetUnitState(d.targ, UNIT_STATE_LIFE) + dmg)
set dmg = 0
endif
endfunction
private function check takes nothing returns boolean
return GetSpellAbilityId() == spell
endfunction
private function start takes nothing returns nothing
local timer t = CreateTimer()
local trigger trig = CreateTrigger()
local data d = data.create()
set d.cast = GetTriggerUnit()
set d.targ = GetSpellTargetUnit()
set d.level = GetUnitAbilityLevel(d.cast, spell)
set d.life = 40 * d.level
set d.dmg = 50 + (50 * d.level)
set d.counter = 0
call TriggerRegisterUnitEvent(trig, d.targ, EVENT_UNIT_DAMAGED)
call TriggerAddCondition(trig, Condition(function sodc))
call TriggerAddAction(trig, function soda)
call TimerStart(t, 5, false, function boom)
call SetTimerStructA(t,d)
call SetTriggerStructA(trig,d)
set t = null
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 check))
call TriggerAddAction( t, function start )
endfunction
endscope