hi all,
i'm trying to create a series of scripts to simulate a civilian (+ rebel) population on an island. rather than having them all alive at once, the populations of each town are kept in one global array. when the player gets close to a town, it spawns the population. When the player leaves the area, the civs are counted then deleted, and the global array updated. this ain't no DAC, but i'm enjoying myself...
the problem i'm having is that not all the civs spawn correctly. about 1 in 5 times, 1 or 2 don't appear. so if you go near a town, then leave and come back enough times, the population disappears. the createUnit script is trying to make the correct number, they just don't appear. i assumed it was due to creating new units too close to other objects, and have made a proximity loop, but this doesn't help (testing it on the intro map has the same problem). i've also slowed the spawn scripts right down, but that doesn't help either.
does anybody have any tips on creating several groups of units within an area, quickly and accurately? i didn't know how to set the side of a created unit, so i'm using a civilian (dummyCiv) on a far away island to create each group, then removing him from the group. i'm sure this isn't the best way to do things...
also, i plan to give these civilians some tasks to do once they spawn, such as wander around. if possible, i want only one script running to control each towns population. what is the best way to move multiple spawned groups (ie not on the map in the mission editor) without lag?
here is an overview of my scripts :
-playerMonitor.sqs
checks player position. if close to town, exec spawnTown.sqs. if far from spawned town, exec cullTown.sqs
-townSpawn.sqs
----------------------------------------------------------------------------------------------
_placeObject = _this select 0
_placeArrayElement = _this select 1
_placeCivs = placeCivsArray select _placeArrayElement
_placeRebels = placeRebelArray select _placeArrayElement
player globalChat format ["population is %1 civs, %2 rebels",_placeCivs,_placeRebels]
#spawnLoop
_randomNum = [1,4] call randomInt
[_placeObject,_randomNum,civArray] exec "spawnUnitArray2.sqs"
_placeCivs = _placeCivs - _randomNum
~5
if (_placeCivs > 4) then {goto "spawnLoop"}
~1
[_placeObject,_placeCivs,civArray] exec "spawnUnitArray2.sqs"
-------------------------------------------------------------------------------------------------------
- spawnUnitArray2.sqs
(upside down for efficiency = good??? i've adjusted the delays and spacing between each new unit without any luck. )
-------------------------------------------------------------------------------------------------------
goto "init"
#checkloop
_createPos = _objectPos
_randTheta = [360] call randomPlus
_randRange = [100] call randomPlus
_createPos = [(_createPos select 0) + _randRange * (cos _randTheta), (_createPos select 1) + _randRange * (sin _randTheta), _createPos select 2]
_nearObj = nearestObject [_createPos select 0,_createPos select 1,_createPos select 2]
hint format ["nearestObject = %1",_nearObj]
dummyLogic setPos _createPos
player globalChat format ["distance is %1", (_nearObj distance dummyLogic)]
if (_nearObj distance dummyLogic < 10) then {player globalchat "too close"; goto "checkLoop"}
~0.1
#placeLoop
;~0.2
_unitArray select ([_unitArrayCount] call randomPlus) createUnit [_createPos,_tempGroup]
_createPos = [(_createPos select 0) + 1, (_createPos select 1) + 1, _createPos select 2]
_tempLoop = _tempLoop + 1
if (_tempLoop < _numberToMake) then {goto "placeLoop"}
~0.2
[dummyCiv] join grpNull
~0.2
group dummyCiv setGroupID ["Alpha","GroupColor1"]
;hint "spawnUnitArray.sqs exiting"
exit
#init
;hint "spawnUnitArray.sqs running"
_objectPos = getPos (_this select 0)
_createPos = _objectPos
_randTheta = [360] call randomPlus
_randRange = [50] call randomPlus
_createPos = [(_createPos select 0) + _randRange * (cos _randTheta), (_createPos select 1) + _randRange * (sin _randTheta), _createPos select 2]
_numberToMake = _this select 1
_unitArray = _this select 2
_unitArrayCount = count _unitArray
_tempLoop = 0
_tempGroup = group dummyCiv
player globalChat format ["number to make = %1",_numberToMake]
~0.1
goto "checkLoop"
-------------------------------------------------------------------------------------------------------
thanks guys!!! : )