Jump to content
Sign in to follow this  
Rommel

Locality

Recommended Posts

I have an action, the player pushes it, it launches a script. (player addaction ["action","script.sqf"]wink_o.gif

Simple enough so far.

Now I want to get the server to execute something from that script.

script.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[server] execVM "script2.sqf"

And to make a variable/code global from that script I would just:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">publicVariable "It";

huh.gif

$10 says that the server doesn't execute it because its local to the client or...???

I bet the experts get sick of these questions, but I guess it just can't be said enough.

Share this post


Link to post
Share on other sites

You are correct in that scripts executed by an addAction are local to the client it was run on.  To achieve what you are looking for me I would recommend something like this (requires 1.09 or higher although there is a way to do it with 1.08).

In your init.sqf or somewhere else at mission start put the following code:

init.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then

{

    "clientAction" addPublicVariableEventHandler {/*Insert code you want executed when client runs addAction*/};

};

This sets up a public variable event handler on the server only that waits for the for pertinent public variable to be changed and then executes whatever code you want every time it does.

Then in your script.sqf add the following code:

script.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">clientAction = true; publicVariable "clientAction";

This broadcasts the public variable that the server event handler is waiting for so that the server can run the code you want. I made the variable boolean but you can you any type of variable.

There is more to the addPublicVariableEventHandler command that is available so check it in the Biki.  I hope this help!

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  

×