Jump to content
Sign in to follow this  
dcthehole

Player Array Script

Recommended Posts

What I'm trying to do is go by the player slot and remove their weapons and give them new ones which I didn't decide on yet thats why they are just "". The error that I'm getting is undefined variable in expression p1. P1-P12 are the names of the player slots. P1-P6 are the first squad, and P7-P12 is the second squad. Does anyone know how to fix this or have any suggestions? Any help is appreciated.

private["_i","_curWep","_curAmmo"];
_curWep = currentWeapon player;
_curAmmo = currentMagazine player;
Player_Array =
[
[P1,P2,P3,P4,P5,P6],
[P7,P8,P9,P10,P11,P12]
];
for [{_i=0},{_i < (count Player_Array)},{_i=_i+1}] do
{
if(!(player in((Player_Array select _i) select 1) || ((Player_Array select _i) select 2))) then
{
	player removeWeapon _curWep;
       player removeMagazines _curAmmo;
	player addWeapon "";
	player addWeapon "";
} else {
	player removeWeapon _curWep;
       player removeMagazines _curAmmo;
	player addWeapon "";
	player addWeapon "";
};
};

Edited by dcthehole

Share this post


Link to post
Share on other sites

if its just 2 groups why not just use

{removeAllWeapons _x} forEach units group this;

then add weapons and ammo same way.

if u cant use that your player array should look like

Player_Array = ["p1","p2","p3"];

and so on...

Share this post


Link to post
Share on other sites

What you're essentially doing is select _i, which isn't more than 0, ever. Your code only executes once because as a condition you wrote "_i < (count playerarray)". Use <= instead if you want it to be 1.

You also have a nested array.

So lets take your first code, and _i is 0.

(playerarray select _i) select 0

This selects the first nested array and selects the first unit out of it. So P1. Switch things around. If I'm not mistaken here count playerarray will only equal to 1 as it shouldn't count things inside nested arrays.

Share this post


Link to post
Share on other sites

Ok, so something like this?

private["_i","_curWep","_curAmmo"];
_curWep = currentWeapon player;
_curAmmo = currentMagazine player;
Player_Array =
[
   [P1,P2,P3,P4,P5,P6],
   [P7,P8,P9,P10,P11,P12]
];
for [{_i=0},{_i <= (count Player_Array)},{_i=_i+1}] do
{
   if(!(player in((Player_Array select _i) select 1) || ((Player_Array select _i) select 2))) then
   {
       player removeWeapon _curWep;
       player removeMagazines _curAmmo;
       player addWeapon "";
       player addWeapon "";
   } else {
       player removeWeapon _curWep;
       player removeMagazines _curAmmo;
       player addWeapon "";
       player addWeapon "";
   };
};  

Ok, thanks thats working now.

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  

×