Jump to content
Sign in to follow this  
fwouedd

I need your help : my random mission randomly fail with a dedicated server.

Recommended Posts

Hi.

I am currently working on a infantry mission. On start, it should create or choose a random weather, choose a random marker to spawn objects, units, trigger and players.

All is perfectly working in preview or if i host the game, but it's not the same on a dedicated server.

So :

Init :

enableSaving [false, false];
waituntil {!isnil "bis_fnc_init"};
call compileFinal preprocessFileLineNumbers "Scripts\fwd_revive.sqf";
call compile preprocessfile "Scripts\shk_pos_init.sqf";
call compile preprocessfilelinenumbers "Scripts\shk_taskmaster.sqf";
_handle1 = [1,1,0] execVM "Scripts\fwd_debug.sqf";
waitUntil {sleep 0.5;ScriptDone _Handle1};
_handle2 = execVM "Scripts\fwd_randomstart_init.sqf";
waitUntil {sleep 0.5;ScriptDone _Handle2};
_handle3 = execVM "Scripts\fwd_randomtime_init.sqf";
waitUntil {sleep 0.5;ScriptDone _Handle3};
_handle4 = execVM "Scripts\fwd_randomstart.sqf";
waitUntil {sleep 0.5;ScriptDone _Handle4};
_handle5 = execVM "Scripts\fwd_randomtime.sqf";
waitUntil {sleep 0.5;ScriptDone _Handle5};
_handle6 = execVM "Scripts\fwd_wait.sqf";
waitUntil {sleep 0.5;ScriptDone _Handle6};
_handle7 = execVM "Scripts\OPFOR\fwd_OPFOR.sqf";
waitUntil {sleep 0.5;ScriptDone _Handle7};
handle8 = execVM "Scripts\fwd_objectives.sqf";

_handle1 : Scripts\fwd_debug.sqf

fwd_trackunit = _this select 0;
fwd_showmarker = _this select 1;
fwd_debug = _this select 2;

publicVariable "fwd_trackunit";
publicVariable "fwd_showmarker";
publicVariable "fwd_debug";

if ( fwd_debug  == 1 ) then { hintC format ["Debug Mode running.\n - Unit tracker : %1\n - Marker tracker : %2",fwd_trackunit,fwd_showmarker]};

_handle2 : Scripts\fwd_randomstart_init.sqf

