Home   Help Search Login Register  

Author Topic: Making an array of units alive using nearestobjects  (Read 1540 times)

0 Members and 1 Guest are viewing this topic.

Offline Rejen

  • Members
  • *
Making an array of units alive using nearestobjects
« on: 27 Sep 2009, 07:37:08 »
Im making a very basic random mine generation script.

All i need at the moment is how to get an array with units that are alive in sqs.

So far I have the following:

_deadmen = nearestObjects [(getmarkerpos "mine"), ["land"], 150];

this provides me with an array of units closest to the markerpos BUT also includes all dead units, however I want just the alive units in an array form.

if i do the following it gives me a number count of units alive in the array but not in array form.

_alivemen= {alive _x} count _deadmen


I need to enter an alive condition into the following:

_deadmen = nearestObjects [(getmarkerpos "mine"), ["land"], 150];

OR translate the following into an array:

_alivemen= {alive _x} count _deadmen

can anyone help me? thanks

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Making an array of units alive using nearestobjects
« Reply #1 on: 27 Sep 2009, 12:04:10 »
Code: [Select]
private["_deadmen", "_alive_list"]

_deadmen = nearestObjects [(getmarkerpos "mine"), ["land"], 150];
_alive_list = [];
{
   if (alive _x) then 
   {
      _alive_list = _alive_list + [_x];
   };
} forEach _deadmen;

Offline Rommel92

  • Members
  • *
Re: Making an array of units alive using nearestobjects
« Reply #2 on: 12 Oct 2009, 14:39:45 »
I don't see why the extra calculation (that and I have never trusted the near commands since running them over 500 times seems to crash the game (not as reproducible in A2, but still happens)), and just use AllUnits?

Code: [Select]
private["_list", "_pos"]

_pos = (getmarkerpos "mine");
_list = [];
{
   if (alive _x and (_x distance _pos < 150)) then 
   {
      _list = _list + [_x];
   };
} forEach allUnits;

 ???

Offline tcp

  • Members
  • *
    • Violator Gaming
Re: Making an array of units alive using nearestobjects
« Reply #3 on: 12 Oct 2009, 18:43:17 »
Well, he was asking for SQS.

Using a trigger might be the easiest method for detection.

Here's my minefield script. The only thing is, it doesn't place random mines. If you go into the trigger area, simulated mines will explode around you. It's linked to your speed, so the only way to get out of the minefield safely is to stop your vehicle, get out and crawl or crouch walk. Backing up the vehicle very slowly might work, but it takes very little movement to set one off. If you try to speed through the minefield, mines will go off like crazy.

Cond:
(vehicle player in thislist)
On Act:
hint "You are entering a minefield!!!"; _minefield=[b1] execVM "minefield.sqf";

b1 has to be the name of the trigger since I don't know how to pass text field as a variable.

Code: (minefield.sqf) [Select]
//example taken from Behind Enemy Lines by laggy
if(!isServer) exitWith{};
private ["_tnam","_tgt","_delay"];
_tnam = _this select 0;
_tgt = list _tnam;
sleep 2;
while {triggerActivated _tnam} do {
{
if(speed _x < 40) then {sleep 1;};
if(speed _x < 20) then {sleep 2;};
if(speed _x > 5) then {"R_57mm_HE" createVehicle [((getpos _x) select 0) + 40 - random 80,((getpos _x) select 1) + 40 - random 80, 0];};
} forEach _tgt;
sleep 1;
_tgt = list _tnam;
};