Jump to content
Sign in to follow this  
PurpleDrain

Run script serverside and broadcast array to clients

Recommended Posts

Hello!

I am trying to make my randomizer script function in multiplayer, but I have not yet been successful in doing so... I have tried make it work with publicVariable in both the init.sqf and the script itself. It works fine both in multiplayer and singleplayer when I am alone but when 2 or more players are present it doesn't work.

I have also tried executing it in-game with the same method as in the init.sqf.

So my question to you all is how I can successfully run this server-side and broadcast the updated array to the clients?

Any help is greatly appreciated.

Note: I haven't fully cleaned up the code of old stuff, so if you see something that isn't used... It's because of that. It might also include faults and/or ineffective ways of doing things, but I am still just a beginner. :P

init.sqf:

ranarr = [0, 0, 0, 0];
publicVariable "ranarr";


if (isServer) then
{
ran = [2, 1] execVM "randomizer_local.sqf";
publicVariable "ranarr";
}

This is the code itself:

_times = _this select 0; // First parameter
_val = _this select 1; // Second parameter
_arrcount = count ranarr;
_i = 0;
_raninit = floor(random _arrcount); // one inital value to avoid nil value
_tmp = []; // temporary array for random values
_case = "gen"; // stage controller
_con = 1; // loop variable
_checktmp = [99];
_checkcount = 1;
// ranarr set [_raninit, _val];

while {_con == 1} do
{
switch (_case) do
{
	case "gen": // generate and check numbers for duplicates
	{
		while {_i < _times} do
		{
			_ran = floor(random _arrcount); // select random value
			{
				if (_ran == _x) then
				{
					while {_ran == _x} do
					{
						_ran = floor(random _arrcount);
					};
				};
			} forEach _checktmp;
			_tmp set [_i, _ran];
			_checktmp set [_checkcount, _ran];
			_i = _i + 1;
			_checkcount = _checkcount + 1;
		};
		_case = "check";
	};
	case "check":
	{
		{
			ranarr set [_x, _val];
		} forEach _tmp;
		publicVariable "ranarr"; // Broadcast updated array to clients.
		_con = 0;
	};
};
};

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  

×