Home   Help Search Login Register  

Author Topic: Tutorial: (Local/Global/Player/server) MP scripting  (Read 8044 times)

0 Members and 1 Guest are viewing this topic.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Tutorial: (Local/Global/Player/server) MP scripting
« on: 26 Feb 2007, 23:18:16 »
Hoping this makes anyone new to BIS scripting more aware of the relationships between
Local, Global, Player and Server



First thing
Game logics are "Only" local on the server, be it a player/server or a dedicated server
as an unwritten standard, most mission makers create a gamelogic and name it "Server"

when you are running the code
?(local server):
what you are actually stating is
Is the game logic named "server" local on this machine, if so, run the code that follows on from ":"

Typical switches are
for .sqs
    ?(local server):hint "I am the server machine"
    ?!(local server):hint "I am not the server machine"
    ? (local player):hint "I am a player machine"
    ?! (local player):hint "I am a dedicated server machine"

for .sqf
    if (local server) then {hint "I am the server machine"};
    if (! local server) then {hint "I am not the server machine"};
    if (local player) then {hint "I am a player machine"};
    if (! local player) then {hint "I am a dedicated server machine"};


Where and when to use these, is dependant on what code you are running and where you want the code to run

More often than not you will see the following at the very start of a script
?(Local server): exit
if(local server)then{exit};
?(local player): exit
if(local player)then{exit};
These lines are used to stop the script from being run on certain machines

or, you can also initiate a script on either clients or server by using something like the following

?(Local server): [] exec "myscript.sqs
?(local player): [] exec "myscript.sqs
or more correctly with arma, functions
?(Local server): [] execVM "myscript.sqf;
?(local player): [] execVM "myscript.sqf;



Certain commands are local or global

Global commands are commands that when run on 1 machine, every other machine is sent / receives that data

Local commands are commands that do not send data to other machines.

setpos, is actually a global command, which means only 1 machine needs to run this code, as all the other machines will receive the data of the objects new position and reposition it
If you run this code on all machines, then every machine will tell every ,machine where to setpos the object, and the last machine that runs the code, will be the one that overwrites the rest

"setdir" is local, meaning if you setdir an object on 1 machine, the others wont see it placed in the new direction, until some other code updates it

It takes time, but eventually you will discover which commands are local and which arent and the workarounds to create a global from a local

Eg, to make setdir into a global command, first setdir the object then setpos it, the setpos sends the direction of the object, thus setdir has been sent globally.

A new command that comes in both Global and local flavours is the setmarkerpos, with it's local varient SetmarkerposLocal

I hope that gives you a better understanding of the relationship between player/server/global/local


NB>> Up too and including the present version (1.05) "setpos" will not work with static objects, eg ammo crates etc, this i believe is a big and will be rectified in some future patch
« Last Edit: 17 Mar 2007, 16:09:18 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #1 on: 26 Feb 2007, 23:41:41 »
Quite interesting  :good:

Do you know if setVelocity and the new setVectorDir and setVectorUp are locals or globals? Do any of them, if global, update object's direction in every client without needing to setpos it?

Offline sharkattack

  • Former Staff
  • ****
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #2 on: 26 Feb 2007, 23:47:54 »
man .. thanx for sharing this information ..    :good:
"HOLY SARDINE" - see Shark-Attack meet his match

Offline Shiner

  • Members
  • *
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #3 on: 27 Feb 2007, 04:41:19 »
Thank you very much.  I was confused by exactly how the gamelogic elements work and this explained it at a level I can understand!!

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #4 on: 27 Feb 2007, 10:16:41 »

Quite interesting  :good:

Do you know if setVelocity and the new setVectorDir and setVectorUp are locals or globals? Do any of them, if global, update object's direction in every client without needing to setpos it?
Dont know m8, i havent got access to a dedi at present, yes i know i can run one on my pc, but for local/global testing you ideally need 1 dedi and 2 players

what we really need now, is a complete and tested list of commands denoting whether they are local or global

