Home   Help Search Login Register  

Advertisement

Author Topic: Scripting Commands in MP  (Read 6301 times)

0 Members and 1 Guest are viewing this topic.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Scripting Commands in MP
« on: 24 Aug 2006, 10:55:01 »

This is an edited version of General Barron's classical MP sticky "How do scripting commands behave in MP?". Many scripting commands work in very unexpected ways, in a MP environment. The purpose of this thread is to find out how.

What this thread is for

We want to know how OFP scripting commands work in MP:
  • 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?
What this thread is NOT for

  • Asking questions about how to solve your personal scripting problems.
Only report your discoveries here! Do not ask questions in this thread!
Discussion and questions are only allowed if they concern how scripting commands behaves in general in a MP environment.


Commands covered so far

action
addAction
animate
animationPhase
camCommand
- camCommand
- camCommit
- camCommitted
- camCreate
- camDestroy
- cameraEffect
- camSetBank
- camSetDir
- camSetDive
- camSetFov
- camSetFovRange
- camSetPos
- camSetRelPos
- camSetTarget
- camSetTarget
createVehicle
cutObj
cutRsc
cutText
deleteVehicle
distance
leader
objStatus
player
publicVariable
random
setpos
setvelocity
setdammage
setViewDistance
setFog
setOvercast
setRain
side
skipTime
titleText
titleCut
titleRsc

Is it local, global, private or public?

The difference between the global and the local scope causes as much confusion for beginner MP scripters as it does for the experts. Here's a simple explanation of the terms, as they are used in this thread.

We need to be able to tell the difference between local/global commands and private/public execution of commands.

When a command is started from a script, that only runs on the server or a single client, we say that it's execution is private. If the effects is then seen on all computers, the command is global. deleteVehicle and setDamage are both good examples of global commands who works like this - they are fool proof. A unit that is deleted or killed on one computer will be deleted or killed on all computers.

When a command is executed on all computers simultaneously we say that it's execution is public. If it is a local command, then the effects will only be seen once, on all computers (exactly as in a SP environment). However, if a global command is executed in public, then the effect will take place once for each computer in the network (4 players on a dedicated server would execute the command 4+1=5 times). createUnit is a good example of a global command that should never be executed in public (unless you want to create a mess). If we, following our 4+1 example above, wish to create a soldier, and we execute the createUnit command in public on all computers, then we would create five soldiers instead of one.

Fragorl  came up with the following summary, that shows how global/local works when they are executed in private/public:

global command + public execution = repeated command on all computers
global command + private execution = single command on all computers
local command + public execution = single command on all computers
local command + private execution = single command on one computer

Local and remote objects

All units, vehicles and objects are either local or remote. A local object is a unit or vehicle controlled by the computer you are playing on. Your player unit, as an example, is always local to you. AI-only groups are always local to the server. Mapobjects are local to everyone. Vehicles should be considered local to players - or AI under a players command - riding in them (this needs testing though, what happens if two players, in different groups, ride in the same vehicle?)



Commands list [To be continued...]

action
The action command should be run where ever the unit performing the action is local, for players or AI in a players group it is usually best to run it on all computers. Results and effects will be seen on all computers.

addAction
The action added will ONLY appear to the computer who executed the command. So if a client adds an action to an object, none of the other player's or their AI will be able to see/use the action. When a client adds an action to that machine's player, then only THAT player (and AI under his command) will be able to see/use that action. So if you want all players to be able to see and use an action, you have to make sure the addaction command is run on all computers. When a player uses the action, the attatched script will only be run on that player's computer.

animate
This must be run on only one machine. It doesn't seem to matter wich one, but the server is recommended. If a vehicle with animated parts recieves multiple "orders" from several computers it will most likely behave very unpredictable. (i.e one computer tells it to open the door, when the next computer tells it to start shutting the doors, and so on.) This has to do with synchronization between the server and the clients, and is not a problem connected with local/global space or private/public execution.

animationPhase
See comments on animate above. Might return a different value from different computers, due to desync and lag. Works best on the server.

camCommand and camCreate - Local
All camera type commands behave in the same way. They are strictly local and must be created on each computer to work properly. This applies to the following commands:

- camCommand
- camCommit
- camCommitted
- camCreate
- camDestroy
- cameraEffect
- camSetBank
- camSetDir
- camSetDive
- camSetFov
- camSetFovRange
- camSetPos
- camSetRelPos
- camSetTarget
- camSetTarget

Example - 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. Bullets, explosives and bombs made with this command will only explode on the computer where the command is run, but damage will be registered on all machines. You can use this command for creating effects, never use it to create units in game (see createVehicle command).

createVehicle - Global
createVehicle will create the desired vehicle on all machines, even if it's run locally on only one computer. Hence the command works best if it is run only on the server. Otherwise one vehicle will be created for each computer that participates in a MP mission. With a dedicated server and four players that would create 4+1=5 vehicles in game if the script is run on all machines.

cutObj - Local
These objects are local and can be displayed on one computer, but remain invisible to the others.

cutRsc - Local
These resources are local and can be displayed on one computer, but remain invisible to the others.

cutText - Local
This text is local and can be displayed on one computer, but remain invisible to the others.

deleteVehicle - Global
Always works normal in MP, regardles of where the command is run. If a vehicle is deleted on one computer it will be deleted on all computers. Period.

distance
Always meassure distance on the server. Technically the command is global and should return the same value, no matter where it is run, but since lag and desynchronization can produce different results on server and client the result would be unpredictable. The server is always right.

leader - Local
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 for sure if the passed groupname is defined on all computers. A group is usually defined in the init field of the commander using the syntax: myGroup = GROUP this
Notice: In MP there is always a short delay, a few seconds, before the groupname is defined on all machines in the network.

objStatus - Local
Status "ACTIVE", "FAILED", "DONE","HIDDEN" is local and may be different on all computers. Thus it is possible for an objective to be completed on a client, but not on the server. Very useful in Death Matches with different briefings for different sides.

player - Local
This useful command will return something different on each computer. It is always local and will always return the current body of the player who's computer runs the command. On a dedicated server this command will return null.

publicVariable
This is one of the most useful scripting commands a  MP mission maker or scripter can find. Let's say you have a variable that you know is local, it only exists on one machine. Now it's time for publicVariable. PublicVariable "broadcasts" the variable to all computers every time you use the command. So if you had the following script run on the server:

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" followed by 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 a private variable in public".

random - Local
This is local to each computer.  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.

setpos - Global
This command works normally in MP, regardless of what computer it is run on, or whether the object affected is local or remote.

setvelocity - Global
This command works normally in MP, regardless of what computer it is run on, or whether the object affected is local or remote.

setdammage - Global
This command works normally in MP, regardless of what computer it is run on, or whether the object affected is local or remote.

setViewDistance - Local
ViewDistance can be different on two computers. Thus it is possible to set alow viewDistance for infantry and a higher one for pilots in the air, for example.

setFog - Local
The environemental changes from this command will ONLY take place on the computer where the command is run from. It is entirely possible for one client to see fog, while another sees a clear day.

setOvercast - Local
The environemental changes from this command will ONLY take place on the computer where the command is run from. It is entirely possible for one client to see clouds, while another sees a clear sky.

setRain  - Local
The environemental changes from this command will ONLY take place on the computer where the command is run from. It is entirely possible for one client to be soaked, while another remains dry.

side - Local
This command work exactly as the command player, exept that it returns the side of any unit. There is a difference between the "side" data type and what gets displayed when you convert a side into a string. When you convert a side into a string, it is converted into a case sensitive string:

Side (data) vs. Side (string)
west - "WEST"
east - "EAST"
resistance - "GUER"
civilian - "CIV" (not entirely sure)
enemy - "ENEMY"

skipTime  - Local
This command must be run on all computers. Otherwise the time will only change on the computer where the change is made. It is possible for one player to see night while another sees day.

titleText  - Local
TitleText is local to each computer so you can display text to one computer that is not visible on the others.

titleCut  - Local
Titlecuts are local to each computer so you can fade one player to black while all others retain normal vision.

titleRsc  - Local
These resources are local and can be displayed on one computer, but remain invisible to the others.

The original thread was started by General Barron, and all credits for the initiative should go to him and the people who answeered his questions in the forums. This is an edited, and somewhat cleaner version, summarizing the results of that thread. All mistakes in it are mine, and the original authors quoted in this text are not to be blamed for any erroneous information that made it's way into the manuscript during editing.
- Nominesine, August, 2006
« Last Edit: 23 Oct 2006, 13:29:22 by bedges »
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Scripting Commands in MP
« Reply #1 on: 24 Aug 2006, 16:56:54 »
During the past months I've been making notes about the commands I've tried in different MP settings. Some of them are more or less verified, others needs more research. have a look at them, and correct me if I'm wrong. I marked the areas needing research in red.

accTime
Time acceleration does not work in MP. Don't even try.

alive - Global
This command will always return the same value. If a unit is dead on one computer, it is dead on all computers.

buildingPos
Mapobjects are local objects to all computers. Hence a reference to a buildingPos will always remain the same on all computers.

cadetMode
Will only react on the mode set by the server. If the server is running in cadet all computers are running in cadet. If the server is running in veteran all computers are running in veteran.

canCommand - Global
- canFire
- canMove
- canStand
These commands works exactly as in SP. A unit who is unable to stand will be unable to stand on all computers. It is not verified if this is also true for players (i.e unit A - who is a player - is unable to stand, will this command return the same value on another players computer?)

civilian
A civlilian unit is a civilian unit and will remain a civilian unit on all computers. See side for special notes.

commander - Global
This command will always refer to the actual commander of the selected vehicle, regardles of locality.

daytime
- Local
However strange as it may sound, this command can return a different value on different computers. Desync between server and client can cause a time offset between the compuetsr in the network, as can skipTime commands. To be on the safe side: execute dayTime only on the server. The server is always right.

driver - Global
This command will always refer to the actual driver of the selected vehicle, regardles of locality.

east
An east unit is an east unit and will remain an east unit on all computers. See side for special notes.

enableRadio - Local?
I am 99% sure that this command is local (it's possible for one player to have access to radio communication while the others are unable to hear it). Needs confirmation.


exit - Local and Private
This command only terminates the script in wich it is executed.

fadeMusic - Local
It is possible to fade the music on only one computer.

fadeSound - Local
I just assume this works as fadeMusic. Can someone verufy this?


forceMap - Local
Just like the different camera types of commands. It is possible to force the map into view on one computer, but not on another.

gunner - Global
This command will always refer to the actual gunner of the selected vehicle, regardles of locality.

getDammage - Global
Always returns the same value, no matter where the command was executed. Danmage is recorded equally on all machines.

hint - Local
It is possible (and sometimes very useful) to execute hints only on some computers.

hintC - ???
I've never tested hintC (the one that requires clicking to unpause the game again) in MP. Since MP games cannot be paused, I'm not sure how it works. If it does work, I assume it behaves like hint, and that that the game is not paused behind the hint box. This needs to be verified, though.

hintCadet
I assume it woorks like hint. See my note on cadet, though. This needs verification before it goes into the first post as a stated fact.


inflame - Global
Fires will be lit at all computers (since OFP version 1.80 I believe, it wasn't like this from start).

inflamed
- Global
If it burns it burns. A fire cannot be flaming on one computer and remain cold on another.
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Scripting Commands in MP
« Reply #2 on: 24 Aug 2006, 17:44:59 »
I thought the CoC list from page 3 of the original thread gave the definitive answer for all commands?
urp!

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: Scripting Commands in MP
« Reply #3 on: 24 Aug 2006, 20:13:40 »
Quote
enableRadio - Local?
I am 99% sure that this command is local (it's possible for one player to have access to radio communication while the others are unable to hear it). Needs confirmation.

Think it is local, because it only blocks radio communication that is local (if the local player writes something it's blocked, but if another player writes something to the first one, it's not blocked...).

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Scripting Commands in MP
« Reply #4 on: 24 Aug 2006, 21:07:29 »
I thought the CoC list from page 3 of the original thread gave the definitive answer for all commands?

It is very useful indeed, but as stated in the old thread... many commands behaves strangely for other reasons than local/global reasons in MP. That's part of what we're trying to figure out in this thread.  Also, the CoC list needs to be rewritten into a more readable format, wich is the second goal of this thread. Feel free to edit the information in the CoC and put it here :)

@garcia
I'm not sure I follow you here (maybe because i always play the games without any subtitles) but you are refering to the sideChat that a player can use in Mp, right? I didn't know that this was also affected by enableRadio. Have you tested this?
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: Scripting Commands in MP
« Reply #5 on: 24 Aug 2006, 21:28:11 »
The radio communication is only the chat with some sounds, basically. If you write "enableradio false" in the init.sqs in a SP mission, and then place a unit and makes him use sidechat (i.e unit1 sidechat "Look at my arse"), then you don't se it. However in multiplayer this just "blocks" the local messages.

I.e player A and player B plays a multiplayer mission with enableradio set to false in the init.sqs. Player A write in the sidechat "Player B, you fart". Player A won't see this, because it's locally and therefor blocked, but Player B will see it. Same goes the other way, if player B writes something, A sees it while B doesn't. Don't know how it is with AI (haven't played with AI and enableradio false in MP), if you will see the messages from them or not.

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re: Scripting Commands in MP
« Reply #6 on: 07 Sep 2006, 22:37:27 »
Quote
createVehicle - Global
createVehicle will create the desired vehicle on all machines, even if it's run locally on only one computer. Hence the command works best if it is run only on the server. Otherwise one vehicle will be created for each computer that participates in a MP mission. With a dedicated server and four players that would create 4+1=5 vehicles in game if the script is run on all machines.


Such a formulation is slightly misleading.

As often in MP, the way the command is issued is crucial to understanding the command's behaviour.

If you createVehicle something through a radio trigger, then the command will be executed on the server and on all clients, resulting in the creation of as many vehicles as computers in the game. Now if you check the locality of these vehicles, you'll see that each is local to the machine that's created it.


That's why I wouldn't say the command is global. On the contrary, it is local. Execute it locally (for instance through a script called by an action), one , and only one, object/vehicle, local to that particular client,  will be created. As to the related moveInXXXX commands, these will work if the issuer of the command, and the unit to be moved in driver/commander/gunner/cargo, are local to the same computer.

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Scripting Commands in MP
« Reply #7 on: 08 Sep 2006, 12:40:05 »
I want add here that createVehicle can also be used in an addAction script.
Since the script behind addAction will be executed local only.

There's only one thing you need to check, since when comming close enough
to other units you can also execute addActions added to them:

A simple check if the script executioner is player, if not: exit, should do the trick.

If you assign the unit a variable name, you can publicVariable it to broadcast in
network.

:edit - uhm - i must have overseen the last part of Igor's post.  :whistle: :-[

~S~ CD
« Last Edit: 09 Sep 2006, 13:51:31 by Chris Death »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline NoMore

  • Members
  • *
  • Location: Denmark
Re: Scripting Commands in MP
« Reply #8 on: 03 Oct 2009, 10:52:05 »
Quote
hintC
I've never tested hintC (the one that requires clicking to unpause the game again) in MP.
It works just like you think. It comes up but the game does not pause. ;)
"He who stands with me shall be my brother." - Warhammer 40k: Dawn of War