Jump to content
Sign in to follow this  
Mongoose_84

Variables in MP

Recommended Posts

Didn't find the answers in the biki... When I declare variables in the init.sqs or in the editor (or whereever) and do all kinds of stuff with them - use them in triggers and scripts - all of this will stay on the client, right? One copy per client that is. It's pretty much as if I was doing it for Single Player, only it will work for every player in the game and the scripts and variables will not interfere with each other from one client to another.

Did I get that right or is my picture of how MP-scripting works wrong? I better know that, before I get started...

Share this post


Link to post
Share on other sites

You are roughly correct.

If you declare X = 0 in the init.sqs, than allclients will have X = 0 simply because of the fact that the init.sqs is run on each machine (engine fact).

However, if you gave all players an action that said when clicked than X = 1, then only players who clicked that action would have X = 1.

On the other hand, most triggers are globally checked. For example, a trigger that "West is present" would make X = 2, then as soon as any west player entered all clients would get X = 2 because even if a different player enters the trigger, all clients see that "West is truly present" in that trigger and thus all execute the activation line (but each trigger on each client runs it seperately.. as you said in your first post)

[EDIT] As a Beginner, it is safe to say to yourself that the only reasonable guarantee that a value is the same on all clients is if it is an object (like a unit) and even then, the only thing that is the same are the various properties (like skill, alive, side, position, etc..) It is certainly possible to make X = player, but since player is something different on each machine, than X is a different object on each machine.

However, if you define group1 as the 12 AI units on the enemy's side in the init.sqs (therefore group1 is same on all clients) than calling <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">leader group1 you can be assured will most certainly be the same value on each client

Just remember there really are no *true* guarantees.

Share this post


Link to post
Share on other sites

thanks once more!

i guess sooner or later i'll also have to learn about the server's special role in this. but for now i think i can get started.

Share this post


Link to post
Share on other sites

actually, i'd like to learn something about it, right now:

how can i be certain, that a script is run only once (on the server, i guess)? for example, i want to add a group of units to the map by script and of course, i don't want it to be one group per player. i would just try and find that out myself, but the annoying thing about MP-scripting is, that you can't really test your scripts unless you have an entire LAN at home...

edit: just took a quick look at this tutorial of snYpir and i'm probably gonna find most of what i need to know about MP-scripting in it... sorry for the unnecessary post - the forum is way too crowded already rofl.gif

Share this post


Link to post
Share on other sites

some of the tutorial's text i find rather irritating...

"You only need to dynamically create objects (using CreateUnit or CreateVehicle) on the server."

>what if i want to create units by a client? i know now, i don't need to do that - but will it work?

"Be prepared for a great deal of pain if you start handling events (especially player-activated ones such as map clicks) in multiplayer."

>why?...

"You should only ever measure distances or perform calculations on the server (because the server is always right)"

>again - why? i can imagine that in some cases that may be important, but for example if i use my custom respawn script client-sided only and calculate distances between group members (and more) - why would that be a problem?

would be nice, if someone could clarify this for me

Share this post


Link to post
Share on other sites

confused_o.gif

and another question: if a player joins a game that has already started, is the init.sqs still executed then on that client? or do i have to take care for that manually?

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  

×