OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: Rommel92 on 31 Mar 2008, 10:04:26
-
I have an action, the player pushes it, it launches a script. (player addaction ["action","script.sqf"];)
Simple enough so far.
Now I want to get the server to execute something from that script.
script.sqf
[server] execVM "script2.sqf"
And to make a variable/code global from that script I would just:
publicVariable "It";???
$10 says that the server doesn't execute it because its local to the client or...???[/i]
I bet the experts get sick of these questions, but I guess it just can't be said enough.
-
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
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
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 Comref. (http://www.ofpec.com/COMREF/#848) I hope this helps!
-
And if you dont want to use betas, in your init.sqf:
// init.sqf
clientAction = false;
if (isServer) then
{
[]spawn
{
while {true} do
{
waitUntil {clientAction};
clientAction = false;
[] spawn
{
// Do whatever is needed here
};
};
};
};
Your local client action should
clientAction = true; publicVariable "clientAction"