Jump to content
Midnighters

Return player object from server

Recommended Posts

Hello all, I'm curious as to grab a player / unit's object from the server.

I want to refrain from doing:

{
	if(_x == player) then
	{
		//etc
	};
} forEach allPlayers;

any good solutions to this? 

Share this post


Link to post
Share on other sites
6 hours ago, davidoss said:

{

   if(isPlayer _x) then { /*etc*/ };

} forEach allPlayers;

 

I guess I didn't put much thought into my example, but is there really not a cleaner way of doing so?

Share this post


Link to post
Share on other sites

No, player is local to the client. You have to select them just like any other object.

Share this post


Link to post
Share on other sites

Really?

If you are using allPlayers , I can't imagine you're picking some AIs by the way. isPlayer is useless here.

Player will return the local player on client or hosted server (once game started locally, more exactly).

 

Remark: playableUnits is a false friend.

For MP usage, it returns the same as switchableUnits in SP, i.e. the red circled, checked as playable, units in 3den... IF you don't disable AIs in lobby. If AIs are disabled, playableUnits is just the same as allPlayers and should be named "playedUnits" in this case. This is important because in such case, variable name (and code in init field) of the unit is nil before JIP.  If bob is a disabled AI in lobby, bob simply doesn't exist before JIP and any attempt to script with bob variable will return an error.

Share this post


Link to post
Share on other sites
On 1/30/2018 at 8:15 AM, pierremgi said:

Really?

If you are using allPlayers , I can't imagine you're picking some AIs by the way. isPlayer is useless here.

Player will return the local player on client or hosted server (once game started locally, more exactly).

 

Remark: playableUnits is a false friend.

For MP usage, it returns the same as switchableUnits in SP, i.e. the red circled, checked as playable, units in 3den... IF you don't disable AIs in lobby. If AIs are disabled, playableUnits is just the same as allPlayers and should be named "playedUnits" in this case. This is important because in such case, variable name (and code in init field) of the unit is nil before JIP.  If bob is a disabled AI in lobby, bob simply doesn't exist before JIP and any attempt to script with bob variable will return an error.

No I was never using allPlayers, just throwing an example. Thanks for your feedback though

Share this post


Link to post
Share on other sites
On 1/30/2018 at 1:24 AM, MKD3-FHI said:

No, player is local to the client. You have to select them just like any other object.

Was curious if there was a more streamlined process.

Share this post


Link to post
Share on other sites
33 minutes ago, Midnighters said:

Was curious if there was a more streamlined process.

Yes. Saying what you intend to obtain, "grabbing a player". allPlayers and isPlayer work fine on dedicated, but not player. Difficult?

Share this post


Link to post
Share on other sites
Just now, pierremgi said:

Yes. Saying what you intend to obtain, "grabbing a player". allPlayers and isPlayer work fine on dedicated, but not player. Difficult?

Not in the slightest, I was just hoping for something better than that. It's already written so.

Share this post


Link to post
Share on other sites
Just now, pierremgi said:

better than what???

{


} forEach playableUnits;
//etc

 

Share this post


Link to post
Share on other sites

working on server:

{ } forEach playableUnits;   // an array with playable units if AI aren't disabled in lobby. Forget if they are, or refresh in a loop to catch JIP

allPlayers   // an array with actual players. Same as above, refresh in a loop for JIP

selectRandom allPlayers : one player grabbed at random (with the actual allPlayers)

getPlayerUID _unit = _someId  // a specific player

 

owner

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Yes, there is no confusion. Thanks for your feedback pierre

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

×