MasterRofl
New Member
- Reaction score
- 8
My dummy unit isn't created. Timer problem?
If I move a unit (pos: x,y) to posx+v, y+v), would it move towards the upper right?
Also, my main problem. Now, a unit is made. But the unit isn't moved.
If I move a unit (pos: x,y) to posx+v, y+v), would it move towards the upper right?
Also, my main problem. Now, a unit is made. But the unit isn't moved.
JASS:
library ThrowKnife initializer ThrowKnife uses HSAS
globals
private constant integer SPELLID = 039;A01U039;
private constant string SLOWSTRING = "slow"
private constant integer DUMMYID = 039;n00N039;
private constant integer DUMMYSPELLID = 039;A026039;
endglobals
struct Dagger
unit u
unit t
unit d
real x
real y
real damage
method onDestroy takes nothing returns nothing
set.u = null
set.t = null
set.d = null
endmethod
endstruct
private function AngleBetweenXY takes real x, real y, real xy, real yx returns real
return bj_RADTODEG * (Atan2(y - yx, x - xy))
endfunction
private function DistanceBetweenXY takes real x, real y, real xy, real yx returns real
local real dx = xy - x
local real dy = yx - y
return SquareRoot((dx * dx) + (dy * dy))
endfunction
//! runtextmacro HSAS_Static("d", "1288", "private")
private function Callback takes nothing returns nothing
local timer t = GetExpiredTimer()
local Dagger d = GetAttachedStructd(t)
local real x
local real y
local real xy
local real yx
set x = GetUnitX(d.d)
set y = GetUnitY(d.d)
set xy = GetUnitX(d.t)
set yx = GetUnitX(d.t)
call SetUnitPositionLocFacingLocBJ( d.d, PolarProjectionBJ(GetUnitLoc(d.d), 25., AngleBetweenPoints(GetUnitLoc(d.d), GetUnitLoc(d.t))), GetUnitLoc(d.t))
if DistanceBetweenPoints(GetUnitLoc(d.d), GetUnitLoc(d.t)) < 12. then
call SetUnitAbilityLevel(d.d, DUMMYSPELLID, GetUnitAbilityLevel(d.u, SPELLID))
call IssueTargetOrder( d.d, SLOWSTRING, d.t)
call UnitDamageTarget(d.d, d.t, d.damage, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
call RemoveUnit(d.d)
call d.destroy()
call PauseTimer(t)
call DestroyTimer(t)
endif
endfunction
private function Actions takes nothing returns nothing
local Dagger d = Dagger.create()
local timer t = CreateTimer()
set d.u = GetTriggerUnit()
set d.t = GetSpellTargetUnit()
set d.x = GetUnitX(d.u)
set d.y = GetUnitY(d.u)
set d.damage = GetUnitAbilityLevel(d.u, SPELLID) * 100.
set d.d = CreateUnit( GetOwningPlayer(d.u), DUMMYID, d.x, d.y, AngleBetweenPoints(GetUnitLoc(d.u), GetUnitLoc(d.t)))
call AttachStructd(t, d)
call TimerStart(t, 0.03, true, function Callback)
set t = null
endfunction
private function Conds takes nothing returns boolean
return GetSpellAbilityId() == SPELLID
endfunction
private function ThrowKnife takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition( function Conds ))
call TriggerAddAction(t, function Actions)
set t = null
endfunction
endlibrary