- Joined
- Apr 2, 2006
- Messages
- 32
I'm making Impetus from dota, a spell where a projectile is thrown and after the target unit is hit, it takes a certain % of the distance the projectile covered in damage. I can do all of this just fine, although, I have run into a strange problem when I want to damage the target unit. If I use the UnitDamageTarget action, the game exits as soon as the projectile hits the target (as soon as it takes the damage).
The spell is auto-castable, which means the projectiles should fire whenever the spell is under auto-castable effects, but, at the moment, I'm still trying to get the "EVENT_UNIT_SPELL_EFFECT" side of things working. Afterwards, I'll add in more to the trigger which makes the auto-casting stuff work.
Here is my current code (WIP):
So there it is, my problem lies in the Impetus_Actions_3 function.
Everything works 100% perfect apart from the UnitDamageTarget line.
I know it's that line because after removing it, then testing the spell it doesn't exit the game/crash/malfunction.
What could be the problem here?
The spell is auto-castable, which means the projectiles should fire whenever the spell is under auto-castable effects, but, at the moment, I'm still trying to get the "EVENT_UNIT_SPELL_EFFECT" side of things working. Afterwards, I'll add in more to the trigger which makes the auto-casting stuff work.
Here is my current code (WIP):
JASS:
scope Impetus
globals
private constant integer Imp_ID = 'A000'
private constant real Percent_Base = 0.04
private constant real Max_Dmg = 375
private constant real Texttag_Vlcty = 60
private constant real Texttag_Size = 10
private constant real Texttag_Red = 5
private constant real Texttag_Green = 80
private constant real Texttag_Blue = 85
private constant real Texttag_Trsprcy = 8
private constant real Texttag_Angle = 90
private constant real Texttag_Durtn = 1.25
private constant string Order_ID = "flamingarrows"
private constant string Un_Order_ID = "unflamingarrows"
endglobals
struct Imp_Data
unit U
endstruct
struct Imp_Data_2
unit u
unit h
triggeraction a
endstruct
private function Impetus_Conditions_2 takes nothing returns boolean
if GetTriggerEventId() == EVENT_UNIT_SPELL_EFFECT and GetSpellAbilityId() == Imp_ID then
return true
endif
return false
endfunction
private function Impetus_Actions_3 takes nothing returns nothing
local trigger x = GetTriggeringTrigger()
local Imp_Data_2 D = Imp_Data_2(GetHandleInt(x, "D"))
local real X1 = GetUnitX(D.u)
local real Y1 = GetUnitY(D.u)
local real X2 = GetUnitX(D.h)
local real Y2 = GetUnitY(D.h)
local real dist = SquareRoot((X2-X1) * (X2-X1) + (Y2-Y1) * (Y2-Y1))
local real dmg = (GetUnitAbilityLevel(D.u, Imp_ID) * Percent_Base) * dist
local texttag t
if D.u == GetEventDamageSource() then
if dmg > Max_Dmg then
set dmg = Max_Dmg
endif
call UnitDamageTarget(D.u, D.h, dmg, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_DIVINE, null)
set t = CreateTextTagUnitBJ("+" + I2S(R2I(dmg)), D.h, Texttag_Vlcty, Texttag_Size, Texttag_Red, Texttag_Green, Texttag_Blue, Texttag_Trsprcy)
call SetTextTagVelocityBJ(t, Texttag_Vlcty, Texttag_Angle)
call PolledWait(Texttag_Durtn)
call DestroyTextTag(t)
endif
call FlushHandleLocals(x)
call TriggerRemoveAction(x, D.a)
call DestroyTrigger(x)
call D.destroy()
set x = null
set t = null
endfunction
private function Impetus_Actions_2 takes nothing returns nothing
local trigger z = GetTriggeringTrigger()
local Imp_Data d = Imp_Data(GetHandleInt(z, "d"))
local Imp_Data_2 D = Imp_Data_2.create()
local trigger x = CreateTrigger()
if GetTriggerEventId() == EVENT_UNIT_SPELL_EFFECT then
set D.h = GetSpellTargetUnit()
endif
set D.u = d.U
call TriggerRegisterUnitEvent(x, D.h, EVENT_UNIT_DAMAGED)
set D.a = TriggerAddAction(x, function Impetus_Actions_3)
call SetHandleInt(x, "D", D)
set z = null
set x = null
endfunction
private function Impetus_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local trigger t = CreateTrigger()
local boolexpr b = Condition(function Impetus_Conditions_2)
local Imp_Data d = Imp_Data.create()
set d.U = u
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, b)
call TriggerAddAction(t, function Impetus_Actions_2)
call SetHandleInt(t, "d", d)
call DestroyBoolExpr(b)
set u = null
set t = null
set b = null
endfunction
private function Impetus_Conditions takes nothing returns boolean
return GetLearnedSkill() == Imp_ID
endfunction
function InitTrig_Impetus takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_HERO_SKILL)
call TriggerAddCondition(t, Condition(function Impetus_Conditions))
call TriggerAddAction(t, function Impetus_Actions)
set t = null
endfunction
endscope
So there it is, my problem lies in the Impetus_Actions_3 function.
Everything works 100% perfect apart from the UnitDamageTarget line.
I know it's that line because after removing it, then testing the spell it doesn't exit the game/crash/malfunction.
What could be the problem here?