- Joined
- Feb 23, 2007
- Messages
- 1,030
So I have a pseudo-attack detection system (It works as long as the units attack speed isn't changed). Glaive Thrower attacks, it creates a glaive and moves the glaive foward every 0.04 seconds. It damages any enemy units it comes in contact with. The problem is I only want it to damage them once. It ends up instantly killing every unit lol
Can't find the problem @_@ If you could comment on my use of structs it would be greatly appreciated as well.
Can't find the problem @_@ If you could comment on my use of structs it would be greatly appreciated as well.
JASS:
scope GlaiveThrower
private constant function GlaiveID takes nothing returns integer
return 'e00C'
endfunction
private constant function GlaiveProjectileID takes nothing returns integer
return 'n004'
endfunction
private function Conditions takes nothing returns boolean
return GetUnitTypeId(GetAttacker()) == GlaiveID()
endfunction
private function Conditions2 takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == GlaiveID() and GetHandleInt(GetTriggerUnit(),"special")!= null
endfunction
private function GlaiveFilter takes nothing returns boolean
return IsUnitInRangeXY(GetFilterUnit(),TempReal1,TempReal2,TempReal3) and IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(TempUnit)) and IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING) == false and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE)>.4 and IsUnitInGroup(GetFilterUnit(),TempGroup) == false
endfunction
globals
trigger gg_trg_GlaiveThrowerAttackCancel
endglobals
private struct Glaive
timer t
unit u
unit a
group g = CreateGroup()
real x
real y
integer c
method onDestroy takes nothing returns nothing
set this.t = null
set this.u = null
set this.a = null
call DestroyGroup(this.g)
set this.g = null
endmethod
endstruct
private struct Time
timer t
method onDestroy takes nothing returns nothing
set this.t = null
endmethod
endstruct
private function MoveProjectile takes nothing returns nothing
local timer t = GetExpiredTimer()
local Glaive str = Glaive(GetHandleInt(t,"str"))
local unit u = str.u
local real x = str.x
local real y = str.y
local real x2 = GetUnitX(u)
local real y2 = GetUnitY(u)
local integer c = str.c-1
local group g = CreateGroup()
local unit p
set TempUnit = u
set TempGroup = str.g
set TempReal1 = x2
set TempReal2 = y2
set TempReal3 = 100
call GroupEnumUnitsInRange(g,x2,y2,TempReal3+MC(),Condition(function GlaiveFilter))
call SetUnitPosition(u,x2+x,y2+y)
loop
set p = FirstOfGroup(g)
exitwhen p==null
call GroupAddUnit(str.g,p)
call UnitDamageTarget(u,p,80,true,false,ATTACK_TYPE_MELEE,DAMAGE_TYPE_SPIRIT_LINK,WEAPON_TYPE_WHOKNOWS)
call GroupRemoveUnit(g,p)
endloop
if c==0 then
call RemoveUnit(u)
call str.destroy()
call ReleaseTimer(t)
else
set str.c = c
endif
call GroupClear(TempGroup)
call DestroyGroup(g)
set t = null
set u = null
set g = null
endfunction
private function TimerActions takes nothing returns nothing
local timer t = GetExpiredTimer()
local Glaive str = Glaive(GetHandleInt(t,"str"))
local unit a = str.a
local unit u = str.u
local real x = GetUnitX(a)
local real y = GetUnitY(a)
local real f = Atan2(y-GetUnitY(u),x-GetUnitX(u))
local real x2 = x+40*Cos(f)
local real y2 = y+40*Sin(f)
call FlushStoredInteger(LocalVars(),I2S(H2I(a)),"special")
call FlushStoredInteger(LocalVars(),I2S(H2I(t)),"str")
call ReleaseTimer(t)
set t = NewTimer()
call SetHandleInt(t,"str",str)
set str.u = CreateUnit(GetOwningPlayer(a),GlaiveProjectileID(),x,y,0)
set str.x = x-x2
set str.y = y-y2
set str.c = 30
call TimerStart(t,0.04,true,function MoveProjectile)
set t = null
set a = null
set u = null
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit a = GetAttacker()
local timer t = NewTimer()
local Glaive str = Glaive.create()
local Time time = Time.create()
set str.u=u
set str.a=a
set str.t = t
set time.t = t
call SetHandleInt(t,"str",str)
call SetHandleInt(a,"special",time)
call TimerStart(t,0.10,false,function TimerActions)
set u = null
set a = null
set t = null
endfunction
private function Actions2 takes nothing returns nothing
local unit u = GetTriggerUnit()
local Time str = GetHandleInt(u,"special")
local timer t = str.t
local Glaive str2 = GetHandleInt(t,"str")
call str.destroy()
call str2.destroy()
call FlushStoredInteger(LocalVars(),I2S(H2I(u)),"special")
call FlushStoredInteger(LocalVars(),I2S(H2I(t)),"str")
call ReleaseTimer(t)
set u = null
endfunction
//===========================================================================
function InitTrig_GlaiveThrower takes nothing returns nothing
local integer a = 0
set gg_trg_GlaiveThrower = CreateTrigger()
set gg_trg_GlaiveThrowerAttackCancel = CreateTrigger()
loop
exitwhen a==MaxPlayers()
call TriggerRegisterPlayerUnitEvent(gg_trg_GlaiveThrower,Player(a),EVENT_PLAYER_UNIT_ATTACKED,null)
set a = a+1
endloop
call TriggerAddCondition(gg_trg_GlaiveThrower, Condition(function Conditions))
call TriggerAddAction(gg_trg_GlaiveThrower, function Actions)
call TriggerAddCondition(gg_trg_GlaiveThrowerAttackCancel, Condition(function Conditions2))
call TriggerAddAction(gg_trg_GlaiveThrowerAttackCancel, function Actions2)
endfunction
endscope