- Joined
- Mar 21, 2011
- Messages
- 1,611
Hi, i made a system for my map that basically lets units move a certain path. i used a hashtable to save the x/y values of the points you add to the path. now, i want to remake the system using a struct, i have nearly no knowledge using structs and got stuck very quickly. this is what i came up with for now
the timer part does not work at all, i dont know how i can make my move method periodically. i guess there are more mistakes.
JASS:
library Wander requires TimerUtils
struct Wander
real array x[5]
real array y[5]
unit u
integer counter = 0
integer lastpos = 0
static method create takes unit U returns Wander
local Wander this = Wander.allocate()
set this.u = U
call IssuePointOrder(this.u, "move", this.x[this.lastpos], this.y[this.lastpos])
return this
endmethod
method addWaypoint takes real X, real Y returns nothing
set this.x[this.counter] = X
set this.y[this.counter] = Y
set this.counter = this.counter + 1
endmethod
method move takes nothing returns nothing
if SquareRoot((GetUnitX(this.u) - this.x[this.lastpos]) * (GetUnitX(this.u) - this.x[this.lastpos]) + (GetUnitY(this.u) - this.y[this.lastpos]) * (GetUnitY(this.u) - this.y[this.lastpos])) < 10 then
set this.lastpos = this.lastpos + 1
call IssuePointOrder(this.u, "move", this.x[this.lastpos], this.y[this.lastpos])
endif
endmethod
method destroy takes nothing returns nothing
set this.u = null
call this.deallocate()
endmethod
static method onInit takes nothing returns nothing
call TimerStart(NewTimer(), 0.1, true, method move)
endmethod
endstruct
function test takes nothing returns nothing
local Wander wanderer
set wanderer = Wander.create(gg_unit_n000_0003)
call wanderer.addWaypoint(-21550.0, -21222.0)
call wanderer.addWaypoint(-20000.0, -20000.0)
call wanderer.addWaypoint(-19000.0, -19000.0)
endfunction
endlibrary
the timer part does not work at all, i dont know how i can make my move method periodically. i guess there are more mistakes.