Midnighters 152 Posted January 29, 2018 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
davidoss 552 Posted January 29, 2018 { if(isPlayer _x) then { /*etc*/ }; } forEach allPlayers; 1 Share this post Link to post Share on other sites
Midnighters 152 Posted January 30, 2018 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
MKD3 27 Posted January 30, 2018 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
pierremgi 4853 Posted January 30, 2018 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
Midnighters 152 Posted February 3, 2018 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
Midnighters 152 Posted February 3, 2018 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
pierremgi 4853 Posted February 3, 2018 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
Midnighters 152 Posted February 3, 2018 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
pierremgi 4853 Posted February 3, 2018 better than what??? Share this post Link to post Share on other sites
Midnighters 152 Posted February 3, 2018 Just now, pierremgi said: better than what??? { } forEach playableUnits; //etc Share this post Link to post Share on other sites
pierremgi 4853 Posted February 3, 2018 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 1 Share this post Link to post Share on other sites
Midnighters 152 Posted February 3, 2018 Yes, there is no confusion. Thanks for your feedback pierre Share this post Link to post Share on other sites