library Wander requires TimerUtils
globals
private constant real MAX_DISTANCE = 700.0
private constant real INTERVAL = 5.0
endglobals
private module Init
private static method onInit takes nothing returns nothing
local region reg = CreateRegion()
local rect rec = Rect(-32256,-32256,32256,32256) // Credits to Nestharus for these values
call RegionAddRect(reg,rec)
call TriggerRegisterEnterRegion(CreateTrigger(),reg,Condition(function thistype.run))
set reg = null
set rec = null
endmethod
endmodule
private struct wander
unit u
static method move takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local real dis = GetRandomReal(1,MAX_DISTANCE)
local real ang = GetRandomReal(0,6.28318530)
call IssuePointOrder(this.u,"move",GetUnitX(this.u)+dis*Cos(ang),GetUnitY(this.u)+dis*Sin(ang))
endmethod
static method create takes unit un returns thistype
local thistype this = thistype.allocate()
local timer t = NewTimer()
set this.u = un
call TimerStart(t,INTERVAL,true,function thistype.move)
call SetTimerData(t,this)
return this
endmethod
static method run takes nothing returns boolean
call thistype.create(GetTriggerUnit())
return false
endmethod
method destroy takes nothing returns nothing
set this.u = null
call this.deallocate()
endmethod
implement Init
endstruct
endlibrary
>Magthridon96
Does it necessarily need a GUI Trigger or JASS system to make creeps walk randomly? why not just use the 'Wander' Ability?
I am only curious why is the system you made better? What does it do exactly?