strider42 64 Posted February 5, 2016 What is the best way to detect if a player is initialised (as part of the init.sqf script, in a multiplayer mission)? I had been using the following to detect if a player has been initialised in a multiplayer mission: if ( hasInterface ) then { waitUntil { alive player }; _player = player; ...However recently I have seen occasions where this did not appear to work as the _player variable had not been set correctly.I solved the problem with the following code: if ( hasInterface ) then { waitUntil { alive player }; waitUntil { ! isNull player }; _player = player; ...I'm guessing a better option would be: if ( hasInterface ) then { waitUntil { alive player && ! isNull player }; _player = player; ...Which is what I am currently using but should I be using something else? BD Share this post Link to post Share on other sites
Guest Posted February 5, 2016 I think the isNull check is ok, alone I mean. Test it out. Share this post Link to post Share on other sites
strider42 64 Posted February 5, 2016 Thanks for the reply harmdhast. The problem I had been seeing seemed to be intermittent.Just using the waitUntil { alive player }; has worked well until I tried to do the following: _player createDiaryRecord ["Diary", ["Titile", "Message"]]; And then I went trough one of those loops that made me belive I needed to test waitUntil { alive player && ! isNull player }; to get it to work, only to find that when I reverted to just waitUntil { alive player }; That was now working.I left it at that and then one of my tests showed that the diary record was not being created so I am back on waitUntil { alive player && ! isNull player };. Since when I have had no problems.Interestingly I asked a friend about this issue and he believed that ! isNull player is not sufficient to to check for the player being initialised hence I decided to make a post to see what other people did. BD Share this post Link to post Share on other sites
Nikander 123 Posted February 5, 2016 What is the best way to detect if a player is initialised (as part of the init.sqf script, in a multiplayer mission)? Hello strider, according to this table in the wiki, one could easily get the impression that when init.sqf is running the player has indeed already been initialized in a multiplayer mission, so you should have no need to explicitly test that in init.sqf. Remember, that when you preview your mission in the editor, you're running in singleplayer mode. Nikander Share this post Link to post Share on other sites
MKD3 27 Posted February 8, 2016 If multiplayer testing, always use the MP editor. So hopefully the singleplayer mode comment above doesnt apply. one could easily get the impression that when init.sqf is running the player has indeed already been initialized Wouldnt hold my breath on that one. Share this post Link to post Share on other sites
jshock 513 Posted February 8, 2016 If multiplayer testing, always use the MP editor. So hopefully the singleplayer mode comment above doesnt apply. It's still running locally on your machine, which in light of locality, could still cause some issues in a dedicated environment. Let's just say I've never needed to use the MP editor to make a mission MP compatible. @Niklander, it is better assumed that the player is initialised in the initPlayerLocal and initPlayerServer. Share this post Link to post Share on other sites
fn_Quiksilver 1636 Posted February 8, 2016 personally I use waitUntil {(!isNull (findDisplay 46))}; but if you want to wait for one of the event scripts (init.sqf or initplayerlocal.sqf) to be terminated before continuing ... // init.sqf 0 = 0 spawn { private ['_exit','_activeScripts','_file']; _exit = FALSE; while {TRUE} do { _activeScripts = diag_activeSQFScripts; _exit = TRUE; { _file = _x select 1; if (['init.sqf',_file,FALSE] call BIS_fnc_inString) then { _exit = FALSE; }; } count _activeScripts; if (_exit) exitWith {/* player init finished */}; }; }; don't think i'll ever need or use such a method, but it should be foolproof. Share this post Link to post Share on other sites
MKD3 27 Posted February 10, 2016 I always use MP editor because of the way my group sets up a template, using it in single player can cause issues with code using if (isServer) then {code}; Share this post Link to post Share on other sites