and then we can develop that list further with "work arounds"
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline sharkattack

  • Former Staff
  • ****
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #5 on: 27 Feb 2007, 18:49:52 »
great idea ..
"HOLY SARDINE" - see Shark-Attack meet his match

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #6 on: 04 Mar 2007, 03:36:06 »
One of them tutorials that made me say "No.. really?" and "ahhhh cool" etc

And I would assume any command modifying the objects position, direction etc is submitted to the server?

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #7 on: 04 Mar 2007, 17:02:09 »
One of them tutorials that made me say "No.. really?" and "ahhhh cool" etc

And I would assume any command modifying the objects position, direction etc is submitted to the server?

setpos will, setdir won't

when it comes to global/local there are two basic questions you need to answer before you can correctly implement the code
These are:

1) Does command have to be run locally?
 eg, Does the target object for the command have to be seen as "local" on the same machine as the command that is being called

2) Is the effect local or global
eg, when the command is run, does the effect only occur on the machine the code is run on, or is it seen globally, as in on every machine


so if we were to create a reference list for the local/global requirements for all commands, we would need 5 columns populated with info
these being:

Column 1: (Command itself )
Column 2: (Requires to be locally run on (Yes/No)
Column 3: (Effect is local only (Yes/No)
Column 4: (Work around to make it global)
Column 5: (Comments)
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline F2kSel

  • Members
  • *
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #8 on: 19 Mar 2007, 17:10:50 »
I'm trying to get my poor head around this. It's a long time since I did scripting and had quite a few problems with things being seen on one pc and not on the other.

What I don't get is why you wouldn't want everything to be global, If I see and explosion, man, car ect wouldn't you want them to show on all PC.
Apart from text and sound I carn't see why  would want anything else to be local.

 

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #9 on: 22 Mar 2007, 17:47:36 »
I'm trying to get my poor head around this. It's a long time since I did scripting and had quite a few problems with things being seen on one pc and not on the other.

What I don't get is why you wouldn't want everything to be global, If I see and explosion, man, car ect wouldn't you want them to show on all PC.
Apart from text and sound I carn't see why  would want anything else to be local.

 

Example 

1layer has a sniper rifle
1 player has an M249

You create an automatic rearming script for the respawning player
lets say we call the weapons that the player has Tx_MyWeps
eg
Tx_MyWeps = weapons player

and then in a script you would use
@ alive player ;; (bad example, old OFP command)
removeallweapons player
{Player addweapon _x} foreach TX_myWeps

TX_MyWeps would have a different value for every player, unless you Publicvariabled it, then every player would get the same weapon, eg not the one they started with

there are many reasons why you wouldnt want the same value for a variable on every computer

and the reason why you need to know where the command needs to be called from and what effect it has, is so that you can run the code where it is needed
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline ViperMaul

  • Members
  • *
    • Theatre Of War (Team PvP Campaign)
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #10 on: 04 Apr 2007, 10:09:44 »

Quite interesting  :good:

Do you know if setVelocity and the new setVectorDir and setVectorUp are locals or globals? Do any of them, if global, update object's direction in every client without needing to setpos it?
Dont know m8, i havent got access to a dedi at present, yes i know i can run one on my pc, but for local/global testing you ideally need 1 dedi and 2 players

what we really need now, is a complete and tested list of commands denoting whether they are local or global

and then we can develop that list further with "work arounds"

This topic really needs lots of concreate examples. But this is just the thread I was looking for. Thanks Alot.
I need to know if

1) Anyone has verified if the new setVectorDir and setVectorUp are locals or globals?
2) What is a confirmed test using a Dedicated server and two human players to find out if these or any other commands are locals or globals?

Thanks,

ViperMaul
ViperMaul
Theatre of War (Co-Lead Dev)
ACE (Jr Project Manager)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #11 on: 04 Apr 2007, 23:51:35 »
Terox, should know better not to quote the entirety of the previous post you're answering to..  :no:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #12 on: 06 Apr 2007, 00:49:09 »
2) What is a confirmed test using a Dedicated server and two human players to find out if these or any other commands are locals or globals?

Basically you have 2 humans connected to a server

Test 1:
Player 1 runs a command on something he knows is local to his machine, eg an ai in his group
If player 1 and player 2 see the same "expected" effect, then the EFFECT is global, if not its local

