Jump to content
Sign in to follow this  
lato1982

How to sync all scripts for multiplayer?

Recommended Posts

Hi,

I've made a coop mission, that was working well in all my tests in editor and scenraio mode. It was designed to play with a few friends as a coop mission, but a big issue occured during the gameplay. All scripts that i made were working local on each computer. So each of us had to do the same objective local. Is there a way to public all variables ? Or do i have to write in each script to public each variable that is needed? What will be a best solution for this?

This is one of the scripts example:

objBardak = false;

         Bardak addEventHandler ["Killed",

	  {

         _m = createMarker["BARDAK CORPSE",getPos Bardak];    
         _m setMarkerShape "ICON";    
         _m setMarkerType "dot";   
         _m setMarkerColor "ColorRed"; 
	  _m setMarkerText "Leader Body - needs identification"; 


        }
	 ];

waitUntil {!alive Bardak};	 
waitUntil {(player distance Bardak) < 5};

cutText ["identifying body...","PLAIN DOWN"];
sleep 1;
cutText ["It's Joseph Bardak!","PLAIN DOWN"];
hint "It's Joseph Bardak!";

taskBardak setTaskState "Succeeded";
taskhint ["Eliminate JOSEPH BARDAK", [1, 1, 1, 1], "taskDone"];

"BARDAK CORPSE" setMarkerText "Joseph's Bardak Body - Confirmed"; 
"BARDAK CORPSE" setMarkerColor "ColorBlue"; 

objBardak = true;

if (!bossLocationKnown AND (!alive Bardak)) then {
sleep 10;
bossLocationKnown = true;
cutText ["YOU GOT THE INTEL ABOUT YURI PETROV PRESENT LOCATION [MARKED ON MAP]", "PLAIN"];
hint "PETROV LOCATION UPDATED";

deleteMarker "BOSS_1";
deleteMarker "BOSS_2";
deleteMarker "BOSS_3";
deleteMarker "BOSS_4";
deleteMarker "BOSS_5";

         _m = createMarker["BOSS_LOCATION",getPos Boss];    
         _m setMarkerShape "ICON";    
         _m setMarkerType "warning";   
         _m setMarkerColor "ColorBlue"; 

	  _m setMarkerText " Yuri Petrov Present Location";

Thank You,

Share this post


Link to post
Share on other sites

You should run the script only on the server, that should fix your problem.

But the script is going to have to be changed quite dramatically.

Share this post


Link to post
Share on other sites

if(isServer)then{...}; or if(!isServer)exitwith{};

=============

if (isServer) then {

//..local hosted server

//..single player

//..dedicated server

};

if (!isServer) then {

//..client on local hosted server (not the host itself!!!)

//..client on dedicated server

};

if (isDedicated) then {

//..dedicated server only

};

if (!isDedicated) then {

//..local hosted server

//..singleplayer

//..all clients

};

if (!isDedicated and isServer) then {

//..local hosted server

//..singleplayer

};

if (!isDedicated and isServer and not isMultiplayer) then {

//..local hosted server

};

Share this post


Link to post
Share on other sites

Ok I'm starting to understand this.

1. So how do i know which commands work local and which are global for MP? For example createMarker works for all players, but how about other commands. I have found this info:

http://community.bistudio.com/wiki/6thSense.eu:EG#Locality

but I think it is just a tip of the ice berg...

The locality of functions is documented in the biki - but where? Is it the Multiplayer Tag - empty means its local?

2. Why all triggers in the editor works always global?

Thanks,

Edited by Lato1982

Share this post


Link to post
Share on other sites

1. Although it is the tip of the iceberg indeed, that's a very good starting point. Having in mind the general stuff regarding locality at all times is necessary if you want to code for MP.

The locality of most functions is documented on the biki. Watch for those two symbols on the top left corner.

AG means global arguments, AL Local Arguments (the arguments passed to the command have to be local to the machine executing the command).

EG means Global Effects (the effects of the command are broadcasted over the network), EL means Local Effects.

2. The triggers are local objects. In the editor, they are created on all machines when the mission.sqm is read. So they are NOT global, even in the editor. On the other hand, being created on every machine, they will probably fire on each machine at about the same time (hence the confusion, I guess).

Share this post


Link to post
Share on other sites

I think I got the point how this works basicly, thanks.

As I think of my script, I don't need to run it on server I just need to make sure that this line:

waitUntil {(player distance Bardak) < 5}; 

works for every human controled character. I thought "player" works that way, but it's not.

How do I replace this term, to met the conditions on each local machine?

is there a better term than player that is for each human controlled character?

or should i try with sth like this:

waitUntil {{(isPlayer _x) AND ((_x distance Bardak) < 5)} forEach allUnits};  // fixed 

will sth like this do the thing?

I can also replace createMarker with createLocalMarker or just add a condition if (isServer) and it should work.

Correct me if I'm wrong because testing MP is so much harder then testing some local scripts for SP.

EDIT:

I have tested another solution that actually works, but not sure about MP:

Mission Init:

{_x execVM "markers\bardakDeadMarker.sqf"} forEach allUnits;

and

bardakDeadMarker.sqf:

waitUntil {(isPlayer _this) AND ((_this distance Bardak) < 5)}; 

am I correct if this is gonna work in MP, since on each local machine the term will be tested for each human player, and the rest of the code will work for each client locally?

Thanks,

Edited by Lato1982

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×