#Need a hand with determining if player is in a slot.

1 messages · Page 1 of 1 (latest)

oak eagle
#

I need to determine if a player is in a Zeus specified slot. The slot itself has a variable name set as "z1".

_zeusSlot = [z1,z2,z3];
if (player in _zeusSlot) then {
    [2, format ["%1 is in a Zeus slot.", name player]] execvm "scripts\performance\log.sqf";
    player call compile preprocessFileLineNumbers "scripts\zeus\zeus_events.sqf";
    player setVariable ["isZeus", true];
};

THE PROBLEM

This seems to work, however it throws an error in the log when a player joins a slot that is NOT the zeus one.

_zeusSlot = [z1,z2,z3];
if (player in _zeusSlot) then {
>
13:05:21   Error position: <z2,z3];
if (player in _zeusSlot) then {
>
13:05:21   Error Undefined variable in expression: z2
#

If I join Zeus 2, it throws an error about Z1 for instance

#

Unless another player is already in that slot

harsh frost
#

You aren't setting the variable name of the slot (slots aren't a real thing), you're setting the variable name of the unit. If a playable unit has no AI enabled, and no player at mission start, it's never created so its variable is not defined.

oak eagle
#

OK so how would I ignore it then

harsh frost
#

There's a couple of ways to get around it. One would be to use getVariable, which can provide a default value if the variable isn't defined. Or you could use isNil to check if it's not defined. Both mean a bit of restructuring.

oak eagle
#

I've had a look at "isnil {player in _slot}" but I dont understand how I'd then use that, as it just returns false? if the players in a defined unit

harsh frost
#

Well, you wouldn't do it like that

#

You would use something like isNil "z2" to check if the thing exists before running further checks

oak eagle
#

But then, I'd have to switch for each one?

harsh frost
#

For Zeus units there's another trick. A Zeus is a two-part entity, with the unit and its associated module. The module still exists even if the player doesn't, so you can reference it safely.
So you can do a local check when the player loads in (initPlayerLocal.sqf for example) to see if their assigned curator module is the right one.

harsh frost
oak eagle
#

That isn't what I need it for, i need to check if a players in the assigned zues slot

#

think whitelisting

harsh frost
#

You can't do things on the slotting screen before the mission briefing phase

#

The mission isn't loaded, scripts aren't running

oak eagle
#

Object init occurs before initPlayerLocal tho, the variable should then be assigned to the Object before this even occurs?

harsh frost
#

Yes....and?

#

You can't do anything at the slotting screen, the game doesn't run mission scripts at that stage.
So you have to do whatever check it is, after the player has committed to a slot.
Then you can do something like this, on the player's client:

private _logic = getAssignedCuratorLogic player;
if (_logic in [list, of, logics]) then {
// Your code here
};```
#

Could probably do it server side too with the right event handler. Same basic principle though. The logics always exist even if the playable unit associated with them doesn't, so you can safely refer to them without fear that they'll be undefined

oak eagle
#

Ok but the problem with that, is the getAssignedCuratorLogic doesn't activate until, 10 seconds~ after the player loads

#

I guess I can shift it all to a waituntil script

#

but that leaves the script "hung" until the player becomes a zeus

harsh frost
#

Well, the alternative is to use one of the getVariable or isNil methods to safely check the unit variables

oak eagle
#

does that not run into the same problem tho.

harsh frost
#
_realUnits = ["z1","z2","z3"] apply {missionNamespace getVariable [_x,objNull]};
if (player in _realUnits) then { ...```
oak eagle
#

Unit INIT = this setVariable ["isZeus", true];

if (player getVariable ["InA_isZeus", true]) then {
    [2, format ["%1 is in a Zeus slot.", name player]] execvm "scripts\performance\log.sqf";
    player call compile preprocessFileLineNumbers "scripts\zeus\zeus_events.sqf";
};
harsh frost
#

That would work too

oak eagle
#

OK going to try this out

harsh frost
#

Use functions though :U

oak eagle
#

i'll setup functions later, this is just to make sure it all works

harsh frost
#

Oh, make sure the name of the var you set and the var you check match, because in that example they... don't

oak eagle
#

yeah I know

#

was an example

#

It works