morthon 152 Posted April 21, 2019 Hi, so I'm trying to spawn vehicles on predefined points using forEach loops. I need to be able to check what types of points I am selecting in the script, because i have points specifically for light vehicles, tanks and planes respectively. To do that I want to use setVariable to the objects I'm using as reference so I can filter dynamically. So far, my attempts to add variables is only producing an error: Undefined variable in expression vehicleSlots (an array). Replacing the vehicles with arrows (placeholder) is working perfectly. Any help would be appreciated. _findVehicleSlots = nearestObjects [[5100,5100], ["B_Truck_01_covered_F"],5100]; vehicleSlots = { _vehicleSlotPos = getPos _x; _vehicleSlotRot = getDir _x; deleteVehicle _x; _createVehicleSlot = createVehicle ["Sign_Arrow_Direction_F", _vehicleSlotPos, [], 0, "CAN_COLLIDE"]; _createVehicleSlot setDir _vehicleSlotRot; _createVehicleSlot setVariable ["SLOTTYPE", "VEHICLE"]; _createVehicleSlot enableSimulationGlobal false; } forEach _findVehicleSlots; Cheers! Share this post Link to post Share on other sites
pierremgi 4906 Posted April 21, 2019 You should rethink entirely what you want. As is, it's not understandable and that's not so clear for you: - you are searching for some trucks (array) - then, delete them - create some arrow signs instead, ... with the truck's direction (why not) - then disabling simulation on these arrows?? You should directly hide/disable sim on trucks then enable/un-hide them with code. Or, you can place markers/logics/triggers, with specific names you want, in which there is the class of what you want to spawn... or, apply some classes to an array of positions... Share this post Link to post Share on other sites
morthon 152 Posted April 22, 2019 So the idea is that I am placing trucks and tanks etc in the editor so I know the points I will later use to spawn vehicles actually have enough physical space to do so. The arrows are visual placeholders for the spawn points (I will make them invisible later). The reason I am not using markers is because I want to store data (variables) on the vehicles occupying the space inside the arrow entity. As far as I am aware you can't store variables in markers. I disabled simulation on the arrows because I am scared that they might hog performance, being as they are entities. I figured it couldn't hurt. In any case, I fixed my issue. This is what I ended up with: _findVehicleSlots = nearestObjects [[5100,5100], ["B_Truck_01_covered_F"],5100]; { _vehicleSlotPos = getPos _x; _vehicleSlotRot = getDir _x; deleteVehicle _x; _createVehicleSlot = createVehicle ["Sign_Arrow_Direction_F", _vehicleSlotPos, [], 0, "CAN_COLLIDE"]; _createVehicleSlot setDir _vehicleSlotRot; _createVehicleSlot setVariable ["slotType", "VEHICLE"]; _createVehicleSlot setVariable ["slotOccupied", "NO"]; _createVehicleSlot enableSimulationGlobal false; vehicleSlots append [_createVehicleSlot]; } forEach _findVehicleSlots; Now I have another question. I would like to give each arrow a variable name. Right now I am just storing them as elements in an array, but I would like to give them global variable names to then store inside another array. Is this inefficient or redundant? If you could give me advice, that would be great! Share this post Link to post Share on other sites
sarogahtyp 1109 Posted April 23, 2019 I think it's redundant because you already stored the arrows in an array. But it's even possible with setVehicleVarName but you have to read the wiki entry carefully to get it work. Also I think you don't need your arrows. you could just store all information in an array instead of creating an object which is not needed: _findVehicleSlots = nearestObjects [[5100,5100], ["B_Truck_01_covered_F"],5100]; { _vehicleSlotPos = getPos _x; _vehicleSlotRot = getDir _x; deleteVehicle _x; _d = vehicleSlots pushBack [false, _vehicleSlotPos, _vehicleSlotRot]; } count _findVehicleSlots; now you have your desired vehicle slots with state, position and direction in your vehicleSlots array. from there you can simply spawn any vehicle you like to... A solution for spawning all such vehicles which are near players could be: _desiredDist = 1000; // range for spawning vehicles near players _vehicleClassNames = ["...", "...", "..."]; // add vehicle classnames as you like _desiredDistSqr = _desiredDist ^ 2; //square distance for faster distance measuring _justPlayers = (allPlayers - entities "HeadlessClient_F") select {alive _x}; // get all alive players // select all slots near players where _state is false (no vehicle spawned) _spawnArray = vehicleSlots select { _x params ["_state", "_pos"]; !_state and {_justPlayers findIf {_x distanceSqr _pos < _desiredDistSqr} > -1} }; //spawn vehicles and store them in spawnedVehicles array { _x params ["_state", "_pos", "_dir"]; _rndClassname = selectRandom _vehicleClassNames _vehicle = createVehicle [_rndClassname, _pos, [], 0, "CAN_COLLIDE"]; _vehicle setDir _dir; _d = spawnedVehicles pushBack _vehicle; //update vehicleSlots array vehicleSlots = vehicleSlots - _x; _d = vehicleSlots pushBack [true, _pos, _dir]; } count _spawnArray; after that you have all spawned vehicle objects added to spawnedVehicles array for later use. EDIT: spawn solution without arrows added Share this post Link to post Share on other sites