Home   Help Search Login Register  

Author Topic: How do scripting commands behave in MP?  (Read 15368 times)

0 Members and 1 Guest are viewing this topic.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
How do scripting commands behave in MP?
« on: 31 Mar 2005, 02:32:26 »
Greetings all,

I've recently started trying my hand at multiplayer editing and scripting. I've read snYpir's excellent MP editing tutorial, which gave me a great start; however, it doesn't go into much detail about scripting in particular, and I haven't been able to find another tutorial that does. One thing that I have found thru tinkering around in MP is that many commands work in very unexpected ways. So my question to all of you MP gurus is the following:

How does each scripting command work in a MP environment?

I want to know about every command possible. I'm not concerend with how the command works in general/SP, since the com ref tells this. I'm more interested in the following questions (plus any others you can think of):

??? Will the effect of the command be seen by all computers (globally), or only by the client it was run on (locally)?

??? What happens when you pass a local object to the command? What about a remote object?

??? How is the AI affected by this command in all of the above situations (if applicable)?

??? Is there anything else that must be done to get the command working properly in MP? Are there any other ways this command behaves differently in MP than in SP?

With that said, I hope to hear from everyone. I'll post new commands as I discover how they work in MP, and if everyone else does the same (and posts what they know already), then as a community we can get this all figured out, and cut down the questions by about 1/2 on this forum :).
« Last Edit: 24 Aug 2006, 10:55:34 by nominesine »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:How do scripting commands behave in MP?
« Reply #1 on: 31 Mar 2005, 02:33:04 »
This post will be modified to contain a list of all commands contributed so far. Please don't post a command that has already been posted, unless you need to correct errors or add to another person's post. In rough alphabetical order:

     Commands posted so far:

action
animate
animationPhase
addAction
camCreate*
createVehicle
cutObj
cutRsc
deleteVehicle
distance
drop*
leader*
move
objStatus
player
publicVariable
random
side*
skipTime
setpos
setvelocity
setdammage
setViewDistance
setFog
setOvercast
setRain
skipTime
titleText
titleCut
titleCut
titleRsc


*command needs more research/clarification


Edit

Check my post on this page here. There I have posted a list created by Spinor of CoC, which lists how most commands work in MP.
« Last Edit: 30 Sep 2005, 23:49:07 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:How do scripting commands behave in MP?
« Reply #2 on: 31 Mar 2005, 02:57:41 »
Leader

In MP this command will always return the original leader of a group, even after he dies (at which time it will return his corpse, which become static objects on the 'civilian' side). Notice that in SP, this command will always return the current leader of a group (so it will always return a living unit when the group has at least one member).

This may not stay true after adding new units to the group via the "join" or "createunit" commands. (need more research)

This command will work on local or remote objects (if a unit is passed). If passed a group, the group must be defined locally.

move

This command will only work if the passed groupname is defined on all computers. This can be a problem if you want to spawn units into groups after the start of the mission, because if you put the following in a unit's init field:
Code: [Select]
groupA = group this; deletevehicle thisThen groupA will NOT be defined on all clients. There MUST be a delay between the group assignment and deleting the unit (figuring this one out caused me great headache).

player

This command will return something different on each computer. It will always return the current body of the player who's computer runs the command. On a dedicated server this command will return null (can be detected by the "isnull" command).

setpos
setvelocity
setdammage

what else?

These commands all work normally in MP, regardless of what computer they are run on, or whether the object affected is local or remote. For example, a client using the "setdammage" command on a unit local to the server WILL injure/heal that unit.

SetFog
SetOvercast
SetRain
Skiptime

The environemental changes from these commands will ONLY take place on the computer where the command is run from. It is entirely possible for one client to see day, while another sees night, for example.

How is the AI affected by this? Does the AI use the environmental settings of the computer it is local to (for vision ranges)?

Camcreate

The effects of this command will only be seen by the computer the command is run from. This means camera cutscenes must be started on each computer individually. Ordinance made with this command that would normally hurt units (such as shells and bullets) will NOT hurt units in MP (for example, a shell will explode but will not cause any damage). Objects and vehicles should NOT be created with this (createvehicle should be used instead).
« Last Edit: 01 Apr 2005, 00:03:59 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:How do scripting commands behave in MP?
« Reply #3 on: 31 Mar 2005, 05:05:31 »
Yay. This thread is long overdue.

Re: Leader. So, if the leader dies, even if a new leader takes his place, the old one (corpse) still remains leader? Also: if normal respawn (like paintball respawn) is activated, and the leader is killed and respawns back into the group (still leader), will the leader command return his new incarnation, or the old corpse?

Re: Init fields. I understand now; an init field is local to whichever computer the unit belongs to.

Re: camcreate. I *think* that you might be wrong about camcreate. I tried running a script in a mp game with 1 client, 1 server, with the line
Code: [Select]
? local server: sh = "shell125" camcreate getpos aawhere server was a game logic, aa was the name of the soldier the server inhabited. The explosion was visible from, and killed, both players.
Here is an updated version of camcreate, which i will delete if it subsequently turns out to be wrong ;)

Camcreate

The effects of this will be seen and felt from all computers, similarly to createvehicle. If camcreate runs only on the server, the results *will* affect all clients; ordinance *will* hurt all clients. If camcreate runs on all clients, the command wil be repeated, once for each client, and once for the server.

Createvehicle

The effects of this are similar to camcreate. Two important distinctions - firstly, createvehicle offsets the object it creates to fit in with nearby objects' collision radii. Camcreate does not. Secondly vehicles created by createvehicle will be usable; vehicles created with camcreate will not be.
« Last Edit: 31 Mar 2005, 05:20:42 by Fragorl »

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re:How do scripting commands behave in MP?
« Reply #4 on: 31 Mar 2005, 08:36:11 »
deleteVehicle
works normal in MP, regardles of locality. If a vehicle is deleted on a client machine it's deleted on the server. If it's deleted on the server it's deleted on the clients.

distance
May return a different value on client and server and the result is rather unnpredictable. The reason for this is lag. Since the client machines are somewhat slower than the server it's possible that a condition like unitOne distance unitTwo <50 will be set to true on the server while it is still false on the client machines. Solution: Never, ever measure distance on the clients.

objStatus
Status "ACTIVE", "FAILED", "DONE","HIDDEN" is local and may be different on all machines. Thus it is possible that an objective that is completed on a client will not be registered by the server.
« Last Edit: 31 Mar 2005, 10:22:02 by nominesine »
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Roni

  • Members
  • *
  • Play the Game !
Re:How do scripting commands behave in MP?
« Reply #5 on: 31 Mar 2005, 09:36:36 »
A few observations from my travels . . .

titlecut
The comref says that this command is obsolete but it still works for me and I'm patched to v1.96.  Titlecuts are local to each machine so you can fade one guy to black while all others retain normal vision etc.

particle drops
These USED to be local but it seems that since about v1.91 or so these are now run on all machines.  It used to be very annoying lighting a fire via a script and having it burning on just one machine . . .

setViewdistance
This is local to each machine.  If you wanted, you could blind one guy while all other players had 5 km visibility.

random
Again, local to each machine.  If you're running a script on all machines that uses a random function you will need to make sure that just ONE machine rolls the dice then passes it's results to all other machines via a server routine, otherwise all of your results will be out of whack.


skipTime
Again, is local to each machine.  What's worse, script execution is partially clock speed dependant.  So if the skipTime script has a pause of (say) 0.1 second between cycles then my machine might take 0.10003 seconds to execute while yours takes 0.100037 seconds to do it.  This does add up over time so that two machines running the same script at supposedly the same time will find themselves out of sync in very short order.

The best solution to this problem is to again have one machine carry out the skipTime function then broadcast the resulting time (via the daytime command) to all other machines via a server loop, while all other machines just read the publicVariable each cycle and skipTime accordingly.


That's all I can think of for now.



roni

Chris330

  • Guest
Re:How do scripting commands behave in MP?
« Reply #6 on: 31 Mar 2005, 10:03:08 »
This is the best thread idea for ages. This should be pinned ;) :D

Chris330

  • Guest
Re:How do scripting commands behave in MP?
« Reply #7 on: 31 Mar 2005, 10:27:15 »
I have a question :) In my MP mission which I'm building I have defined several groups using the init lines of the respective units of the groups. I assume from this thread now that it is likely that only the server's machine will recognise these groups.

