Jump to content
Sign in to follow this  
jw custom

Execute script only server side?

Recommended Posts

I have a trigger in my mission that execute a script which spawn a UAV Terminal at a random location and that works fine, but it seems that all clients execute that script and then theres spawned up to 6 UAV Terminals.

Now how do i ensure that the script only will be executed by host/server side?

Share this post


Link to post
Share on other sites

Very simple answer, you can ask for "isServer" at the very top of your script. It will return true if the executing machine is the server, otherwise it returns false.

Example .sqs

? not isServer : exit

Example .sqf (what I prefer)

if(not isServer) exitWith{};

Share this post


Link to post
Share on other sites
Very simple answer, you can ask for "isServer" at the very top of your script. It will return true if the executing machine is the server, otherwise it returns false.

Example .sqs

? not isServer : exit

Example .sqf (what I prefer)

if(not isServer) exitWith{};

cool thanks :)

P.S. one more question though: so if i use "if(not isServer) exitWith{};" the code within the brackets will get executed if NOT server right?

Share this post


Link to post
Share on other sites

The more proper way is this:

if(isServer)then{
// code to execute if this is the server
};

if(!isServer)then{
// code to execute if this is NOT the server
};

You shouldn't use exitWith{} to exit scripts.

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  

×