allPlayers can be delayed on a dedicated server, causing issues for mods and missions that rely on it and expected it to be reliable.
Description
Details
- Severity
- Major
- Resolution
- Open
- Reproducibility
- Random
- Operating System
- Windows 10 x64
- Category
- Scripting
- Start mission on a dedicated server.
- Observe allPlayers vs call BIS_fnc_listPlayers after briefing ends.
- Possibly repeat steps a few times.
Wiki only states that
In a player-hosted game, the complete array of allPlayers may get delayed on mission start. Use BIS_fnc_listPlayers if you need it earlier.
Which, would imply that it should be reliable on a dedicated server, however I recently ran into an issue on a dedicated server where allPlayers wasn't returning all of the players for a bit after mission start.
Mission used to confirm issue, both with and without mods:
Test mission usage:
- Confirm "postInit: [] != [p0]" is shown in briefing.
- Wait for "postInit: [p0] == [p0] after X seconds" after mission start.
- If seconds is < 1, restart mission and try again.
Screenshot of result on a modded dedicated server.
Screenshot of result on a locally hosted non-modded dedicated server.
Event Timeline
Thanks for updating the wiki to reflect these findings, however I reported it to the issue tracker in hope that it could be fixed.
I was not able to replicate this issue with getUserInfo, it consistently returns the player object in a spawn on postInit.
could you provide 2 scripts side by side one using allplayers and one using getuserinfo doing the same thing but allplayers failing?
I apologize for the late reply, I must have overlooked the notification.
Sure, though I'm not quite sure what you have in mind.
So, below is the postInit code that was used for the getUserInfo test, following it is an equivalent for allPlayers, if that's what you want?
allUsers/getUserInfo
if (!isServer) exitWith {}; private _allPlayers = allUsers apply { getUserInfo _x select 10 }; private _listPlayers = call BIS_fnc_listPlayers; if (_allPlayers isNotEqualTo _listPlayers) then { format ["postInit: %1 != %2", _allPlayers, _listPlayers] remoteExec ["systemChat", -2]; time spawn { private _allPlayers = allUsers apply { getUserInfo _x select 10 }; private _listPlayers = call BIS_fnc_listPlayers; while { _allPlayers isNotEqualTo _listPlayers } do { sleep 0.01; _allPlayers = allUsers apply { getUserInfo _x select 10 }; _listPlayers = call BIS_fnc_listPlayers; }; format ["postInit: %1 == %2 after %3 seconds", _allPlayers, _listPlayers, time - _this] remoteExec ["systemChat", -2]; }; } else { format ["postInit: %1 == %2", _allPlayers, _listPlayers] remoteExec ["systemChat", -2]; };
allPlayers
if (!isServer) exitWith {}; private _allPlayers = allPlayers - entities "HeadlessClient_F"; private _listPlayers = call BIS_fnc_listPlayers; if (_allPlayers isNotEqualTo _listPlayers) then { format ["postInit: %1 != %2", _allPlayers, _listPlayers] remoteExec ["systemChat", -2]; time spawn { private _allPlayers = allPlayers - entities "HeadlessClient_F"; private _listPlayers = call BIS_fnc_listPlayers; while { _allPlayers isNotEqualTo _listPlayers } do { sleep 0.01; _allPlayers = allPlayers - entities "HeadlessClient_F"; _listPlayers = call BIS_fnc_listPlayers; }; format ["postInit: %1 == %2 after %3 seconds", _allPlayers, _listPlayers, time - _this] remoteExec ["systemChat", -2]; }; } else { format ["postInit: %1 == %2", _allPlayers, _listPlayers] remoteExec ["systemChat", -2]; };