03-02-2010, 05:32 PM
I was just reading a tutorial about triggers in MP which I found interesting. This may be useful.
Quote:TRIGGERS
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.
Example scenario:
Trigger with Condition: East Present
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.
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â¦
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:
1st Trigger:
- Condition: East Present
- OnActivation: trig1Fired = True; publicVariable "trig1Fired"
2nd Trigger:
- Condition: trig1Fired
- OnActivation: hint "This is a more secure way to get things done in OFP."; [] exec "bringintheWOMD.sqs"
How this works:
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.
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.
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.