Home   Help Search Login Register  

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

0 Members and 1 Guest are viewing this topic.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:How do scripting commands behave in MP?
« Reply #45 on: 02 Oct 2005, 15:37:00 »
Understood mac. It's just that I was searching for this thread the other day and had trouble finding it, it had sunk so quickly.

It seems to me there is still much disagreement over how certain commands behave in MP.  I think it would it be safe to say that with the exception of createVehicleand  deleteVehicle, a command should executed on all clients if you want the effects to be observed on all clients.

Is redundancy an issue with any other commands? I know that the *Radio commands only need be executed on one client to be seen by all, but if a trigger executes a sideRadio command, for example, is the message displayed once or multiple times on each client?  

If I am using setWPPos or move for enemy AI (local to the server), does it cause problems to execute these commands on every client instead of only on the server?

Are there any situations where executing commands on all clients would cause problems other than unnecessary cpu load?  
« Last Edit: 02 Oct 2005, 15:37:58 by Mr.Peanut »
urp!

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:How do scripting commands behave in MP?
« Reply #46 on: 03 Oct 2005, 16:01:24 »
Is redundancy an issue with any other commands?
Yes. See "join" below.
Quote
I know that the *Radio commands only need be executed on one client to be seen by all, but if a trigger executes a sideRadio command, for example, is the message displayed once or multiple times on each client?
I wasn't aware that *Radio behaved differently from *Chat, which definitiely only has effect on the machine where it is issued. In other words: to have all nodes see the output of a *Chat, it has to be run on all nodes (possibly with the exception of a dedicated server, since that would be uneccessary)
Quote
If I am using setWPPos or move for enemy AI (local to the server), does it cause problems to execute these commands on every client instead of only on the server?
There could be problems. Let's say "script X" handles the moving around of a certain group and that script happens to run on all machines. Also, "X" will dynamically adapt the placement of waypoints and ordering of movement based on several external factors. Now, during an MP session, due to desync and packet loss and whatnot, the subset of the current gamestate that X needs to function might be different on different machines. The result would then be script X on machine A moving a waypoint to point P1 whereas the same script on machine B tries to move it to P2.

Therefore, the best practice is to issue these where the affected unit/group is local. (Now, move will only have an effect on the machine where the unit/group that move operates on is local)

Quote
Are there any situations where executing commands on all clients would cause problems other than unnecessary cpu load?
Yes. One example that comes to mind and that is very common is the use of the join command in waypoints or triggers. I have played several missions where the MP player group meets up with some other entity (classical "rescue VIP"-type missions) that then joins the player group. Since the mission maker was unaware of the many pitfalls of MP mission making, the result in-game will be several repeated calls for the VIP to join the squad:
Quote
5, join 1
5, ready
5, join 1
5, ready
5, join 1
5, ready
5, join 1
5, ready
5, join 1
5, ready
Now that's HIGHLY annoying!

mad rabbit

  • Guest
Re:How do scripting commands behave in MP?
« Reply #47 on: 23 Nov 2005, 17:26:49 »
I'm so glad this forum was made a sticky, albiet a temporary.  Tyring to find this info over last 2 years has been a nightmare!  Try not knowing this stuff when making a CTI...without 2 computers to trial it on!!

e.g. 1) make script
       2) replicate as needed
       3) found out command has MP issues
       4) edit all 10 scripts to source out to a script that is only executed on server/client

Nice work on getting this topic started and maintained General Barron!  Now if we can convince someone to make the tutorial or even better get HAMMY to include this info in his executable Command Reference 1.91 that would be great.

----------------------

I've taught myself OFP scripting from the ground-up (i.e. I know no other programming type language  :) what better way to learn than OFP) and I've been making a CTI for the last 2 years based on the MFCTI core.  

CTI maps use a lot of arrays, so my question is:

How are arrays effected by locality in a MP setting with a dedicated server?

e.g.
If I have an array defined at the start of a map in a script run on all machines (for CTI scripters this would be "Main\initserver.sqs") but I dynamically edit (contents not size for now) that array with different objects and sub-arrays, how is this handled in a MP setting?

1) global script = defines array
2) local to player script edits array = array contents edited/updated on all computers?
3) local to server script edits array = array edited/updated on all computers?

Now I've learnt the difference between variables, arrays, functions, commands, scripts etc. through various sources but here's the problem I have:

1) 'arrays' can hold 'objects' which can be defined as a 'variable'

e.g. Var1 = vehicle1;subArray = [Var1];mainArray = [subArray]
       i.e. mainArray = [[vehicle1]]

2) Now if Var1 changes to vehicle2 via a local to player script, does the contents of Array1 change?

e.g. local: Var1 = vehicle2
       server: subArray = [Var1]
       mainArray = [[?]]

I know it might seem off-topic in relation to the thread, but in relation to the 'PublicVariable' command, does this have to be done OR can be used (sorry for my lack of understanding in this department) with arrays?

Therefore, is it better to use arrays with multiple contents or mutliple variables that are broadcasted via the 'PublicVariable' command?

I'm of the mind that the former is better than the latter as I've read somewhere that arrays hold the information better whereas using variables can be erroneous in a MP setting?

---------------

Sorry if this is off-topic, but it was in a way in relation to the 'PublicVariable' command so it seemed fitting.  Feel free to move this as a serperate topic.  :)
   
« Last Edit: 23 Nov 2005, 17:30:41 by mad rabbit »

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:How do scripting commands behave in MP?
« Reply #48 on: 24 Nov 2005, 02:16:35 »
Good Q's, and I'd say that they are all on topic. I don't have much time for a reply, but I can add more later if needed.

The main issue here is how variables are handled in an MP environment. The answer is the same for all types of variables, including arrays.

Even though the global arrays are initialized at the same time, and with the same data, on every node (computer+server), each node stores its own array, completely separate from the rest. Later changes made to one node's array will NOT affect the other nodes (even though the array has the same name, and is global). The same is true for all other variable types.

Pretty much the only way you can have one node affect the variables on other nodes is with the 'publicvariable' command; which BTW doesn't support arrays, strings, and a few other types.

---------------

What I would HIGHLY recommend to ANYONE using fairly complex MP scripting, is that they use the CoC's Network Services 2. It has built in functions for sharing arrays across the network, as well as a couple other extremely handy functions. The documentation is a little hard to understand at first, but it is pretty straightforward once you get the hang of it, and it makes things about 1000x easier to script.

Crashdome had started making a tutorial on how to use the NS. I will have to see the status of that tut, and possibly finish it myself. I swear to you NS will make your life easier, especially with something as complex as CTI.
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!

Chris330

  • Guest
Re:How do scripting commands behave in MP?
« Reply #49 on: 25 Dec 2005, 04:11:56 »
Dear all,

I have a question. This is a script I have been writing which works fine on single player but has not been tested on multiplayer. There's no need to get bogged down in the script too much all I need to know is because game logic units are always local to the server, does this mean that their positions are always defined on the server and broadcast to the clients? Or, do I have to instruct the client machine(s) to change the postions of the game logics too, or can I just get away with altering their positions on the server?

The following script has been made assuming that the client machine(s) do not have to update the positions of the game logics. Rather it has been made assuming that the positions of the game logics in the mission are determined and broadcast globally by the server. Have a look at it. I have annotated the bits I need some clarification on (they are only small parts of the script).

Please note it is a camera script which utilises two game logic units. One named cameraeffect1 and one named cameraeffect2.



//I think this bit is now okay as I understand that camcreate
//must be executed on the client machines too.
:D
_camoffx = _this select 0
_camoffy = _this select 1
_helo = _this select 2
_cam1 = "camera" camcreate [0,0,0]
_cam1 cameraeffect ["internal", "back"]
_cam1 camsettarget cameraeffect1
_cam1 camsetrelpos [0,0,0]
_cam1 camcommit 0


#start
?not local server : goto "checkserverready"
//If this is not the server machine then goto the loop that
//waits for the server to finish the maths

_BankPitch = _helo call GetBankPitch
_Pitch = _BankPitch select 1
_sinangle = sin(_Pitch)
_cosangle = cos(_Pitch)

;evaluate where camsetrelpos command should set the camera to for _camoffy
e = (_sinangle) * (_camoffy)
a = (_cosangle) * (_camoffy)
//broadcast the camsetrelpos variables to the client(s)
publicvariable "a"
publicvariable "e"


;get heading of helicopter and evaluate x and y offsets for the game logics for _camoffx
_heading = getdir _helo
_angle = 360 - _heading
_xa = (cos (_angle)) * _camoffx
_ya = (sin (_angle)) * _camoffx

;Get position co-ordinates of helicopter
_xh = getpos _helo select 0
_yh = getpos _helo select 1

//The interesting bit. Will this automatically update the
//game logics' positions on the client?

;Position the game logics
cameraeffect2 setpos [(_xh + _xa),(_yh + _ya),0]
_dist = _helo distance cameraeffect2
_height = sqrt ((_dist^2)-(_camoffx^2))
cameraeffect1 setpos [(_xh + _xa),(_yh + _ya),_height]
cameraeffect1 setdir _heading
logiccomplete = true


//Client waits for server to finish then camsetrelpos variables
//are issued.

#checkserverready
?logiccomplete : goto "camerapositioning"
goto "checkserverready"

#camerapositioning
_cam1 camsetrelpos [0,a,e]
_cam1 camcommit 0
~0.001
logiccomplete = false
?camend : goto "finish"
goto "start"

#finish
_cam1 CameraEffect ["TERMINATE", "BACK"]
CamDestroy _cam1

exit

  8)
« Last Edit: 25 Dec 2005, 04:26:05 by Chris330 »