- Joined
- Dec 29, 2006
- Messages
- 15
Hello, I'm trying to learn how to use ABC struct attachments, and Jass and I've been trying to make this trigger move the casting unit in a circle. However it hasn't been working; anyone know why?
JASS:
scope BoomerangABC
globals
constant integer AID_BOOMERANGABC = 'A000'
endglobals
globals
private constant real PERIOD = 0.04
private constant real SLIDE_SPEED = 600.
endglobals
private struct SpellData
unit boomerangcaster
real distance
integer ticks
location radius
real angle = 0.0
endstruct
private function Timer_Actions takes nothing returns nothing
local integer i = 1
local SpellData data
local real x
local real y
local location temppoint
local timer t = GetExpiredTimer()
set data = GetTimerStructA(t)
set data.angle = (data.angle +(360/ (SLIDE_SPEED*PERIOD)))
set temppoint = PolarProjectionBJ(data.radius, data.distance, data.angle)
set x = GetLocationX(temppoint)
set y =GetLocationY(temppoint)
call SetUnitPosition(data.boomerangcaster, x, y)
set data.ticks = data.ticks - 1
if data.ticks <= 0 then
call SetUnitPathing( data.boomerangcaster, true )
call PauseUnit( data.boomerangcaster, false )
call data.destroy()
call ClearTimerStructA(t) // We must clear attachments before destroying timer
call DestroyTimer(t)
endif
endfunction
private function Actions takes nothing returns nothing
local SpellData data = SpellData.create()
local location target = GetSpellTargetLoc()
local timer t = CreateTimer()
local real Dx
local real Dy
local real angle
set data.boomerangcaster = GetTriggerUnit()
set Dx = GetLocationX(target) - GetUnitX(data.boomerangcaster)
set Dy = GetLocationY(target) - GetUnitY(data.boomerangcaster)
set data.distance = ((SquareRoot(Dx * Dx + Dy * Dy))/2) //calculates distance of radius
set angle = AngleBetweenPoints(target, GetUnitLoc(data.boomerangcaster))
set data.radius = PolarProjectionBJ(target,data.distance, angle)//calculates center of circle
call RemoveLocation(target)
set data.ticks = R2I(data.distance / (SLIDE_SPEED*PERIOD))
call SetUnitPathing( data.boomerangcaster, false )
call PauseUnit( data.boomerangcaster, true)
// attaching a struct to a timer
call SetTimerStructA(t, data)
call BJDebugMsg(udg_w)
call TimerStart(t,PERIOD,true,function Timer_Actions)
set t = null
endfunction
//===========================================================================
private function SpellComparision takes nothing returns boolean
return GetSpellAbilityId() == AID_BOOMERANGABC
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( trig, Condition( function SpellComparision ) )
call TriggerAddAction( trig, function Actions)
endfunction
endscope
Last edited: