Home   Help Search Login Register  

Author Topic: Tutorial: (Local/Global/Player/server) MP scripting  (Read 8960 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?