Jump to content
fourjays

Local player check incorrectly returning false?

Recommended Posts

Hey,
This is half mission/half mod question, so hope it's in the right place. I've made a placeable module and associated function that loads a loadout onto a given unit. The function is called via the unit's init line in the mission file, like so:
 

[this, "pl_ptl"] call bwi_fnc_getPlayerLoadout;

Basic stuff. This function (eventually) loads the loadout for the given role (pl_ptc) on to the unit. The problem is that before the function gets to any of the more complicated stuff (where the module comes into play) it is sometimes quitting out, resulting in a naked player.
 
Very early on this occurred a lot due to me not properly checking if a player was loaded. This is now done using the following lines:

 

waitUntil{ !isNull _unit };
waitUntil { player == player && time > 1 };

 

However, this still occasionally occurs and I have tracked it back to a simple player locality check:
 

if (!local player) exitWith{ true };

 
At some point during the loading process, this is behaving as if the player is *not* local. However, all the information I can find seems to indicate this shouldn't be happening. This very same check is performed later in the chain, as it is included in the header of each loadout file (leftover from an older version) which seems to be giving the correct result.
 
This is the full set of checks to determine that the player has loaded, and is local (when the nakedness occurs it exits with the "Unit not local" message):

 

// Quit on dedicated server and HCs.
if ( isDedicated || !hasInterface ) exitWith { true };

// Wait for unit to load in.
waitUntil{ !isNull _unit };
waitUntil { player == player && time > 1 };

hint parseText "<t color='#0000ff'>DEBUG</t><br/>Player loaded";

if ( !local _unit ) exitWith {
hint parseText "<t color='#0000ff'>DEBUG</t><br/>EXITING - Unit not local";
true
};

 

Can anyone give any insight into this behaviour? Thanks

Share this post


Link to post
Share on other sites

There is a big difference between

if (!local player) exitWith{ true };

and 

 

if ( !local _unit ) exitWith {

hint parseText "<t color='#0000ff'>DEBUG</t><br/>EXITING - Unit not local";
true
};

One is checking if player is local, another if _unit is local. so which one is it? 
 

Share this post


Link to post
Share on other sites

"local player" is true on every client, you only want the client that gets the loadout to run the script

params ["_unit", "_loadout"];
 
if (!hasInterface) exitWith {};
 
waitUntil {!isNull player};
if (!local _unit) exitWith {};

Share this post


Link to post
Share on other sites

There is a big difference between

if (!local player) exitWith{ true };

and 

 

if ( !local _unit ) exitWith {

hint parseText "<t color='#0000ff'>DEBUG</t><br/>EXITING - Unit not local";

true

};

One is checking if player is local, another if _unit is local. so which one is it?

Second one. First one was me surmising from memory and confusing matters in the process. It is for some reason returning as if the unit isn't local, when as far as I can tell it is only running locally (e.g. the hint it fires only appears on the affected machine). It's like the unit is momentarily not local?

 

"local player" is true on every client, you only want the client that gets the loadout to run the script

params ["_unit", "_loadout"];
 
if (!hasInterface) exitWith {};
 
waitUntil {!isNull player};
if (!local _unit) exitWith {};

Will give this a go and see how it pans out. The main difference I see is doing isNull on the player instead of the _unit. EDIT: Believe that is working. Will see if it survives an op with a load of guys. :P

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

×