Test 2:
reverse the situation, Player 2 runs code on player 1's local ai unit

If the effect was the same as test 1, then the command can be called upon whether the object is local or global, if not the command has to be run where the object is local

This is a better test than 1 player on a dedi
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #13 on: 06 Apr 2007, 02:22:13 »
setVelocity is local/global.  You can use it on a non-local unit, but the effect will only be on the client executing the command; as soon as the server synchs the unit will snap back in place. If you use it on a local unit, the effect will be observed global, since the local position is what will be synched. The 'old' setDir command also behaved this way(I think), which is what allowed client-side only  ECP to simulate tail rotor failure based on local settings.  I suspect the new commands will also behave this way.
urp!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #14 on: 06 Apr 2007, 09:26:02 »
What do you mean with "local unit"? because units created with createVehicleLocal are not transferred to the rest of the clients. Or do you mean a "global" unit but affecting its dir, etc only from the machine that created it?

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #15 on: 06 Apr 2007, 20:17:27 »
i was referring to a unit/object that was local on a specific players machine, eg an ai unit in the players group, is local on that players machine and is therefore a useful object for certain tests
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline WhisperOFP

  • Members
  • *
  • I'm a llama!
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #16 on: 12 Apr 2007, 16:33:25 »
It may also be good to have informations on trigger's locality, and how they behave depending on local and global conditions.
As far as I've seen, it looks like triggers put on the editor do exist on every PC connected to the game (which is quite normal as all PC have the mission.sqm describing these triggers), and each PC check the conditions independantly. Can anyone confirm? It's a wild guess I did, but I'm not too sure.

As for triggers created with createTriggers, it looks like they only exist on the PC where they were created, and the condition is only checked there.

Btw, Terox your information about setVelocity is quite worrying to me, for another reason, which is about locality transfer.
I tried to use selectPlayer on a MP map, making the player switch to a former AI unit, and it worked. But, once I moved my new character, it was quickly put back in place. Your synchro explanation could very be the cause, which means that there is no locality transfert in this case. Sad, as it is definitely possible, as group respawn does exactly that. It's unfortunately not accessible through scripting :(
Sill now way you can fully take control of a AI unit in ArmA :(

Offline ViperMaul

  • Members
  • *
    • Theatre Of War (Team PvP Campaign)
Re: Tutorial: (Local/Global/Player/server) MP scripting
« Reply #17 on: 12 Apr 2007, 17:59:16 »
I get to teach a couple of friends about this topic.
The unfortunate part is I do not have a complete understanding of it all. LOL

I am getting a better understanding now about local and global commands.
Now a question about scripts, loops, conditions, etc.

In terms of keeping the impact and stress on the server FPS and performance, how do you determine which kinds of scripts should be run on the client and NOT the server; or which scripts should run only on the server; or which scripts should be allowed to remove the check at all and be ran on any machine?

It might help if we use a concrete example here.
An example for each situation would be best.


EXAMPLE:

Let's take Chaff/Flare Defense system script.

  • In this implementation we had a ExecVM an .SQF file for each Helicopter.
  • The .SQF file has a While Loop that runs until there is critical damage then stops
  • The While Do Loop checks for a missile by contantly checking for a Vehicle's variable (e.g. _helo getVariable "missileincomming";
  • This "missileincomming" variable is set through the EventHandler "IncomingMissile"

So as you can see, this While Do Loop continues to run basically until the Helo is destroyed.
Right now there is no Server or Client check at all.

My questions are this?
Does this mean the While Do loop is being run on the server CPU only by default thus causing server strain if there 60+ Helos flying around?
If it runs on the Server CPU only, can I reduce the server strain and force it to run on the Client Only without breaking functionality?
Is it possible that if one player jumps in the helo and then lands; gets out; and another player Jumps in, does the While Do loop and script switch from being run on that client to the new client?

As you can see I need some guidance here from the GURU of wisdom.

Thanks for your help in advance!


ViperMaul
Theatre of War (Co-Lead Dev)
ACE (Jr Project Manager)