Jump to content
Sign in to follow this  
hogscraper

Question about _playerCount changing onPlayerConnected

Recommended Posts

Hello,

I've been playing around with BIS_fnc_addStackedEventhandler and onPlayerConnected/onPlayerDisconnected in an effort to welcome a player back,(among other things), when they disconnect and comes back. But what I'm running into is that when the player comes back, nothing returns the right values. I'm passing along the right variables,(I have tested both name and uid and they both always report the correct values).

_playerName = _this select 0;
_uid = _this select 1;

diag_log format["_playerName=%1",_playerName];
diag_log format["_uid=%1",_uid];
if (_playerName == '__SERVER__') exitWith {};
_player = objNull;
_playerCount = {isPlayer _x} count playableUnits;
diag_log format["_playerCount=%1",_playerCount];
while{!isplayer _player}do
{  
   {
     if (getPlayerUID _x == _uid) exitWith {
          _player = _x;
     };
   } forEach playableUnits; 
 };


_ClientID = owner _player;

The first time they connect it counts them correctly and everything I've added after that works perfectly. If they disconnect and come back it doesn't count them and always shows _ClientID==0. Anyone know a what might be causing this?

I originally thought maybe it was because I was using deletevehicle to remove their corpse from the battlefield but I got rid of that and ran a barebones mission. Nothing but my onconnect/disconnect. Five players on and it shows _playercount==5. One leaves and comes back and it shows _playercount==4 and I can't send any publicvariableClient to reconnected players as it shows their clientID as zero. Any help or guidance here would be appreciated!

Share this post


Link to post
Share on other sites

It could be a locality/JIP issue with the player along with the owner command, according to the owner command wiki. It will return 0 if it doesn't get the ID local object from the machine.

Edited by JShock

Share this post


Link to post
Share on other sites

Because unit belongs to the server (id:0) until client puts player in it, at which point it changes locality and ownership. Matching uid is not enough, the unit can still be !isPlayer.

Share this post


Link to post
Share on other sites

I have it set in my onplayerconnected so that it keeps iterating

while{!isplayer _player}do

but for reconnecting players only it never shows isplayer _player as true. I put hundreds of while loops like the above in my onplayerconnected, with a bunch of diag_logs inside, and the first time a player connects it passes immediately. On reconnect it just went ten minutes and never found the playable unit with the same PUID as the reconnecting player that was isplayer or alive. I guess what's bugging me is that the first connection is immediately transferred from server to client as owner. Its only after they log out, then back in, that it has trouble. After an extreme test of 10000 lines of while loops its apparent that on first connect it recognizes the playable unit as being alive and isplayer near instantly but on reconnect, the server will not recognize that the player is alive or isplayer until after everything in onplayerconnected has run, which kind of defeats the purpose. This is using the latest dev build.

It looks like nothing works between server and client from when onplayerconnected starts and when it finishes ONLY if the player has disconnected then reconnects. Like the server is treating a client differently if they had previously connected but I've never read anything that can confirm that. Maybe I need to just get past that section, THEN find their playerobj, THEN run what I need to. I'll see what happens if I just move players to a debug area from onplayerconnected, and use a trigger to catch when they spawn and from there run everything that was in onplayerconnected.

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  

×