if (isServer) then { 
_missionsector0 = ["Z1","Z2","Z3","Z4","Z5","Z6","Z7","Z8","Z9","Z10","Z11","Z12","Z13"];
_missionsector  = _missionsector0 select floor(random count _missionsector0);
Startpoint = getmarkerpos _missionsector;
publicVariable "Startpoint";
_marker1 = createMarker ["S1", Startpoint];
"S1" setMarkerShape "ELLIPSE";
"S1" setMarkerBrush "Border";
"S1" setMarkerColor "Colorblue";
"S1" setMarkerSize [2500, 2500];
if ( fwd_showmarker  == 1 ) then { "S1" setMarkerAlpha 1} else { "S1" setMarkerAlpha 0};

_marker2 = createMarker ["S2", Startpoint];
"S2" setMarkerShape "ELLIPSE";
"S2" setMarkerBrush "Border";
"S2" setMarkerColor "Colorblue";
"S2" setMarkerSize [1500, 1500];
if ( fwd_showmarker == 1 ) then { "S2" setMarkerAlpha 1} else { "S2" setMarkerAlpha 0};

_posSTART = ["S1",0,"S2"] call SHK_pos;
_marker3 = createMarker ["S3",_posSTART];
"S3" setMarkerShape "ICON";
"S3" setmarkerSize [1,1];
"S3" setMarkerType "mil_dot";
if ( fwd_showmarker  == 1 ) then { "S3" setMarkerAlpha 1} else { "S3" setMarkerAlpha 0};

_marker4 = createMarker ["C1", Startpoint];
"C1" setMarkerShape "ICON";
"C1" setmarkerSize [1,1];
"C1" setMarkerType "mil_dot";
if ( fwd_showmarker  == 1 ) then { "C1" setMarkerAlpha 1} else { "C1" setMarkerAlpha 0};

_marker5 = createMarker ["M", Startpoint];
"M" setMarkerShape "ELLIPSE";
"M" setMarkerBrush "Border";
"M" setMarkerColor "ColorRed";
"M" setMarkerSize [1000, 1000];
if ( fwd_showmarker  == 1 ) then { "M" setMarkerAlpha 1} else { "M" setMarkerAlpha 0};

_marker6 = createMarker ["M1", Startpoint];
"M1" setMarkerShape "RECTANGLE";
"M1" setMarkerBrush "BDiagonal";
"M1" setMarkerColor "ColorRed";
"M1" setMarkerDir ([ Startpoint , leader PlayerGrp ] call BIS_fnc_dirTo);
"M1" setMarkerSize [1000, 1000];
"M1" setMarkerAlpha 0;
if ( fwd_showmarker  == 1 ) then { 	_marker6a = createMarker ["M1a", Startpoint];"M1a" setMarkerShape "RECTANGLE";"M1a" setMarkerBrush "BDiagonal";"M1a" setMarkerColor "ColorRed";"M1a" setMarkerDir ([ Startpoint , leader player ] call BIS_fnc_dirTo);"M1a" setMarkerSize [1000, 1000];"M1a" setMarkerAlpha 0.5};

_marker7 = createMarker ["M2", Startpoint];
"M2" setMarkerShape "RECTANGLE";
"M2" setMarkerBrush "BDiagonal";
"M2" setMarkerColor "ColorRed";
"M2" setMarkerDir ([ Startpoint , leader PlayerGrp] call BIS_fnc_dirTo);
"M2" setMarkerSize [250, 250];
"M2" setMarkerAlpha 0;
if ( fwd_showmarker  == 1 ) then { 	_marker7a = createMarker ["M2a", Startpoint];"M2a" setMarkerShape "RECTANGLE";"M2a" setMarkerBrush "BDiagonal";"M2a" setMarkerColor "ColorRed";"M2a" setMarkerDir ([ Startpoint , leader player ] call BIS_fnc_dirTo);"M2a" setMarkerSize [250, 250];"M2a" setMarkerAlpha 1};
};

_handle3 : Scripts\fwd_randomtine_init.sqf

if (isServer) then
{	
mytime = round(random 24);
myweather = 0.2 + ((round (random 5))/10);
mywind1 = (round(random 60)) - 30;
mywind2 = (round(random 60)) - 30;

if ( myweather > 0.7) then
	{
		myfog =  0.2 - ((round(random 2))/(10));
	} else {
		myfog= 0.01;
	};

 if ( myweather > 0.5) then
	 {
		myrain =  myweather +((round(random 2))/(10));
	} else {
		myrain= 0;
	 };

fwdinitialWeather = (paramsArray select 0);  
switch (fwdinitialWeather) do 
	{
	case 1: {fwdweather = 0;fwdrain = 0;fwdfog = 0;fwdwind1 = 1;fwdwind2 = 1;};                            
	case 2: {fwdweather = .40;fwdrain = .40;fwdfog= 0;fwdwind1 = 2;fwdwind2 = 2;};                        
	case 3: {fwdweather = .70;fwdrain = .70;fwdfog = .05;fwdwind1= 3;fwdwind2 = 3;};                       
	case 4: {fwdweather = 1;fwdrain = 1;fwdfog = .05;fwdwind1 = 4;fwdwind2 = 4;};                       
	case 5: {fwdweather = .75;fwdrain = .10;fwdfog = .30;fwdwind1 = 1;fwdwind2 = 1;};                     
	case 6: {fwdweather = .85;fwdrain = .20;fwdfog = .50;fwdwind1= 0;fwdwind2 = 0;};
	case 7: {fwdweather = myweather;fwdrain = myrain;fwdfog = myfog;fwdwind1 = mywind1;fwdwind2= mywind2;};
	};

publicVariable "fwdweather";
publicVariable "fwdwind1";
publicVariable "fwdwind2";
publicVariable "fwdfog";
publicVariable "fwdrain";

fwdinitialhour = (paramsArray select 1);  
switch (fwdinitialhour) do
{
case 1: {fwdtime = 13;};                            
case 2: {fwdtime = 17;};                       
case 3: {fwdtime = 23;};                      
case 4: {fwdtime = 30;};
case 5: {fwdtime = 33;};
case 6: {fwdtime = mytime;};  	
};	
publicVariable "fwdtime";
};

