Jump to content
Sign in to follow this  
alleycat

How to check for a player slot?

Recommended Posts

How to check for a player slot?

The only way I found was to name the object in the editor and act on that, but the game keeps showing errors about it not existing if that player slot is not taken.

if (!(isnil b")) then
{
if (b1 == player) then
{

};
};

Share this post


Link to post
Share on other sites

if (!isNil "b1") then {
if (b1 == player) then {
}:
};

waitUntil {!isNil "b1"};
if (isPlayer b1) then {
}:

Hope these help. :)

Dirty Haz

Share this post


Link to post
Share on other sites

Thanks, however it does not work in multiplayer. When the b1 unit is not used by a player it throws an error. Is there really no way to check for some things existence without the game throwing errors?

Share this post


Link to post
Share on other sites

Yes. These should work:

waitUntil {!isNil "b1"};

if (isNil "b1") exitWith {};

if (isNil "b1") then {b1 = player};

Dirty Haz

Share this post


Link to post
Share on other sites

Thanks, exitwith fixed the problem

Share this post


Link to post
Share on other sites

Is it possible to check what slot/object the LOCAL player is? I think the solution above only checks for wether an object exists.

Share this post


Link to post
Share on other sites

Just use "player":

if (player == b1) then {

};

Since player only refers to the local player.

Share this post


Link to post
Share on other sites
if (isServer) then{
{
if (isPlayer _x) then {
//do something - _x refers to a player 
};
}forEach playableUnits;
};

Share this post


Link to post
Share on other sites
That won't check for the local player though

if you are checking for a local player:

{
if (player == _x) then {
//_x is the local player - add what to do to _x here
};
}foreach playableUnits;

Share this post


Link to post
Share on other sites

Thanks, but I still cant get the part to work that checks for what player slot a player selected.

Share this post


Link to post
Share on other sites
Thanks, but I still cant get the part to work that checks for what player slot a player selected.

You still need to name your units for that and check for

if (!isNil "p1") then {
    if (player == p1) then {
         yourcode
    };
};

otherwise you have no option to check for the player being in a specific slot/playing a specific unit.

  • Thanks 1

Share this post


Link to post
Share on other sites

yay thanks, I think that should work

Share this post


Link to post
Share on other sites

if you would have listed all these criteria in the first post, this would have been a much faster exercise - just sayin

  • Like 1

Share this post


Link to post
Share on other sites
On 5/17/2014 at 3:56 PM, Belbo said:

You still need to name your units for that and check for

 


if (!isNil "p1") then {
    if (player == p1) then {
         yourcode
    };
};
 

 

otherwise you have no option to check for the player being in a specific slot/playing a specific unit.

 

Thanks, @Belbo

Finally something that works here!

if (!isNil "playerName") then														// if the string (unit player name) exist, so...
{
    if (player == playerName) then 													// if the player in initPlayerLocal.sqf is playerName, so... 
    { 
     	//code
    };
};

 

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  

×