- Joined
- Jun 19, 2009
- Messages
- 556
vJASS:
scope Wanderer initializer Init
globals
hashtable hash = InitHashtable()
endglobals
private function Conditions takes nothing returns boolean
local unit u = LoadUnitHandle(hash, 0, GetHandleId(Player(0)))
local real x = LoadReal(hash, 0, GetHandleId(u))
local real y = LoadReal(hash, 1, GetHandleId(u))
if RectContainsUnit(RectFromCenterSizeBJ(Location(x,y), 100, 100), u) then
return true
endif
return false
endfunction
private function Actions takes nothing returns nothing
local real x
local real y
local unit u = LoadUnitHandle(hash, 0, GetHandleId(Player(0)))
local integer t = LoadInteger(hash, 2, GetHandleId(u))
local location l = PolarProjectionBJ(GetUnitLoc(u), GetRandomReal(500,1500), GetRandomReal(0,360))
//SETTING X AND Y TO CURRENT LOCATION
set x = LoadReal(hash, 0, GetHandleId(u))
set y = LoadReal(hash, 1, GetHandleId(u))
//SETTING CURRENT LOCATION ORIGINAL TERRAIN
call SetTerrainType(x, y, t, 1, 1, 0)
//UPDATING X AND Y TO NEW LOCATION
set x = GetLocationX(l)
set y = GetLocationY(l)
//SAVING NEW LOCATION ORIGINAL TERRAIN
call SaveInteger(hash, 2, GetHandleId(u), GetTerrainType(x, y))
//SAVING NEW LOCATION
call SaveReal(hash, 0, GetHandleId(u), x)
call SaveReal(hash, 1, GetHandleId(u), y)
//ISSUING ORDER AND CHANGING NEW LOCATION TO SNOW
call IssuePointOrderLoc(u, "move", l)
call SetTerrainType(x,y,'Wsnw',-1,1,0)
endfunction
private function Init takes nothing returns nothing
local trigger trg = CreateTrigger()
local unit u
local real x
local real y
local integer c = CountUnitsInGroup(GetUnitsOfTypeIdAll('hgry'))
if c == 0 then
set u = CreateUnitAtLoc(Player(0), 'hgry', GetRectCenter(GetPlayableMapRect()), GetRandomReal(0,360))
set x = GetUnitX(u)
set y = GetUnitY(u)
call SaveReal(hash, 0, GetHandleId(u), x)
call SaveReal(hash, 1, GetHandleId(u), y)
call SaveInteger(hash, 2, GetHandleId(u), GetTerrainType(x, y))
call SaveUnitHandle(hash, 0, GetHandleId(Player(0)), u)
endif
call TriggerRegisterTimerEvent(trg, 1, true)
call TriggerAddCondition(trg, Condition(function Conditions))
call TriggerAddAction(trg, function Actions)
endfunction
endscope
vJASS:
scope Wanderer initializer Init
globals
hashtable hash = InitHashtable()
endglobals
private function Conditions takes nothing returns boolean
local unit u = LoadUnitHandle(hash, 0, GetHandleId(GetLocalPlayer()))
local real x = LoadReal(hash, 0, GetHandleId(u))
local real y = LoadReal(hash, 1, GetHandleId(u))
local location l = Location(x,y)
local rect r = RectFromCenterSizeBJ(l,100,100)
if RectContainsUnit(r,u) then
call RemoveRect(r)
call RemoveLocation(l)
set u = null
return true
endif
call RemoveRect(r)
call RemoveLocation(l)
set u = null
return false
endfunction
private function Actions takes nothing returns nothing
local real x
local real y
local unit u = LoadUnitHandle(hash, 0, GetHandleId(GetLocalPlayer()))
local location ul = GetUnitLoc(u)
local integer t = LoadInteger(hash, 2, GetHandleId(u))
local location l = PolarProjectionBJ(ul, GetRandomReal(500,1500), GetRandomReal(0,360))
//SETTING X AND Y TO CURRENT LOCATION
set x = LoadReal(hash, 0, GetHandleId(u))
set y = LoadReal(hash, 1, GetHandleId(u))
//SETTING CURRENT LOCATION ORIGINAL TERRAIN
call SetTerrainType(x, y, t, 1, 1, 0)
//UPDATING X AND Y TO NEW LOCATION
set x = GetLocationX(l)
set y = GetLocationY(l)
//SAVING NEW LOCATION ORIGINAL TERRAIN
call SaveInteger(hash, 2, GetHandleId(u), GetTerrainType(x, y))
//SAVING NEW LOCATION
call SaveReal(hash, 0, GetHandleId(u), x)
call SaveReal(hash, 1, GetHandleId(u), y)
//ISSUING ORDER AND CHANGING NEW LOCATION TO SNOW
call IssuePointOrderLoc(u, "move", l)
call SetTerrainType(x,y,'Wsnw',-1,1,0)
//CLEARING LEAKS
set u = null
call RemoveLocation(l)
call RemoveLocation(ul)
endfunction
private function Init takes nothing returns nothing
local trigger trg = CreateTrigger()
local unit u = CreateUnit(GetLocalPlayer(),'hgry',0,0,GetRandomReal(0,360))
local real x = GetUnitX(u)
local real y = GetUnitY(u)
call SaveReal(hash, 0, GetHandleId(u), x)
call SaveReal(hash, 1, GetHandleId(u), y)
call SaveInteger(hash, 2, GetHandleId(u), GetTerrainType(x, y))
call SaveUnitHandle(hash, 0, GetHandleId(GetLocalPlayer()), u)
call TriggerRegisterTimerEvent(trg, 0.2, true)
call TriggerAddCondition(trg, Condition(function Conditions))
call TriggerAddAction(trg, function Actions)
set u = null
set trg = null
endfunction
endscope
Attachments
Last edited: