- Joined
- Jul 6, 2009
- Messages
- 1,885
I made a simple projectile spell that works like: Unit throws a dagger,if the dagger encounters a unit of ancient classification,it will stun it.
Here's the trigger:
But it doesn't seem to work. The projectile moves,but doesn't hit any unit,also it doesn't get removed when it passes more than 900.0 range which is supposed to. Actually,when i tried putting some debug messages,it seems they don't work if they're placed bellow GroupEnumUnitsInRange function in Dagger_Loop function!
Also i use function GetClosestUnit,which i made:
It might affect problem,but it shouldn't.
+rep for anyone who helps me solve this.
Here's the trigger:
JASS:
function Throw_Dagger_Condition takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
function Throw_Dagger_Actions takes nothing returns nothing
local unit u = CreateUnit(GetOwningPlayer(GetTriggerUnit()),'h00A',GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),bj_RADTODEG * Atan2(GetSpellTargetY() - GetUnitY(GetTriggerUnit()),GetSpellTargetX() - GetUnitX(GetTriggerUnit())))
call GroupAddUnit(udg_Daggers,u)
call SaveReal(udg_Hashtable,GetHandleId(u),0,0.00)
set u = null
endfunction
function Dagger_Filter takes nothing returns boolean
return IsUnitType(GetFilterUnit(),UNIT_TYPE_ANCIENT) and GetOwningPlayer(GetFilterUnit()) != GetOwningPlayer(GetEnumUnit())
endfunction
function Group_Count takes nothing returns nothing
set udg_Integer = udg_Integer + 1
endfunction
function Dagger_Loop takes nothing returns nothing
local real x = GetUnitX(GetEnumUnit()) + 30 * Cos(GetUnitFacing(GetEnumUnit()) * bj_DEGTORAD)
local real y = GetUnitY(GetEnumUnit()) + 30 * Sin(GetUnitFacing(GetEnumUnit()) * bj_DEGTORAD)
local group g
local unit u
call SetUnitX(GetEnumUnit(),x)
call SetUnitY(GetEnumUnit(),y)
call SaveReal(udg_Hashtable,GetHandleId(GetEnumUnit()),0,LoadReal(udg_Hashtable,GetHandleId(GetEnumUnit()),0) + 30.00)
call GroupEnumUnitsInRange(g,x,y,40.00,Filter(function Dagger_Filter))
set udg_Integer = 0
call ForGroup(g,function Group_Count)
if udg_Integer > 0 then
set u = CreateUnit(GetOwningPlayer(GetEnumUnit()),'h005',x,y,0.00)
call UnitApplyTimedLife(u,'BTLF',1.00)
call IssueTargetOrder(u,"thunderbolt",GetClosestUnit(g,x,y))
call GroupRemoveUnit(udg_Daggers,GetEnumUnit())
call KillUnit(GetEnumUnit())
elseif LoadReal(udg_Hashtable,GetHandleId(GetEnumUnit()),0) > 900.00 then
call GroupRemoveUnit(udg_Daggers,GetEnumUnit())
call KillUnit(GetEnumUnit())
endif
call DestroyGroup(g)
set g = null
set u = null
endfunction
function Dagger_Loop_Init takes nothing returns nothing
call ForGroup(udg_Daggers,function Dagger_Loop)
endfunction
//===========================================================================
function InitTrig_Throw_Dagger takes nothing returns nothing
local trigger t = CreateTrigger()
set gg_trg_Throw_Dagger = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Throw_Dagger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition( gg_trg_Throw_Dagger, Condition(function Throw_Dagger_Condition))
call TriggerAddAction( gg_trg_Throw_Dagger, function Throw_Dagger_Actions)
call TriggerRegisterTimerEvent(t,0.03,true)
call TriggerAddAction(t, function Dagger_Loop_Init)
set t = null
endfunction
But it doesn't seem to work. The projectile moves,but doesn't hit any unit,also it doesn't get removed when it passes more than 900.0 range which is supposed to. Actually,when i tried putting some debug messages,it seems they don't work if they're placed bellow GroupEnumUnitsInRange function in Dagger_Loop function!
Also i use function GetClosestUnit,which i made:
JASS:
function GetClosestUnit takes group g,real x,real y returns unit
local real r1 = 0.00
local real r2 = 4000.00
local unit u1
local unit u2
local group a = g
loop
set u1 = FirstOfGroup(a)
exitwhen u1 == null
set r1 = SquareRoot((GetUnitX(u1) - x) * (GetUnitX(u1) - x) + (GetUnitY(u1) - y) * (GetUnitY(u1) - y))
if r1 < r2 then
set r2 = r1
set u2 = u1
endif
call GroupRemoveUnit(a,u1)
endloop
call DestroyGroup(a)
set a = null
set u1 = null
set u2 = null
return u2
endfunction
+rep for anyone who helps me solve this.