Jump to content
Sign in to follow this  
Drongo69

Scripts executed on the server

Recommended Posts

I've read up about executing scripts in MP, but I have not been able to find an answer to this particular question. In a coop mission I'm working on, I use a server_loop.sqs script to check for client actions. This script only runs on the server due to this code (called from init.sqs)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? local(server) : [] exec "server\prep.sqs"

[] exec "client\client_loop.sqs"

exit

The "server\prep.sqs" file calls "server\server_loop.sqs".

The loop looks like so:

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

#lp

? (do_mission) : [] exec "server\mission_control.sqs"

~0.2

? (do_moveout) : [] exec "server\moveout.sqs"

~0.2

? (do_rtb) : [] exec "server\rtb.sqs"

~0.2

? (do_medevac) : [] exec "support\medevac.sqs"

~0.2

? (do_cas) : [] exec "support\cas.sqs"

~0.2

? (do_trans) : [] exec "support\trans.sqs"

~0.2

? (do_airstrike) : [] exec "support\airstrike.sqs"

~0.2

goto "lp"

exit

My questions:

1. Will those scripts execute ONLY on the server?

2. Or will they try to run on every client?

3. Do I need to put "?!(server) : exit" at the start of each of those called scripts?

In other words, if a script run on a server calls another script, will the second script run on every machine?

Attempting to script MP stuff without a LAN to test on is a very special form of frustration.

* Head explodes *

Share this post


Link to post
Share on other sites

since you wrote this<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? local(server) : [] exec "server\prep.sqs"everything called in prep.sqs or "later" will only run on the machine where "server" is local, and that is, if "server" is a logic set in the editor, the server.

Share this post


Link to post
Share on other sites
Quote[/b] ]1. Will those scripts execute ONLY on the server?

Yes

Share this post


Link to post
Share on other sites
My questions:

1. Will those scripts execute ONLY on the server?

What CrashDome said, ie yes.

Quote[/b] ]2. Or will they try to run on every client?
No
Quote[/b] ]3. Do I need to put "?!(server) : exit" at the start of each of those called scripts?
In the case exemplified by you above, no
Quote[/b] ]In other words, if a script run on a server calls another script, will the second script run on every machine?
Again, no, for the case at hand. Take care to note and understand the generalisation: if a script runs on only one machine and calls another script, the second script will also only run on that machine, be it a server or client.
Quote[/b] ]Attempting to script MP stuff without a LAN to test on is a very special form of frustration.
No doubt... getting to grips with OFP:s MP idioms without a proper test setup is an exercise in futility.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? local(server) : [] exec "server\prep.sqs"

[] exec "client\client_loop.sqs"

exit

Just in case this has been missed here:

your client_loop.sqs will also be executed on the server,

as calling another script by exec statement will not end

the current script and so it will also execute the next line.

If client_loop.sqs is expected by you to run server side also -

forget what i said wink_o.gif

~S~ CD

Share this post


Link to post
Share on other sites

Client_loop.sqs is required on every PC with a player. It doesn't do much, just...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[] exec "client\intel.sqs"

~1

#lp

? (update_client) : [] exec "client\info.sqs"

~1

goto "lp"

exit

Intel.sqs just setmarkerposes some markers and info.sqs displays are range of titletexts based upon certain global variables. Having that script run on a dedicated server won't cause any trouble, will it?

Share this post


Link to post
Share on other sites

I never got around finishing this, but it should explain how to ensure that scripts work only on the server as well as offering some more mp scripting advice.

Share this post


Link to post
Share on other sites
Client_loop.sqs is required on every PC with a player. It doesn't do much, just...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[] exec "client\intel.sqs"

~1

#lp

? (update_client) : [] exec "client\info.sqs"

~1

goto "lp"

exit

Intel.sqs just setmarkerposes some markers and info.sqs displays are range of titletexts based upon certain global variables. Having that script run on a dedicated server won't cause any trouble, will it?

For sure it will not cause any trouble, when running on a dedicated server - but it's running for nothing.

Nothing will be displayed on the dedicated server, but

resources will be used - even if it's about harmless cpu usage,

ppl tend to keep their techniques, and in case of following

more complex scripts, you probably might catch yourself one day by using same thing because you always did so and it has

never been a problem before tounge_o.gif

Also, if this script is running local on player side, you should

set boolean update_client to false right after it's true state

became accepted on client-side, because your wait interval

lasts only for 1 second, which could lead to multiple execution

of info.sqs in case of more than 1 second network delay when setting it false on server side in combi with publicvariable.

generally nothing wrong here, but as i already said: to much

smoke for nothin' blues.gif

~S~ CD

Share this post


Link to post
Share on other sites

Thanks for the additional advice. The first line of client\info.sqs is:

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

so that should be okay, right? Generally speaking, what kind of waits do people use when using publicvariable? ~1? ~3?

By the way, I would REALLY appreciate it if any seasoned MP scripting vets could take a look at the mission I'm developing and give me some help.

Coin coop tech test

It's a dynamic coop campaign. It's also my first MP mission. There is no emoticon for "down on my knees begging for scripting advice", so I'm just gonna say...

please ? smile_o.gif

Share this post


Link to post
Share on other sites

if he uses the line:

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

? (player == player) : [] exec "client\info.sqs"

A dedicated server will not execute the client code, but a non-dedicated server will. As Chris said, it's a minor issue in this situation, though.

Food for thought:

to execute server-side only use the logic check as you have done - ? (local server) : do stuff

to distinguish between dedicated server and non-dedicated server use - ? (player == player) : do stuff

A player is null on a dedicated server and therefore never equal to itself

Share this post


Link to post
Share on other sites
Quote[/b] ]so that should be okay, right? Generally speaking, what kind of waits do people use when using publicvariable? ~1? ~3?

I tend to use CoC's Network Services instead of publicvariable. It's bulky in small missions but a life saver in large ones.. especially a campaign. I suggest reading a bit about it.

Share this post


Link to post
Share on other sites

Daddl

Your script tutorial is one of the best docs Ive seen. Now if only someone could write a comprehensive config.cpp tutorial. My biggest problem there is identifying reserved variables and what is user defined and if it is reserved what are the accepted results.

Share this post


Link to post
Share on other sites

I second that, Daddl's guide is a very useful document. Clear and straightforward with a lot of important info in one place. It's going to be a permanent fixture in my editing folder. Thanks smile_o.gif

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  

×