_handle4 : Scripts\fwd_randomstart;sqf

waitUntil { !(isNull player) };
waitUntil { time > 0 };
player setPosATL getMarkerPos "S3";
player setDir  ([ leader PlayerGrp , Startpoint ] call BIS_fnc_dirTo)};

_handle5 : Scripts\fwd_randomtime.sqf

waitUntil {!isNil "fwdtime"};
skipTime fwdtime;
1 setOvercast fwdweather;
1 setFog fwdfog;

_handle6 : Scripts\fwd_wait.sqf (without this script, the sky doesn't change, with it, my entire ramdom weather script run correctly.)

skipTime 1;
1 setRain fwdrain;
setWind [fwdwind1,fwdwind2,true];

_handle7 : Scripts\OPFOR\fwd_OPFOR.sqf

if (isServer) then { 

// Unit 1 spawn settings;
nul = [u1,"M1","Random","nofollow"] execVM "Scripts\fwd_ups.sqf";
if ( fwd_trackunit  == 1 ) then 
	{ 0 = [] spawn 
		{
		_Marker_U1 = createMarker ["Marker_U1",[0,0]];
		"Marker_U1" setMarkerShape "ICON";
		"Marker_U1" setmarkerSize [0.5,0.5];
		"Marker_U1" setMarkerType "mil_dot";
		"Marker_U1" setMarkerColor "ColorRed";
		"Marker_U1" setMarkerText "U1";
		while {not isnull U1} do {"Marker_U1" setmarkerpos getpos U1; sleep 0.5;};
		};
	};

// Unit 2 spawn settings;
nul = [u2,"M1","Random","nofollow"] execVM "Scripts\fwd_ups.sqf";
if ( fwd_trackunit  == 1 ) then 
	{ 0 = [] spawn 
		{
		_Marker_U2 = createMarker ["Marker_U2",[0,0]];
		"Marker_U2" setMarkerShape "ICON";
		"Marker_U2" setmarkerSize [0.5,0.5];
		"Marker_U2" setMarkerType "mil_dot";
		"Marker_U2" setMarkerColor "ColorRed";
		"Marker_U2" setMarkerText "U2";
		while {not isnull U2} do {"Marker_U2" setmarkerpos getpos U2; sleep 0.5;};
		};
	};

// Unit 3 spawn settings;
nul = [u3,"M2","Random","nofollow"] execVM "Scripts\fwd_ups.sqf";
if ( fwd_trackunit  == 1 ) then 
	{ 0 = [] spawn 
		{
		_Marker_U3 = createMarker ["Marker_U3",[0,0]];
		"Marker_U3" setMarkerShape "ICON";
		"Marker_U3" setmarkerSize [0.5,0.5];
		"Marker_U3" setMarkerType "mil_dot";
		"Marker_U3" setMarkerColor "ColorRed";
		"Marker_U3" setMarkerText "U3";
		while {not isnull U3} do {"Marker_U3" setmarkerpos getpos U3; sleep 0.5;};
		};
	};
if ( fwd_debug   == 1 ) then { hintC "FWD_objectives : spawn ok"};

// Unit 4 spawn settings;
nul = [u4,"M2","Random","nofollow"] execVM "Scripts\fwd_ups.sqf";
if ( fwd_trackunit  == 1 ) then 
	{ 0 = [] spawn 
		{
		_Marker_U4 = createMarker ["Marker_U4",[0,0]];
		"Marker_U4" setMarkerShape "ICON";
		"Marker_U4" setmarkerSize [0.5,0.5];
		"Marker_U4" setMarkerType "mil_dot";
		"Marker_U4" setMarkerColor "ColorRed";
		"Marker_U4" setMarkerText "U4";
		while {not isnull U4} do {"Marker_U4" setmarkerpos getpos U4; sleep 0.5;};
		};
	};

// Unit 5 spawn settings;
_posU5 = [getmarkerpos "M1",[10,1000],random 360,0,[0,1000]] call SHK_pos;
_MU5 = createMarker ["MU5", _posU5];
"MU5" setMarkerShape "ICON";
"MU5" setmarkerSize [1,1];
"MU5" setMarkerType "mil_dot";
"MU5" setMarkerText "U5";
if ( fwd_showmarker  == 1 ) then { "MU5" setMarkerAlpha 0.5} else { "MU5" setMarkerAlpha 0};
U5 setpos _posU5;
if ( fwd_trackunit  == 1 ) then 
{ 0 = [] spawn 
	{
	_Marker_U5 = createMarker ["Marker_U5",[0,0]];
	"Marker_U5" setMarkerShape "ICON";
	"Marker_U5" setmarkerSize [0.5,0.5];
	"Marker_U5" setMarkerType "mil_dot";
	"Marker_U5" setMarkerColor "ColorRed";
	"Marker_U5" setMarkerText "U5";
	while {not isnull U5} do {"Marker_U5" setmarkerpos getpos U5; sleep 0.5;};
	};
	0 = [u5] execVM "Scripts\OPFOR\fwd_OPFORintercept.sqf";
};

	// Unit 6 spawn settings;
_posU6 = [getmarkerpos "M1",[10,1000],random 360,0,[0,1000]] call SHK_pos;
_MU6 = createMarker ["MU6", _posU6];
"MU6" setMarkerShape "ICON";
"MU6" setmarkerSize [1,1];
"MU6" setMarkerType "mil_dot";
"MU6" setMarkerText "U6";
if ( fwd_showmarker  == 1 ) then { "MU6" setMarkerAlpha 0.5} else { "MU6" setMarkerAlpha 0};
U6 setpos _posU6;
if ( fwd_trackunit  == 1 ) then 
{ 0 = [] spawn 
	{
	_Marker_U6 = createMarker ["Marker_U6",[0,0]];
	"Marker_U6" setMarkerShape "ICON";
	"Marker_U6" setmarkerSize [0.5,0.5];
	"Marker_U6" setMarkerType "mil_dot";
	"Marker_U6" setMarkerColor "ColorRed";
	"Marker_U6" setMarkerText "U6";
	while {not isnull U6} do {"Marker_U6" setmarkerpos getpos U6; sleep 0.5;};
	};
	0 = [u6] execVM "Scripts\OPFOR\fwd_OPFORintercept2.sqf";
};

// Vehicle 1 spawn settings;
_posV1 = [getmarkerpos "M1",[10,1000],random 360,0,[1,1000]] call SHK_pos;
_MV1 = createMarker ["MV1", _posV1];
"MV1" setMarkerShape "ICON";
"MV1" setmarkerSize [1,1];
"MV1" setMarkerType "mil_dot";
"MV1" setMarkerText "V1";
if ( fwd_showmarker  == 1 ) then { "MV1" setMarkerAlpha 0.5} else { "MV1" setMarkerAlpha 0};
V1 setpos _posV1;
nul = [V1,"M1","nofollow"] execVM "Scripts\fwd_ups.sqf";
if ( fwd_trackunit  == 1 ) then 
	{ 0 = [] spawn 
		{
		_Marker_V1 = createMarker ["Marker_V1",[0,0]];
		"Marker_V1" setMarkerShape "ICON";
		"Marker_V1" setmarkerSize [0.5,0.5];
		"Marker_V1" setMarkerType "mil_dot";
		"Marker_V1" setMarkerColor "ColorRed";
		"Marker_V1" setMarkerText "V1";
		while {not isnull V1} do {"Marker_V1" setmarkerpos getpos V1; sleep 0.5;};
		};
	};

// Vehicle 2 spawn settings;
_posV2 = [getmarkerpos "M1",[10,1000],random 360,0,[1,1000]] call SHK_pos;
_MV2 = createMarker ["MV2", _posV2];
"MV2" setMarkerShape "ICON";
"MV2" setmarkerSize [1,1];
"MV2" setMarkerType "mil_dot";
"MV2" setMarkerText "V2";
if ( fwd_showmarker  == 1 ) then { "MV2" setMarkerAlpha 0.5} else { "MV2" setMarkerAlpha 0};
V2 setpos _posV2;
nul = [V2,"M1","nofollow"] execVM "Scripts\fwd_ups.sqf";
if ( fwd_trackunit  == 1 ) then 
	{ 0 = [] spawn 
		{
		_Marker_V2 = createMarker ["Marker_V2",[0,0]];
		"Marker_V2" setMarkerShape "ICON";
		"Marker_V2" setmarkerSize [0.5,0.5];
		"Marker_V2" setMarkerType "mil_dot";
		"Marker_V2" setMarkerColor "ColorRed";
		"Marker_V2" setMarkerText "V2";
		while {not isnull V2} do {"Marker_V2" setmarkerpos getpos V2; sleep 0.5;};
		};
	};

// Empty game logic spawn settings + activate fillhouse;
GL1 setpos getmarkerpos "M1";
nul = [GL1,2,false,1,15,250,0.3,nil,nil,nil] execVM "Scripts\lv_fillHouse.sqf";

};

_handle8 : Scripts\fwd_objectives.sqf

sleep 20;
if ( fwd_debug  == 1 ) then { hintC "FWD_objectives : launching"};
_marker0 = createMarker ["O1", Startpoint];
"O1" setMarkerShape "ICON";
"O1" setmarkerSize [1,1];
"O1" setMarkerType "mil_objective";
"O1" setMarkerColor "ColorBlack";
"O1" setMarkerAlpha 1;
"O1" setMarkerText "Neutralize OPFOR";
_marker1 = createMarker ["O1a", Startpoint];
"O1a" setMarkerShape "ELLIPSE";
"O1a" setMarkerBrush "BDiagonal";
"O1a" setMarkerColor "ColorOPFOR";
"O1a" setMarkerSize [1000, 1000];
if ( fwd_showmarker  == 1 ) then { "O1a" setMarkerAlpha 0} else { "O1a" setMarkerAlpha 1};
sleep 2;
if ( fwd_debug  == 1 ) then { hintC "FWD_objectives launched"};
sleep 2;
["Task1","Strike : Neutralize OPFOR.","Combat Operation : Seize the Area. Neutralize OPFOR."] call SHK_Taskmaster_add;

if ( fwd_debug  == 1 ) then { random1 = round(random 11);} else { random1 = round(random 100);};
if (random1 < 11) then
{0 = [] execVM "Scripts\OPFOR\FWD_Airpatrol.sqf";} else {if ( fwd_debug  == 1 ) then { hintC "FWD_Airpatrol : not launched"}};

sleep 15;
_trgO1 = createTrigger ["EmptyDetector",Startpoint];
_trgO1 setTriggerArea [500,500,0,false];
_trgO1 setTriggerActivation ["EAST","NOT PRESENT",false];
_trgO1 setTriggerStatements ["this", "['Task1','succeeded'] call SHK_Taskmaster_upd", "hint ''"]; 

_trgO2 = createTrigger ["EmptyDetector",Startpoint];
_trgO2 setTriggerArea [500,500,0,false];
_trgO2 setTriggerActivation ["EAST","NOT PRESENT",false];
_trgO2 setTriggerStatements ["this", "hint ''", "hint ''"];
_trgO2 setTriggerTimeout [30, 30, 30, false ];
_trgO2 setTriggerType "END1";

Or download here (Mega.co.nz).

Sometimes, players stay in pre-setpos position, sometimes, the entire Scripts\OPFOR\fwd_OPFOR.sqf is not working, but the objectives one is launched and the end trigger is activated after the sleep delay. I think it's a bad synchronisation between host and players, but i'm lost.

Do you have any solutions or idea to optimize this or to make it functionnal on a dedicated server? Do you know how i can use the startLoadingScreen / endLoadingScreen with my init.sqf on a dedicated server?

Thank you.

(Oh, i forget. Thank you Farooqaaa, Shuko, Kronzky and spunFIN. Your scripts are awesome.)

Edited by fwouedd
My english is crap.

Share this post


Link to post
Share on other sites

First some general advice: use as few global variables as possible. They are difficult to keep track of, are not a clear and organized way of passing data to other functions, and cause bugs that are very hard to find. Your mission would be much better organized if functions used local variables and took arguments rather than accessing global variables. Obviously, global variables from the editor or debug variables are fine because generally no function will change them; they are just constants. Global variables become even more of an issue in multiplayer when determining which clients have what value in what variable.

To deal with multiplayer issues, I have found that the most organized and effect design is have the server handle everything and only make the clients execute certain functions. This way a multiplayer mission is designed just like a singleplayer mission, but with some uses of BIS_fnc_MP. The mission should then behave exactly the same in the editor as in multiplayer.

I have not spent hours studying your mission and testing. I have looked at the functions you posted and made some changes that follow my above advice. Do not expect my changes to work perfectly; they are just an example of how you could do things differently (and in my opinion better).

The init:

if (!isServer) then {waitUntil {!(isNull player)}};
waituntil {!isnil "bis_fnc_init"};
finishMissionInit;
enableSaving [false, false];

fwd_debug = compileFinal preprocessFileLineNumbers "Scripts\fwd_debug.sqf";
fwd_randomstart_init = compileFinal preprocessFileLineNumbers "Scripts\fwd_randomstart_init.sqf";
fwd_randomtime_init = compileFinal preprocessFileLineNumbers "Scripts\fwd_randomtime_init.sqf";
fwd_randomstart = compileFinal preprocessFileLineNumbers "Scripts\fwd_randomstart.sqf";
fwd_randomtime = compileFinal preprocessFileLineNumbers "Scripts\fwd_randomtime.sqf";
fwd_wait = compileFinal preprocessFileLineNumbers "Scripts\fwd_wait.sqf";
fwd_OPFOR = compileFinal preprocessFileLineNumbers "Scripts\OPFOR\fwd_OPFOR.sqf";
fwd_objectives = compileFinal preprocessFileLineNumbers "Scripts\fwd_objectives.sqf";
call compileFinal preprocessFileLineNumbers "Scripts\fwd_revive.sqf";
call compileFinal preprocessFileLineNumbers "Scripts\shk_pos_init.sqf";
call compileFinal preprocessFileLineNumbers "Scripts\shk_taskmaster.sqf";

if !(isServer) exitWith {};

_missionSectorArray = ["Z1","Z2","Z3","Z4","Z5","Z6","Z7","Z8","Z9","Z10","Z11","Z12","Z13"];
_missionsector = _missionSectorArray select (floor (random count _missionSectorArray));

0 = [1,1,0] call fwd_debug;
0 = [_missionsector] call fwd_randomstart_init;
_weatherArray = [] call fwd_randomtime_init;

0 = [[_missionsector], "fwd_randomstart", true] spawn BIS_fnc_MP;
0 = [(_weatherArray select 0), "fwd_randomtime", true] spawn BIS_fnc_MP;
0 = [(_weatherArray select 1), "fwd_wait", true] spawn BIS_fnc_MP;
0 = [[_missionsector], "fwd_objectives", true] spawn BIS_fnc_MP;

0 = [] call fwd_OPFOR;

The init that you posted is somewhat strange. There is no reason to wait for functions to be done if they do not have sleep commands in them. It would be easier to compile the functions and then use 'call'. Call also returns a value from the function, which I then use as the arguments of the next function. Call also waits for the function to finish executing.

Few changes were made to 'fwd_debug', 'fwd_randomstart_init', 'fwd_OPFOR', and 'fwd_objectives'. I just made 'fwd_randomstart_init' and 'fwd_objectives' accept an argument and use local variables. I also moved the random selection of a marker from 'fwd_randomstart_init' to the init.

fwd_randomtime_init:

private ["_weather", "_rain", "_fog", "_windStr", "_windDir", "_time", "_randomWeather", "_randomWindStr", "_randomWindDir", "_randomFog", "_randomRain"];

switch (paramsArray select 0) do {
   case 1: {_weather = 0;_rain = 0;_fog = 0;_windStr = 1;_windDir = 1;};
   case 2: {_weather = .40;_rain = .40;_fog= 0;_windStr = 2;_windDir = 2;};
   case 3: {_weather = .70;_rain = .70;_fog = .05;_windStr= 3;_windDir = 3;};
   case 4: {_weather = 1;_rain = 1;_fog = .05;_windStr = 4;_windDir = 4;};
   case 5: {_weather = .75;_rain = .10;_fog = .30;_windStr = 1;_windDir = 1;};
   case 6: {_weather = .85;_rain = .20;_fog = .50;_windStr= 0;_windDir = 0;};
   case 7: {
       _randomWeather = 0.2 + ((round (random 5))/10);
       _randomWindStr = (round(random 60)) - 30;
       _randomWindDir = (round(random 60)) - 30;

       if ( _randomWeather > 0.7) then {
           _randomFog =  0.2 - ((round(random 2))/(10));
       } else {
           _randomFog= 0.01;
       };

       if ( _randomWeather > 0.5) then {
           _randomRain =  _randomWeather +((round(random 2))/(10));
       } else {
           _randomRain= 0;
       };

       _weather = _randomWeather;
       _rain = _randomRain;
       _fog = _randomFog;
       _windStr = _randomWindStr;
       _windDir= _randomWindDir;
   };
};

switch (paramsArray select 1) do {
   case 1: {_time = 13;};
   case 2: {_time = 17;};
   case 3: {_time = 23;};
   case 4: {_time = 30;};
   case 5: {_time = 33;};
   case 6: {_time = round(random 24);};
};

[[_time, _weather, _fog],[_rain, _windStr, _windDir]]

In the weather function, there was simply no reason to declare so many global variables, some of which were never used again, when you could make the function return the values that it used to publicVariable.

These next functions are meant to be executed on the client machines (or at least it looks like that to me). I have changed them to be executed by BIS_fnc_MP and accept arguments.

fwd_randomstart:

private ["_startPos"];

_startPos = getMarkerPos (_this select 0);
player setPosATL getMarkerPos "S3";
player setDir ([player, _startPos] call BIS_fnc_dirTo)};

fwd_randomtime:

private ["_time", "_weather", "_fog"];

_time = _this select 0;
_weather = _this select 1;
_fog = _this select 2;

skipTime _time;
1 setOvercast _weather;
1 setFog _fog;

fwd_wait:

private ["_rain", "_windStr", "_windDir"];

_rain = _this select 0;
_windStr = _this select 1;
_windDir = _this select 2;

skipTime 1;
1 setRain _rain;
setWind [_windStr,_windDir,true];

Using BIS_fnc_MP ensures that all clients will execute these functions with arguments determined only by the server. The key is that only the server decided what numbers to use for the time and weather. The clients then just react to that information. There is no chance of them doing anything unexpected.

Share this post


Link to post
Share on other sites

Thank you Zenophon, I will study your advice, study your changes and, I hope, learn a lot. Thanks again.

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  

×