Jump to content
Sign in to follow this  
hogmason

playable units array near object

Recommended Posts

So i have an if command that will fire up if a playable unit is within 30 mtrs of a crashed helicopter

i have an array of all playable unit names and am trying the below but its not working i know the if (_players_array is not correct i just placed that there for a demo of what i am trying to do. i just need to figure out how to use the array.


_players_array = [sgt,Medic2,Medic,Sniper,Machinegunner,Morter,Scout,FAC,IED_TECH,Ammo,AssualtTrooper,AssualtTrooper_1,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11];

	if (_players_array distance _crashed_chopper <30) then
	{ 

	hint "Hold This Position untill further notice";
                         // Waves of enemy
                          [] execVM "missions\common\wave.sqf";

	}; 

how would i make this code work

Share this post


Link to post
Share on other sites

A simple trigger would probably do the job.

Is it dynamically spawned, or is your crashed chopper set up in the editor?

Edit: By the way, you might want to use the count command.

For a trigger:

this && {_x in players_array} count thislist

Edited by BlackMamb

Share this post


Link to post
Share on other sites

Then you need to create that trigger via script:

_trg=createTrigger["EmptyDetector", getPosATL crashed_chopper]; 
_trg setTriggerArea[30,30,0,false];
_trg setTriggerActivation["WEST","PRESENT",false];
_trg setTriggerStatements["this && {_x in players_array} count thislist", "Wave = true; publicVariable Wave;", ""]; 

Then, Wave is broadcasted as true, and you can use either another trigger or a waitUntil condition to execute whatever script you need running after that.

Share this post


Link to post
Share on other sites

im getting this error

Error in expression <this && {_x in players_array} count thislist>

Error position: <&& {_x in players_array} count thislist>

Error &&: Type Number, expected Bool,code

---------- Post added at 22:43 ---------- Previous post was at 22:42 ----------

this is what i done highlighted in red

waituntil {!isnil "bis_fnc_init"};

//crash site marker
[] call TOD_crash_mkr;



//crashed chopper
if (isServer) then 
{
[color="#FF0000"]players_array[/color] = [sgt,Medic2,Medic,Sniper,Machinegunner,Morter,Scout,FAC,IED_TECH,Ammo,AssualtTrooper,AssualtTrooper_1,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11]; 

    if (isnil "Site_Secure") then {Site_Secure = 0;};
     if (isnil "Site_Overrun") then {Site_Overrun = 0;};
	  if (isnil "Survivors_dead") then {Survivors_dead = 0;};
	   [color="#FF0000"]if (isnil "Wave") then {Wave = 0;};[/color]

	 	Site_Secure = 1; publicvariable "POWs_rescued";
         Site_Overrun = 1; publicvariable "POWs_death_Limit";
		  Survivors_dead = 1; publicvariable "Survivors_dead"; 

  _Survivor_grp = createGroup west;  
   _crash_type = ["UH1Wreck","UH60_wreck_EP1","C130J_wreck_EP1"] call BIS_fnc_selectRandom;
    [color="#FF0000"]_crashed_chopper[/color] = createVehicle [_crash_type, (getMarkerPos "Crash_Site"), [], 0, "NONE"];

//Survivors
	  _Survivor_choice = ["USMC_Soldier_Officer","US_Soldier_Officer_EP1","BAF_Soldier_Officer_MTP"] call BIS_fnc_selectRandom;

		 Survivor = _Survivor_grp createUnit [_Survivor_choice, (MarkerPos "Crash_Site"), [], 0, "FORM"];
          sleep 0.2;
              Survivor switchMove "AinjPpneMstpSnonWrflDnon";
               Survivor setcaptive true;
                Survivor setBehaviour "CARELESS";
                 Survivor disableAI "MOVE";
                  removeAllWeapons Survivor; 
                   Survivor setVehicleInit "this addAction ['Rescue Him!', 'missions\scripts\rescue.sqf'];";					   
				     sleep 1;

		 Survivor1 = _Survivor_grp createUnit [_Survivor_choice, (MarkerPos "Crash_Site"), [], 0, "FORM"];
          sleep 0.2;
              Survivor1 switchMove "AinjPpneMstpSnonWrflDnon";
               Survivor1 setcaptive true;
                Survivor1 setBehaviour "CARELESS";
                 Survivor1 disableAI "MOVE";
                  removeAllWeapons Survivor1; 
                   Survivor1 setVehicleInit "this addAction ['Rescue Him!', 'missions\scripts\rescue.sqf'];";
			        processInitCommands;
				    sleep 1;

   [_crashed_chopper] call Enemy_wave_mkrs;  

_[color="#FF0000"]trg=createTrigger["EmptyDetector", getPosATL _crashed_chopper]; 
_trg setTriggerArea[30,30,0,false];
_trg setTriggerActivation["WEST","PRESENT",false];
_trg setTriggerStatements["this && {_x in players_array} count thislist", "Wave = 1; publicVariable Wave;", ""];[/color]


   waitUntil { Wave == 1 }; 

	[sgt,nil,rgroupChat,"HOLD THIS POSITION."] call RE;
        [] execVM "missions\common\init_wave.sqf";





Share this post


Link to post
Share on other sites
A simple trigger would probably do the job.

Is it dynamically spawned, or is your crashed chopper set up in the editor?

Edit: By the way, you might want to use the count command.

For a trigger:

this && {_x in players_array} count thislist

That returns how many that are in the array, to make it a boolean you need to add e.g > 0

this && {_x in players_array} count thislist > 0

@hogmason, you're trying to measure the distance of an array to a position :) Distance needs an object or position.

Try this, instead of checking distance of an array to an object (doesn't work), we check each individual object in the array and their distance to the position and finally we check if that number is greater than 0 (boolean)

_players_array = [sgt,Medic2,Medic,Sniper,Machinegunner,Morter,Scout,FAC,IED_TECH,Ammo,AssualtTrooper,AssualtTrooper_1,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11];
if (({(_x distance _crashed_chopper) <30} count _players_array) > 0 ) then		{ 
	hint "Hold This Position untill further notice";
                         // Waves of enemy
                          [] execVM "missions\common\wave.sqf";

	};

Share this post


Link to post
Share on other sites
That returns how many that are in the array, to make it a boolean you need to add e.g > 0

Of course. Just forgot it when copy/pasting the suff.

Share this post


Link to post
Share on other sites

what about to check if enemy ai are within 30 mtrs so i can fail the task for it was over run

i thought something like this but dont work i looked around but cant find anything.


_totalEnemy = {_x == EAST} count allUnits;	
if (({(_x distance _crashed_chopper) <30} count _totalEnemy) > 0 ) exitWith		


Share this post


Link to post
Share on other sites

{_x == EAST}

You're comparing an object to a side, that doesn't work.

Try this instead

{side _x == EAST}

Share this post


Link to post
Share on other sites

cheers mate but its not working no rpt error either


_totalEnemy = {side _x == EAST} count allUnits;	

if (({(_x distance _crashed_chopper) <30} count _totalEnemy) > 0 ) exitWith
 {
  hint "test to see if the ai end task";
 };

Share this post


Link to post
Share on other sites

Same issue I was pointing at the beginning: the if check is performed only once. As it's not true, nothing happens, and it's not performed anymore.

So, you either need to include that in a loop (in a separate thread that is, if you have code beneath it, so that it keeps doing whatever needs to be done) or create a trigger with that condition.

Share this post


Link to post
Share on other sites

Sorry my fualt it is inside a loop

---------- Post added at 21:38 ---------- Previous post was at 21:32 ----------

this is the code this subject highlighted in red


========= other code up here spawning shit ============= then i have

 [color="#FF0000"]  while {true} do 
{

     if (({(_x distance _crashed_chopper) <30} count _players_array) > 0 ) exitWith		
     { 
	    [sgt,nil,rgroupChat,"HOLD THIS POSITION."] call RE;
           [] execVM "missions\common\init_wave.sqf";

  };[/color]



   };
sleep 60;
[color="#FF0000"]_totalEnemy = {side _x == EAST} count allUnits;	[/color]	 

//End Task
   _grp = units _Survivor_grp;
while {Site_Secure == 1 && Site_Overrun == 1 && Survivors_dead == 1} do 
{

	if (count _grp < 1) exitWith //set condition of survivors dead
	{

	    Survivors_dead = 0; publicvariable "Survivors_dead";
	         [sgt,nil,rgroupChat,"All the Survivors Have been Killed!"] call RE;		   
		       deleteMarker "Crash_Site";
                  deleteMarker "spawn1";
		       deleteMarker "spawn2";
		       deleteMarker "spawn3";
		       deleteMarker "spawn4";
		       deleteMarker "spawn5";
                  deleteVehicle Survivor; 
                  deleteVehicle Survivor1;						
               ["AircraftDown","failed"] call SHK_Taskmaster_upd;
               [] call SHK_addTask;				 
	};

[color="#FF0000"]		if (({(_x distance _crashed_chopper) <30} count _totalEnemy) > 0 ) exitWith //set condition of enemy units near crash site
	{

	    Site_Overrun = 0; publicvariable "Site_Overrun";
	         [sgt,nil,rgroupChat,"The Enemy Have over run the crash site RETREAT!"] call RE;
                   sleep 60;				 
		       deleteMarker "Crash_Site";
                  deleteMarker "spawn1";
		       deleteMarker "spawn2";
		       deleteMarker "spawn3";
		       deleteMarker "spawn4";
		       deleteMarker "spawn5";
                  deleteVehicle Survivor; 
                  deleteVehicle Survivor1;				   
               ["AircraftDown","failed"] call SHK_Taskmaster_upd;
               [] call SHK_addTask;			
	};[/color]

	if ({(_x distance POW_safe) <30} count _grp  == (count _grp)) exitWith // set condition of survivor back at base.
	{

         	Site_Secure = 0; publicvariable "Site_Secure";
			 sleep 20;
	         [sgt,nil,rgroupChat,"Well done boys you saved the Survivors and held the crash site position!"] call RE;		   
		       deleteMarker "Crash_Site";
                  deleteMarker "spawn1";
		       deleteMarker "spawn2";
		       deleteMarker "spawn3";
		       deleteMarker "spawn4";
		       deleteMarker "spawn5";
                  deleteVehicle Survivor; 
                  deleteVehicle Survivor1;			   
		       ["AircraftDown","succeeded"] call SHK_Taskmaster_upd; 
               [] call SHK_addTask;				   
	};
	{
		if (!alive _x) then {_grp = _grp - [_x]};
	} foreach _grp;		
	sleep 1;

};



---------- Post added at 21:42 ---------- Previous post was at 21:38 ----------

got this error in rpt now


Error in expression < (({(_x distance _crashed_chopper) <30} count _totalEnemy) > 0 ) exitWith 
{

Si>
 Error position: <count _totalEnemy) > 0 ) exitWith 
{

Si>
 Error count: Type Number, expected Array
File C:\Users\natho\Documents\ArmA 2 Other Profiles\=Mason=\missions\TOUR_OF_DUTY_v1.Takistan\missions\tasks\tsk_Aircraft_down.sqf, line 92

Share this post


Link to post
Share on other sites

Oh yeah, I'm stupid. You have your answer right there in your RPT.

Error count: Type Number, expected Array

_totalEnemy is a number (you used count to create it). Count needs an array as input, and gives you a number as a return value.

So you need to have _totalEnemy as an array. Which is going to be difficult if they're spawned dynamically troughout the mission.

There would be ways to do that, although a simple trigger with EAST PRESENT as conditions will do that really easily.

Share this post


Link to post
Share on other sites

yeah i think i might go the trigger then something like (ive never really created triggers via code) this

_trg=createTrigger["EmptyDetector", getPosATL crashed_chopper]; 
_trg setTriggerArea[30,30,0,false];
_trg setTriggerActivation["EAST","PRESENT",false];
_trg setTriggerStatements["this", "Site_Overrun = 0; publicvariable "Site_Overrun";", ""];



will that work

---------- Post added at 21:59 ---------- Previous post was at 21:56 ----------

and to delete a trigger id use deleteVehicle _trg correct

Share this post


Link to post
Share on other sites

Now you have!

Yeah, that should work, but maybe don't use _trg if you already used that in the same code.

About the public variable, I stuck that in there the first time cause I didn't know/didn't exactly read what you were trying to achieve. Now if that trigger executes some script serverside only, you don't need that. This is just a way (amongst others) to synchronize triggers effects on all clients in a MP mission.

Share this post


Link to post
Share on other sites

i thought wit the pub variable it would let me update an if command like such


_trg=createTrigger["EmptyDetector", getPosATL crashed_chopper]; 
_trg setTriggerArea[30,30,0,false];
_trg setTriggerActivation["EAST","PRESENT",false];
_trg setTriggerStatements["this", "Site_Overrun = 0; publicvariable Site_Overrun;", ""];




//now later inside a loop

if (Site_Overrun == 0) exitWith

---------- Post added at 22:05 ---------- Previous post was at 22:04 ----------

hold on i think i just digested that you mean use the

Site_Overrun = 0;

but dont need

publicvariable Site_Overrun

unless its not run server side.

---------- Post added at 22:06 ---------- Previous post was at 22:05 ----------

im only winging all this variable stuff have no idea bout them except use them to update changes for if commands and such never really found a good tut on them ;)

---------- Post added at 22:10 ---------- Previous post was at 22:06 ----------

getting this error with that trigger

_trg=createTrigger["EmptyDetector", getPosATL>

Error position: <createTrigger["EmptyDetector", getPosATL>

Error 0 elements provided, 3 expected

Share this post


Link to post
Share on other sites

Little tip:

add, for debug purposes, something like

hint format ["%1", getPosATL crashed_chopper];

right before you create the trigger. This will give you a hint with the values of that array. You'll immediately see if that position is defined or not.

Regarding the "variables stuff", here's what I can tell you:

- local variables (_myLocalVariable) are local to the script they've been defined in.

This means that you define and use that variable inside a script and affect a value to it, say _myLocalVariable = 2;

Now if you try and access that variable from another script, it will still be undefined (nil).

Note that:

- those variables will be accessed and modified by functions called inside that script, so you should use

private [_myLocalVariable];

when using it again in a function, so that it doesn't modify the variable in your first script.

- Local variables initialized in Control Structures (e.g an if check) are local to that structure and stay undefined in the rest of your script.

- global variables (myGlobalVariable) are local to the whole computer the script is executed on. You can access those from any script on that computer.

In MP, the values are not broadcasted to each client. So, if in your init.sqf, you define myGlobalVariable = 0;

Every client and the server will have that varaible defined, with an associated value of 0.

Now if a script executed on your server only changes it to myGlobalVariable = 1;

this will have only an effect on the server. All clients will still have an associated value of 0 to that variable.

For example, a trigger waiting for myGlobalVariable == 1 will only be activated on the server.

- public variables (myPublicVariable) are created by broadcasting a global variable to the whole network using the publicVariable command.

e.g You've defined myPublicVariable = 0; in the init.sqf. All clients and the server have a value of 0 associated with that variable.

Let's say a script executed on one machine only changes it to:

myPublicVariable = 2;
publicVariable "myPublicVariable";

Now all machines have an associated value of 2 to that variable.

Every machine waiting for myPublicVariable == 2 will now execute the associated code.

Note that:

- publicVariable must be executed everytime you want a value to be broadcasted. Meaning that if you change that value back to 0 on the server, you need to

use publicVariable again to synchronize that new value on each machine.

- public varaibles are automatically synchronized to JIP.

- publicVariable cannot be used, for obvious reasons, on local variables.

- Variables can be assigned to a specific object using the setVariable command, and then retrieved with getVariable.

This allows to store information regarding a number of specific objects without creating 200 variables with different names. It can also be another way to broadcast

values over the network.

Hope this is at least a bit clear.

Now, knowing that, every scripter will find his own ways to do stuff. The possibilities are limitless.

There are other commands and ways to play with public values. Publicvariableclient, for example, or GameLogics value. But these are the basics.

Edited by BlackMamb

Share this post


Link to post
Share on other sites

awsome cheers mate that will definatly get me on my way ;) ;)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×