Jump to content
Sign in to follow this  
Cookieeater

How to message the server that a host did an action successfully?

Recommended Posts

I have a script that a player can run that changes a public boolean. Let's refer to this as "scriptisrun". If scriptisrun is true, then I want to execute some code. The problem is that inside multiplayer, the code only runs on the client and not the server. How can I get a client running the script to message the server to change a public boolean?

For clarification:

I have used publicVariable, maybe I'm doing something wrong...

init.sqf:

publicVariable "scriptisactive";
scriptisactive = false;

waitUntil { scriptisactive};
PlaySound "blah"
titleText ["blah"}
etc...


playeraction.sqf:


scriptisactive = true;

When the player activates playeraction.sqf, the code underneath "waitUntil {scriptisactive};" only runs for him, and not for the rest of the players in the game.

Edited by Cookieeater

Share this post


Link to post
Share on other sites

Hey, I might not fully understand what problem you are having, still I am going to blindly suggest you try using publicVariable and maybe addPublicVariableEventHandler. :p

Share this post


Link to post
Share on other sites

I have used publicVariable, maybe I'm doing something wrong...

init.sqf:

publicVariable "scriptisactive";
scriptisactive = false;

waitUntil { scriptisactive};
PlaySound "blah"
titleText ["blah"}
etc...


playeraction.sqf:


scriptisactive = true;

When the player activates playeraction.sqf, the code underneath "waitUntil {scriptisactive};" only runs for him, and not for the rest of the players in the game.

Share this post


Link to post
Share on other sites

You are almost there, you just have the order of things wrong. I commented each block to give a breakdown of what is happening.

Try this:

// init.sqf

// Initialize the variable at startup on server and all clients.
scriptIsActive = false; 

// Pause the script only on the server until the variable is true.
if (isServer) then
{    
    waitUntil {scriptIsActive};
    PlaySound "blah";    
    titleText ["blah"};    
    etc...
};

//playerAction.sqf

// Change the value of variable on the client only.
scriptIsActive = true;

// Broadcast the new value to server and other clients so script can continue on server.
publicVariable "scriptIsActive";

Note that is added an isServe check to make sure you only pause the init.sqf on the server (which won't show title texts unless a MP host).

Please note there is also a new command in A3 called publicVariableServer that will only broadcast to the server, so in this case I would actually recommend using it instead of publicVariable to reduce network traffic. As stated above, you could also use a public variable event handler on the server to wait for the value of the variable to change instead of the waitUntil. The above code is NOT JIP compatible (it can be but I kept it simple).

I hope this helps.

Share this post


Link to post
Share on other sites

Thanks a lot, Loyalguard. This script works but turns out my mission is completely broken when running on a dedicated server. Thanks for the help though, I'll remember it when I get to this part again.

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  

×