Jump to content
Sign in to follow this  
celludriel

allPlayers empty on dedicated server

Recommended Posts

hey,

 

I'm using this funciton on a onPlayerConnected listener

    setWarfundOnPlayerByPlayerUID = {
        diag_log format ["Calling setWarfundOnPlayerByPlayerUID, with %1", _this];
        _playerUID = _this select 0;
        _amount    = _this select 1;

        if(_playerUID != "") then {
            diag_log format ["allPlayers: %1", allPlayers];
            {
                if(_playerUID == getPlayerUID _x) exitWith {
                    diag_log format ["Setting warfund on %1", _x];
                    _x setVariable ["warfund", _amount, true];
                };
            } forEach allPlayers;
        };
    };

When I try this on a local server instance this works perfectly, however on a dedicated server allPlayers seems to be empty.  Here is an extract of the log

17:47:46 "Calling setWarfundOnPlayerByPlayerUID, with ["76561197962746017",100]"
17:47:46 "allPlayers: []"

Is there something else I should use to fetch all the players on a dedicated server ?  This code should ONLY run on the server btw if that is to any importance to the answer.  I'm puzzled by this one ...

Share this post


Link to post
Share on other sites

Last time I used allPlayers it worked fine. You don't happen do be on dev branch, do you?

Share this post


Link to post
Share on other sites

Nope I'm on the latest steam release, Maybe it's because I use it on the onPlayerConnected event and players are just not there yet at this point.  Otherwise I have no idea

Share this post


Link to post
Share on other sites

Nope I'm on the latest steam release, Maybe it's because I use it on the onPlayerConnected event and players are just not there yet at this point.  Otherwise I have no idea

 

OnPlayerConnected fires before there is a player object.

 

initPlayerServer.sqf executes after there is a player object.

  • Like 1

Share this post


Link to post
Share on other sites

So I tried

 

https://community.bistudio.com/wiki/BIS_fnc_addStackedEventHandler

 

I've been using the regular onPlayerConnected instead of this one, maybe this would fix it, however the result was the same.

 

BIS_fnc_addStackedEventHandler just combines all the code from stacked events into one scope.

 

["EH1","onPlayerConnected",{/* code 1 */},[]] call BIS_fnc_addStackedEventHandler

["EH2","onPlayerConnected",{/* code 2 */},[]] call BIS_fnc_addStackedEventHandler 

 

is the same as:

 

onPlayerConnected {

/* code 1 */

/* code 2 */

};

  • Like 1

Share this post


Link to post
Share on other sites

OnPlayerConnected fires before there is a player object.

 

initPlayerServer.sqf executes after there is a player object.

 

Thanks this explains the behavior, It's not what I liked to hear though, since this means I have to add custom code in initPlayerServer.sqf.  Now I hoped to have a way to add it in a file in the folder of my "mechanic", keeping it detached from the main mission files.  Now I'll have to mix variables of my mechanic inside the root files :(.  Oh well I'll live with it.

Share this post


Link to post
Share on other sites

Bah didn't work :( I need to find a better way

 

using allPlayers in  initPlayerServer.sqf still returns an empty array.  Maybe the player is only known to that function after initPlayerServer.sqf has run and not during :(

Share this post


Link to post
Share on other sites

Bah didn't work :( I need to find a better way

 

using allPlayers in  initPlayerServer.sqf still returns an empty array.  Maybe the player is only known to that function after initPlayerServer.sqf has run and not during :(

Not only allPlayers works perfectly in initPlayerServer.sqf and returns all players (just checked), _this param passed to initPlayerServer.sqf contains player object, so there is no need for allPlayers all together.

  • Like 1

Share this post


Link to post
Share on other sites

Not only allPlayers works perfectly in initPlayerServer.sqf and returns all players (just checked), _this param passed to initPlayerServer.sqf contains player object, so there is no need for allPlayers all together.

Then we have both different behaviors going on ???  Cause I can assure you I'm printing out allPlayers during initPlayerServer.sqf runs and it is empty.  But I'll check again when I get home.  However you are right ... I actually don't need allPlayers anymore if I rewrite a bit of code and pass the player object to my method instead of just the UID

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  

×