- Joined
- Nov 30, 2007
- Messages
- 1,202
I can't figure out what im Doing wrong. I'm trying to fetch a Table based on GetHandleId(unit) but for some reason the struct attributes rect r and integer zoneId is always null when onLeaevZone is executed.
JASS:
library DogSetup initializer Init
globals
private player neutral = Player(PLAYER_NEUTRAL_AGGRESSIVE)
private rect array zones
private group array dogGroup
private constant integer REGULAR_WOLF = 'n000'
private Table table
endglobals
struct Dog
integer zoneId
rect r
unit u
timer t
integer minWander
integer maxWander
static method create takes integer unitType, integer zoneId, integer min, integer max returns thistype
local thistype this = .allocate()
local location p = GetRandomLocInRect(zones[zoneId])
local real x = GetLocationX(p)
local real y = GetLocationY(p)
call RemoveLocation(p)
set this.r = zones[zoneId]
set this.u = CreateUnit(neutral, unitType, x, y, bj_UNIT_FACING)
set table[GetHandleId(this.u)] = this
call GroupAddUnit(dogGroup[zoneId], this.u)
set this.zoneId = zoneId
call BJDebugMsg("zoneId: " + I2S(this.zoneId))
call this.setWanderInterval(min, max)
return this
endmethod
method setWanderInterval takes integer min, integer max returns nothing
set minWander = min
set maxWander = max
endmethod
method randomMove takes nothing returns nothing
local location p = GetRandomLocInRect(zones[this.zoneId])
call BJDebugMsg("Zone: " + I2S(this.zoneId))
call IssuePointOrderLocBJ(this.u, "move", p)
call PingMinimapLocForForceEx(GetPlayersAll(), p, 1, bj_MINIMAPPINGSTYLE_SIMPLE, 100, 100, 100)
call RemoveLocation(p)
set p = null
call BJDebugMsg("Random Move: " + I2S(this.zoneId))
endmethod
private static method doWander takes nothing returns nothing
endmethod
endstruct
function spawnDogs takes nothing returns nothing
endfunction
private function OnLeaveZone takes nothing returns boolean
local unit u = GetTriggerUnit()
local Dog dog
if (GetOwningPlayer(u) == neutral) then
set dog = Table[GetHandleId(u)]
if (dog != 0) then
call dog.randomMove()
endif
endif
set u = null
return false
endfunction
private function Init takes nothing returns nothing
local integer i = 0
local integer j
local real h
local real w
local real factor
local integer numOfWolves
local trigger tLeaveZone = CreateTrigger()
local Dog dog
set zones[0] = gg_rct_Lane00
set zones[1] = gg_rct_Lane01
set zones[2] = gg_rct_Lane02
set zones[3] = gg_rct_Lane03
set zones[4] = gg_rct_Lane04
set zones[5] = gg_rct_Lane05
set zones[6] = gg_rct_Lane06
set zones[7] = gg_rct_Lane07
set zones[8] = gg_rct_Lane08
set zones[9] = gg_rct_Lane09
set zones[10] = gg_rct_Lane10
set zones[11] = gg_rct_Lane11
set zones[12] = gg_rct_Lane12
set zones[13] = gg_rct_Lane13
set zones[14] = gg_rct_Lane14
set zones[15] = gg_rct_Lane15
set zones[16] = gg_rct_Lane16
set table = Table.create()
call TriggerAddCondition(tLeaveZone, Condition(function OnLeaveZone))
loop
exitwhen zones[I] == null
set dogGroup[I] = CreateGroup()
call TriggerRegisterLeaveRectSimple(tLeaveZone, zones[I])
set h = GetRectHeightBJ(zones[I])
set w = GetRectWidthBJ(zones[I])
set factor = 344064.00
set numOfWolves = R2I(w*h/factor)
call BJDebugMsg("Wolves: " + I2S(numOfWolves))
set j = 0
loop
exitwhen j == numOfWolves
call Dog.create(REGULAR_WOLF, i, 3, 9)
set j = j + 1
endloop
set i = i + 1
endloop
endfunction
endlibrary
Last edited: