Guest User

Untitled

a guest
Jan 21st, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. TRIGGERS
  2.  
  3. Triggers work in a multiplayer environment a bit differently from how people usually think. Triggers, like everything else in OFP, are executed locally on every client. This can lead to “desync”, which means that players experience different things because the mission is not synchronized anymore between the clients and the server.
  4.  
  5. Example scenario:
  6.  
  7. Trigger with Condition: East Present
  8.  
  9. Let player X be a west soldier and player Y be an east soldier. When player Y walks into the zone of the trigger, his computer doesn’t send any particular information about the trigger event to player X’s computer. But in a normal situation the trigger also executes on player X’s computer because player Y’s character is also standing in the trigger zone on X’s computer.
  10.  
  11. But what if there is a lag peak, or player X’s / player Y’s connection lags slightly behind the other players’ connections just at the moment when the trigger should execute on all computers? That might cause player Y warping over the trigger on player X’s computer and thus the trigger will never fire for player X, even though it does so for player Y. These kinds of problems lead to entriely different situations in missions between players. Some players may have objectives marked done but others won’t etc…
  12.  
  13. To ensure this will not become a problem in your missions, you can implement a “safety net” for all mission critical triggers. This solution makes use of 2 triggers, set up as in the following example:
  14.  
  15. 1st Trigger:
  16. - Condition: East Present
  17. - OnActivation: trig1Fired = True; publicVariable "trig1Fired"
  18.  
  19. 2nd Trigger:
  20. - Condition: trig1Fired
  21. - OnActivation: hint "This is a more secure way to get things done in OFP."; [] exec "bringintheWOMD.sqs"
  22.  
  23. How this works:
  24.  
  25. 1. Player Y walks into the 1st trigger’s zone and the trigger executes at least (but not necessarily only) on player Y’s computer, setting the trig1Fired variable to True and sending a publicVariable message about the trig1Fired variable to all computers in the session. Now all computers should have variable trig1Fired variable set to True.
  26.  
  27. 2. On all computers in the session the 2nd trigger notices that the trig1Fired variable has become True and executes whatever was in 2nd trigger’s OnActivation line.
  28.  
  29. This method ensures that even if the 1st trigger only fires on player Y’s computer, the information is sent to all computers in the session thus leading to a synchronized game flow with the help of the 2nd trigger. It might be that some or even all computers in the session already saw the 1st trigger event and thus don’t need the additional publicVariable message, but this method takes into account the possibility of desync/lag etc. problems.
  30.  
  31.  
  32.  
  33. SCRIPTS
  34.  
  35. Scripts (started with exec, addAction) are also executed locally. This isn’t usually a problem but there are issues that must be taken into account when designing MP missions, especially when using the addAction command.
  36.  
  37. Lag and different speeds of client computers causes scripts to rarely start and end at the exact same time in multiplayer missions. This is why, for example, at the start of multiplayer missions some players may be able to start moving while others are still watching the intro. This issue has no workable solution – we have to live with the fact that people have different hardware and different connection speeds to the server.
  38.  
  39. Baddo’s thoughts: You could try to reduce this effect with a waiting loop at the end of your intro. Every client could tell the server that they have reached the end of the intro and after all clients have reported to be finished with the intro, the server would tell all clients to start the mission. This would increase the waiting time for some players, but would make the situation fairer to others who suffer from slower internet connection to the server or have slower hardware. In general, this is not worth doing imho, because there would still be differences in when the scripts start/end. This method might reduce the differences but would never remove them completely.
  40.  
  41.  
  42.  
  43. ADDACTION / PLAYER
  44.  
  45. A script started from addAction is only executed locally i.e. only on the computer of the player who uses the action. You must use the publicVariable command and a True/False variable to activate a trigger if you want your script to run on all computers in the session. Example:
  46.  
  47. this addAction ["Bring in the WOMD","activateWOMD.sqs"]
  48.  
  49. Script: activateWOMD.sqs
  50. trigWOMDFire = True
  51. publicVariable "trigWOMDFire"
  52. exit
  53.  
  54. Trigger:
  55. - Condition: trigWOMDFire
  56. - OnActivation: hint "This is a more secure way to get things done in OFP."; [] exec "bringintheWOMD.sqs"
  57.  
  58.  
  59. The player command can be very useful when using the addAction command. If you want to add an action to all players, you might be tempted to put this in Init field of each playable unit:
  60.  
  61. this addaction["Eat dust","eatdust.sqs"]
  62.  
  63. But this is not a good way to do it. All client computers in the session will execute this line of code for each playable unit. This leads to a situation where players will see the added actions of other playable units in their action menus if they are close enough to each other. In other words, players will see actions that are not meant for them at all or they will see multiple actions of the same type in their action menu.
  64.  
  65. A way to fix this problem is to execute this line of code at the start of the mission:
  66.  
  67. player addAction["Eat dust","eatdust.sqs"]
  68.  
  69. This code should go into the init.sqs file or an equivalent place where it will only be executed once for each player. Do not put this line in the Init fields of the units because then all players will add the action to themselves multiple times. Example:
  70.  
  71. In a playable unit’s Init field:
  72. this exec "initunit.sqs"
  73.  
  74. Script initunit.sqs:
  75. if not(local _this) then {exit}
  76. _this addAction["Eat dust","eatdust.sqs"]
  77. exit
  78.  
  79.  
  80. Happy editing.
Add Comment
Please, Sign In to add comment