Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,219
Yet another vjass problem.. yay..
the system is supposed to make a unit patrol between x number of way points.
Just to confirm a few things that I've found out so far:
1. the locations are successfully stored into the hashtable. The following code creates the units exactly where they are supposed to be.
2. the loops numbers work fine too. The message displays the following:
i 1
i2 2
i 3
i2 4
i 5
i2 6
i 7
i2 8
3. if I use the following line the unit wont move at all, I can't issue anything. I suspect it's because the loop orders him to move to his current location.
however, if I use the following..
the unit wont move at all, I can order him around but he wont move to the next point.
the system is supposed to make a unit patrol between x number of way points.
JASS:
globals
group patrolUnits = CreateGroup()
hashtable patrolHash = InitHashtable()
endglobals
function patrol takes unit u, integer locationCount returns nothing
local integer i = GetHandleId(u)
local integer loopCount = 0
local real array x
local real array y
call GroupAddUnit(patrolUnits, u)
loop
exitwhen loopCount > locationCount
set loopCount = loopCount + 1
set x[loopCount] = GetLocationX(udg_patrol_points[loopCount])
set y[loopCount] = GetLocationY(udg_patrol_points[loopCount])
endloop
call SaveInteger(patrolHash, i, 0, locationCount)
call SaveReal(patrolHash, i, 1, x[1])
call SaveReal(patrolHash, i, 3, x[2])
call SaveReal(patrolHash, i, 5, x[3])
call SaveReal(patrolHash, i, 7, x[4])
call SaveReal(patrolHash, i, 2, y[1])
call SaveReal(patrolHash, i, 4, y[2])
call SaveReal(patrolHash, i, 6, y[3])
call SaveReal(patrolHash, i, 8, y[4])
/*
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 1), LoadReal(patrolHash, i, 2)), bj_UNIT_FACING )
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 3), LoadReal(patrolHash, i, 4)), bj_UNIT_FACING )
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 5), LoadReal(patrolHash, i, 6)), bj_UNIT_FACING )
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 7), LoadReal(patrolHash, i, 8)), bj_UNIT_FACING )
*/
call IssuePointOrderLocBJ(u, "attack", Location(LoadReal(patrolHash, i, 1), LoadReal(patrolHash, i, 2)))
endfunction
function Group takes nothing returns nothing
local unit u = GetEnumUnit()
local integer h = GetHandleId(u)
local location array locs
local location uLoc = GetUnitLoc(u)
local integer i = -1
local integer i2 = 0
loop
exitwhen i2 >= LoadInteger(patrolHash, h, 0) * 2
call BJDebugMsg(R2S(DistanceBetweenPoints(uLoc, locs[i])))
set i = i + 2
set i2 = i2 + 2
call BJDebugMsg("i " + I2S(i))
call BJDebugMsg("i2 " + I2S(i2))
set locs[i2] = Location(LoadReal(patrolHash, h, i), LoadReal(patrolHash, h, i2))
if DistanceBetweenPoints(uLoc, locs[i2]) < 50 then
if i2 >= 4 then
call IssuePointOrderLocBJ(u, "move", locs[1])
call BJDebugMsg("moving to point 1")
else
call IssuePointOrderLocBJ(u, "move", locs[i2 + 1])
call BJDebugMsg("moving to point" + I2S(i2))
endif
endif
endloop
endfunction
function patrolUpdate takes nothing returns nothing
call ForGroup(patrolUnits, function Group)
endfunction
//===========================================================================
function InitTrig_Patrol_System takes nothing returns nothing
set gg_trg_Patrol_System = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Patrol_System, 0.03 )
call TriggerAddAction( gg_trg_Patrol_System, function patrolUpdate )
endfunction
Just to confirm a few things that I've found out so far:
1. the locations are successfully stored into the hashtable. The following code creates the units exactly where they are supposed to be.
JASS:
/*
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 1), LoadReal(patrolHash, i, 2)), bj_UNIT_FACING )
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 3), LoadReal(patrolHash, i, 4)), bj_UNIT_FACING )
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 5), LoadReal(patrolHash, i, 6)), bj_UNIT_FACING )
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), Location(LoadReal(patrolHash, i, 7), LoadReal(patrolHash, i, 8)), bj_UNIT_FACING )
*/
2. the loops numbers work fine too. The message displays the following:
i 1
i2 2
i 3
i2 4
i 5
i2 6
i 7
i2 8
3. if I use the following line the unit wont move at all, I can't issue anything. I suspect it's because the loop orders him to move to his current location.
JASS:
call IssuePointOrderLocBJ(u, "move", locs[i2])
however, if I use the following..
JASS:
call IssuePointOrderLocBJ(u, "move", locs[i2 + 1])
the unit wont move at all, I can order him around but he wont move to the next point.
Attachments
Last edited: