Jump to content
Sign in to follow this  
Ub3rObama

Script not executing properly client/server

Recommended Posts

I'm using this to call script.sqf, in a number of unit (player) slots.

Null = ["12345678"] execVM "script.sqf";

script.sqf

WaitUntil{not isNull player};  
waitUntil{(getPlayerUID player) != ""}; 

_uid = getPlayerUID player;

if(_uid != (_this select 0)) then {
endMission "LOSER";
};

This is designed to check if a player is in his correct slot. Now I'm really stumped by this, because whats happening is when 2 people join the game in their correct slots, it kicks them straight away. I'm sure its the exec, and that it must be executing on the server, but I've tried changing it around and haven't gotten any good results. I think I'm having a dumb moment because it seems obvious but I just can't work it out. Should be bloody simple.

The script works fine, if its only 1 person joining.

Edited by Ub3rObama

Share this post


Link to post
Share on other sites

Not everybody has a UID of 12345678. Atleast not to my knowledge. I'm no expert in that stuff though.

Share this post


Link to post
Share on other sites

Its supposed to kick anyone who is in that slot (unit) who doesn't have that specific UID, its designed to make that slot/unit so only 1 person can join it.

Share this post


Link to post
Share on other sites

I don't know anything about how UIDs are assigned so I can't help you directly. Did you adjust the UIDs to the specific player IDs?

Share this post


Link to post
Share on other sites

Whats happening is when the first person goes through a check the _uid gets stuck. So when another person comes along and goes through the check, it uses the previous _uid, which breaks everything. I don't understand how thats happening, I thought execVM opened a new thread every time it was called, meaning fresh variables but it looks like it keeps the same thread open, re uses it and doesn't update the variables, or is skipping code, its really odd.

What needs to happen is the script only on the client machine, but I have no idea how to get that to happen.

Edited by Ub3rObama

Share this post


Link to post
Share on other sites

could try looking at - onPlayerConnected "[_id, _name] execVM ""script.sqf""";

be careful using player in mpscripts -

Share this post


Link to post
Share on other sites

The problem is init lines run for all players, not just the one that joins the specific slot. Say Player_A and Player_B joins Unit_A and Unit_B. Your logic is sound in that Arma for Player_A runs the init line for Unit_A. The uid obviously matches if he chooses the right unit in the lobby. Same for unit Unit_B. This is why it works with one person.

Here's the problem. When Player_B joins Unit_B the script also runs on computer where Player_A is. So what happens is:

On PlayerB's computer:

Null = ["PlayerB_UID"] execVM "script.sqf"; => works since on PlayerB's computer, the 'player' object has this uid.

On PlayerA's computer:

Null = ["PlayerB_UID"] execVM "script.sqf"; => does not work. Since on PlayerA's computer the 'player' object does not have this uid.

Likewise when Player_A joins Unit_A the script also runs on the computer where Player_B is. This is why both players are kicked.

Without thinking much I think the following should fix it:

Null = ["12345678", this] execVM "script.sqf";

And then the script:

WaitUntil {not isNull player};  
waitUntil {(getPlayerUID player) != ""}; 

_uid = getPlayerUID player;

//Is this player controlling this unit? If not then quit.
if (player != (_this select 1)) exitWith {};

if(_uid != (_this select 0)) then {
   endMission "LOSER";
}; 

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  

×