So my question is where can I execute a script that will define the groups on all machines (including clients). Should I put it in the init.sqs file or something ???

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:How do scripting commands behave in MP?
« Reply #8 on: 31 Mar 2005, 10:35:55 »
Great! Thanks for the feedback so far. I sure hope this thread gets filled to the brim...
Quote
This is the best thread idea for ages.
Yeah, it's so good, it's been thought of 1,000,000 times before... just no one has ever made a really organized post for it I suppose. :D
Quote
Re: Init fields. I understand now; an init field is local to whichever computer the unit belongs to.
I don't think this is true. I've run assignment statements thru an init field (groupA = group this), and the variable is set on all machines. I believe the issue with deleting units from the init field is just one specific oddity in ofp.
Quote
Re: Leader. So, if the leader dies, even if a new leader takes his place, the old one (corpse) still remains leader?
Yes, the corpse will remain the leader. I have not yet done much research into the specifics (like if the leader ever changes), but I did notice that after killing a group leader, his corpse was returned with this command. Since this NEVER happens in SP, I wrote it down, as an example of "other MP issues" that might arise from a command other than locality.

Re: camcreate
I'm pretty sure I've had different results with this command than you suggest, but hopefully some MP experts with WAY more experience than me to set us all straight. :)

Just for completeness:

titlersc
cutobj
cutrsc
titletext
cuttext

These commands all behave like titlecut (above).
« Last Edit: 01 Apr 2005, 00:03:30 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:How do scripting commands behave in MP?
« Reply #9 on: 31 Mar 2005, 10:39:27 »
I have a question :) In my MP mission which I'm building I have defined several groups using the init lines of the respective units of the groups. I assume from this thread now that it is likely that only the server's machine will recognise these groups.

So my question is where can I execute a script that will define the groups on all machines (including clients). Should I put it in the init.sqs file or something ???

You posted this while I was typing up my last post, but I'll clarify the point in a new one.

If you define the group in a unit's init field, it will be defined on all machines. However, if you delete the unit right after you define the group (i.e. no delay in between), it will NOT be defined on all machines.

Incorrect:
Code: [Select]
   groupA = group this; deletevehicle thisCorrect:
Code: [Select]
   groupA = group this; this exec "delete.sqs"delete.sqs:
Code: [Select]
~2
deletevehicle _this
« Last Edit: 31 Mar 2005, 10:39:46 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re:How do scripting commands behave in MP?
« Reply #10 on: 31 Mar 2005, 10:40:47 »
publicVariable

*** Erroneous theory deleted to avoid confusion - see correct explanation in GB's post below ***

« Last Edit: 23 Aug 2006, 13:05:16 by nominesine »
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:How do scripting commands behave in MP?
« Reply #11 on: 31 Mar 2005, 10:53:06 »
@publicvariable

Err.... I believe you are incorrect about how this command behaves. It does not "declare" a variable as public. Rather, it "broadcasts" the variable to all computers at the time you use the command. So if you had the following script run on the server:
Quote
a = 4
publicvariable "a"
a = 6
Then "a" would be 4 on all computers, except on the server, where it would be 6. Each of those computers could then change their own, personal "a" variable as much as they like. However, once any computer broadcast "a" with the publicvariable command again, then everyone else's "a" would be set to that one value (after which they could be changed again, and so on).

Basically, "publicvariable" should really be thought of as "broadcast public variable".

An important note about this, however, is that there will be a slight delay between when the variable is sent from a machine, and when it is recieved on every other machine (depending on ping). Usually this isn't to worry about, but for time-sensitive data, it could be.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re:How do scripting commands behave in MP?
« Reply #12 on: 31 Mar 2005, 11:13:26 »
*** post deleted as above ***
« Last Edit: 23 Aug 2006, 13:06:18 by nominesine »
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re:How do scripting commands behave in MP?
« Reply #13 on: 31 Mar 2005, 11:57:09 »
*leader
move
objStatus
player
random

Random is baaaaaad...if you got, i.e a=(random 100) in a script, then each computer gets it's own a, so the best thing is to either run the script only on server (if possible), or run only the random stuff on the server and publicvariable it to every one else.

Offline Roni

  • Members
  • *
  • Play the Game !
Re:How do scripting commands behave in MP?
« Reply #14 on: 31 Mar 2005, 12:35:32 »
Re: publicVariable - In use (if not in fact) there are three different types of variables, not two - private, public and "shared public".

Private variables
As we all know (  :P  ) private variables are local only to the script in which they appear.  So for instance - I could write one script that spawns another script any number of times and have each of these spawned scripts use the same private variable at the same time.  This is not a problem as each variable is only relevant within its own environment.

Example -

;parent.sqs
_x=10
#loop
this exec "offspring.sqs"
_x=_x-1
~1
if _x >0 then goto "loop"

;offspring.sqs
_x=10
#loop
"Shell73" camCreate (getPos player)
_x=_x-1
~1
if _x >0 then goto "loop"



parent.sqs will spawn offspring.sqs ten times and each of these spawned scripts will in turn camCreate a Shell73 on the head of the player ten times (100 Shell73's in total).    :noo:  :beat:

In this case _x is used in the parent script AND in each of the spawned offspring scripts.  At any given time the value of this variable will be different in each and every script, but this won't matter as they are only ever referred to internally.  The _x in parent.sqs has absolutely nothing in common with the _x in any other script that uses that same variable name apart from the label "_x".


Public variables
Unlike private variables, public variables DO care about other scripts, but only if they are running on the same machine !.  In this way you can create a "persistent" variable that can be set by one script (eg init.sqs) and then modify it throughout the mission by running other scripts (eg via addActions, triggers etc).

Example -

;init.sqs
playerCanteens = 12

;drinkWater.sqs
if playerCanteens < 1 then exit
playerCanteens = playerCanteens - 1
<player effects go in here>
:



In this instance init.sqs sets the variable at the outset and each use of the script drinkWater.sqs reduces it.  playerCanteens may also be reduced by other scripts or influences (eg - triggers), but again, only if they are called on that machine.

In fact, the above scripts could be run simultaneously on all machines running in an MP mission and there would be no problem - each machine would update it's own version so that I might be completely out of canteens while you still had nine left, for example.


"Shared Public" variables
This is the same as above, but in this case other machines DO affect the variable.  To make a public variable "shared" all you have to do is execute the command "publicVariable XXX" where XX is the variable to be broadcast.

Taking the above example as a start, if one machine were to broadcast "publicVariable playerCanteens" then the current value of ITS version of playerCanteens would be broadcast to all other machines, instantly updating them to this value.  So if I was empty and you still had nine left, and I broadcast my value then you and every other player in the game would now also be empty.  And I would instantly become very unpopular !     :P   :P

Note that in most cases publicVariables will want to be shared, but not always.

The above sample is a good example of when you WOULD NOT want to broadcast it.  In this case one script works for all players, each running their own version and keeping track of their own canteen levels - there is no need to write one version of the script for each player.

A good example of when you WOULD want to broadcast it would be a scoring script - one machine would update the score then broadcast this to all other machines, the others would just read the broadcast value and update their own version of this variable accordingly.


Server loops and client loops
This brings up the best way to use shared public variables - server loops and client loops.  Check out the following time dilation script -

; timeDilation.sqs

; set time dilation factor
_dilationFactor = 1/1200

; Send client machines to client loop
? !(local server) : goto "clientloop"

; This loop runs continuously on host machine actioning time dilation.
; Time dilation is sent to all client machines via public variable declaration
#serverloop
skipTime _dilationFactor
realTime = daytime
publicVariable "realTime"

; Pause, continue loop
~0.1
goto "serverloop"

#clientloop

; This loop runs continuously on all client machines actioning time dilation.
; Dilation factor is derived continuously from public variable realTime distributed by host machine
? realTime > daytime : skipTime (realTime - daytime)

; Pause, continue loop
~0.1
goto "clientloop"



This script uses a server loop which update the server's game time and broadcasts this to the network, and a client loop which simply receives the server-determined game time and update its own local game time accordingly.  This saves having to write two scripts and makes it easier for a scripter to understand and edit it.


Converting "public" and "private" variables
Once you have defined a variable you can convert for what type to another by simply reassigning it.  For example - you might have a private variable that runs within a script that at its conclusion spits out a public version of the same value.  The syntax is simple - all you do is drop the preceding underscore in the public version (eg - playerCanteens = _playerCanteens)

For instance, you might want to run one single script on 10 different units that returns ten  different values, then takes the highest or lowest one of these values.  Similarly, you might want to run a script on ten different PLAYERS (ie machines), then take the highest or lowest of these results.  In this case, the script would run, the public variable would be assigned, then it would be broadcast to the network. (eg - playerCanteens = _playerCanteens, publicVariable playerCanteens)

Well, that's my latest two cents on the subject.  Once again, I started writing and my fingers got ahead of me.  I apologise in advance for any poorly written or boneheadly obvious info contained in this post.

Cheers all



roni