Jump to content

Adding random snow


AceOfSpades

Recommended Posts

Update.

_snowrun = true;
snow = nil;
 
while {_snowrun} do {
        If (isServer) then {
        snowchance = random 100;
        publicvariable "snowchance";
        };
        if (snowchance > 75) then {
                if (isNil "snow") then {
                        snow = [] execvm "custom\spawn_snow.sqf";
                };
        }
        else {
                if (!isNil "snow") then {
                        terminate snow;
                        snow = nil;
                        sleep 20;
                        setviewdistance 1600;
                        0 setfog 0.3;
                        0 setovercast 0.6;
                };
        };
sleep 900;
};
Link to comment
Share on other sites

Yeah I mean you let the whole snow.sqf script run on the server (in the init.sqf just start it inside the "if (isServer)" block.. and it will start on the server) and change it so something like this:

_snowrun = true;
letItSnow = false; // public variable
 
while {_snowrun} do {
        snowchance = random 100;
        if (snowchance > 75) then {
                if (!letItSnow) then {
                      letItSnow = true;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        }
        else {
                if (letItSnow) then {
                      letItSnow = false;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        };
sleep 900;
}; 

Do not start the snow on the server that will do nothing but draining performance on the server lol

Just send it to the clients they start the script then (or terminate it)

You could remove the check for "if (letItSnow) then {" and let the clients do it, this is just the modified version of your client script so I dont confuse you even more ^^

 

You are doing some weird stuff in your version  :D

 

Edit: on the client you can then use "addPublicVariableEventHandler" (http://community.bistudio.com/wiki/addPublicVariableEventHandler) to listen to the "letItSnow" variable:

_snow = nil;
"letItSnow" addPublicVariableEventHandler {
    _letItSnow = _this select 1; // variable value send from the server
​	if (_letItSnow) then {
		_snow = [] execvm "custom\spawn_snow.sqf";
	} else {
		terminate _snow;
		_snow = nil;
		sleep 20;
		setviewdistance 1600;
		0 setfog 0.3;
		0 setovercast 0.6;
	};
};

Edit 2: changed client code to show how it can be done.

Edited by Axe Cop
Link to comment
Share on other sites

Yeah I mean you let the whole snow.sqf script run on the server (in the init.sqf just start it inside the "if (isServer)" block.. and it will start on the server) and change it so something like this:

_snowrun = true;
letItSnow = false; // public variable
 
while {_snowrun} do {
        snowchance = random 100;
        if (snowchance > 75) then {
                if (!letItSnow) then {
                      letItSnow = true;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        }
        else {
                if (letItSnow) then {
                      letItSnow = false;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        };
sleep 900;
}; 

Do not start the snow on the server that will do nothing but draining performance on the server lol

Just send it to the clients they start the script then (or terminate it)

You could remove the check for "if (letItSnow) then {" and let the clients do it, this is just the modified version of your client script so I dont confuse you even more ^^

 

You are doing some weird stuff in your version  :D

 

So if I am getting this right. You are saying that I create a seperate server and client file. The server file looks like the one above. And the client script only awaits the outcome (publicvariables) of the server script?

 

So in the init.sqf

 

if (isServer) then{

[] execvm "snow_server.sqf";

};

 

if (!isServer) then{

[] execvm "snow_client.sqf";

};

Link to comment
Share on other sites

exactly, thats how I would do it, just try that I didn't test anything just wrote the code here in teh froums :D

It's not that easy to snyc this random stuff between all clients, but at least it is pretty simple to send values to all clients in arma.. try that in any other programming language thats fun, not :D

Link to comment
Share on other sites

exactly, thats how I would do it, just try that I didn't test anything just wrote the code here in teh froums :D

It's not that easy to snyc this random stuff between all clients, but at least it is pretty simple to send values to all clients in arma.. try that in any other programming language thats fun, not :D

 

Will test it out :). Also I am adding a blizzard sound whilst snowing.

Link to comment
Share on other sites

You could of couse put the code in only 1 file and then seperate it with if(isServer) in that file, its the same but would make it easier to install the script for admins? Keep in mind that it wont work if the line is at the wrong place in the init.sqf ... :)

 

What would be the right place in the init.sqf file?

Link to comment
Share on other sites

somewhere outside of every server or client check, so at the bottom of the init.sqf I would say ;)

 

Ah yes :). That is where is it now. Also shouldn't the client script run a whole loop?

_snowrun = true;
letItSnow = false; // public variable
 
if (isServer) then {
while {_snowrun} do {
        snowchance = random 100;
        if (snowchance > 75) then {
                if (!letItSnow) then {
                      letItSnow = true;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        }
        else {
                if (letItSnow) then {
                      letItSnow = false;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        };
sleep 900;
};
};

if (!isServer) then { 
_snow = nil;
while {_snowrun} do {
"letItSnow" addPublicVariableEventHandler {
    _letItSnow = _this select 1; // variable value send from the server
​	if (_letItSnow) then {
		_snow = [] execvm "custom\spawn_snow.sqf";
	} else {
		terminate _snow;
		_snow = nil;
		sleep 20;
		setviewdistance 1600;
		0 setfog 0.3;
		0 setovercast 0.6;
      };
    };
  };
  sleep 900;
};
Link to comment
Share on other sites

No better remove the while loop "while {_snowrun} do {" at the client side!!

The server triggers the execution of everything inside: "letItSnow" addPublicVariableEventHandler { ... };

Which means every time the server executes "publicVariable "letItSnow";" the client will run that code!! no loop needed that would produce only bugs, the server is running THAT the loop already..

 

Event handling is a known concept of many programming languages, maybe not that easy to understand if you have no background knowledge about that, maybe this article helps understand it a little: http://en.wikipedia.org/wiki/Event_(computing)

Link to comment
Share on other sites

No better remove the while loop "while {_snowrun} do {" at the client side!!

The server triggers the execution of everything inside: "letItSnow" addPublicVariableEventHandler { ... };

Which means every time the server executes "publicVariable "letItSnow";" the client will run that code!! no loop needed that would produce only bugs, the server is running THAT the loop already..

 

Event handling is a known concept of many programming languages, maybe not that easy to understand if you have no background knowledge about that, maybe this article helps understand it a little: http://en.wikipedia.org/wiki/Event_(computing)

It is not working unfortunately. On the serverside there are no errors on the log. But on the client side I found this:

 

Error in expression <dler {
_letItSnow = _this select 1; 
};
if (_letItSnow) then {
_snow = [] ex>
  Error position: <​ if (_letItSnow) then {
_snow = [] ex>
  Error Invalid number in expression
File mpmissions\__CUR_MP.Lingor\custom\snow_client.sqf, line 8
Error in expression <dler {
_letItSnow = _this select 1; 
};
if (_letItSnow) then {
_snow = [] ex>
  Error position: <​ if (_letItSnow) then {
_snow = [] ex>
  Error Invalid number in expression
File mpmissions\__CUR_MP.Lingor\custom\snow_client.sqf, line 8
Link to comment
Share on other sites

what is snow_client.sqf, line 8? :)

 

Ah made a mistake, reading. This is the current error:

 

Error in expression <Handler {
_letItSnow = _this select 1; 
if (_letItSnow) then {
_snow = [] ex>
  Error position: <​ if (_letItSnow) then {
_snow = [] ex>
  Error Invalid number in expression
File mpmissions\__CUR_MP.Lingor\custom\snow_server.sqf, line 28
Error in expression <Handler {
_letItSnow = _this select 1; 
if (_letItSnow) then {
_snow = [] ex>
  Error position: <​ if (_letItSnow) then {
_snow = [] ex>
  Error Invalid number in expression
File mpmissions\__CUR_MP.Lingor\custom\snow_server.sqf, line 28
 
And on line 28 of this file there is:
 
if (_letItSnow) then {
 
This is the script. Exected in the init.sqf by:
execvm "custom\snow_server.sqf";
 
if (isServer) then {

_snowrun = true;
letItSnow = false; // public variable

while {_snowrun} do {
        snowchance = random 100;
        if (snowchance > 10) then {
                if (!letItSnow) then {
                      letItSnow = true;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        }
        else {
                if (letItSnow) then {
                      letItSnow = false;
		      publicVariable "letItSnow"; // sends variable to all clients
                };
        };
sleep 20;
};
};

if (!isServer) then { 
"letItSnow" addPublicVariableEventHandler {
    _letItSnow = _this select 1; // variable value send from the server
​	if (_letItSnow) then {
		_snow = [] execvm "custom\spawn_snow.sqf";
	} else {
		terminate _snow;
		sleep 20;
		setviewdistance 1600;
		0 setfog 0.3;
		0 setovercast 0.6;
      };
    };
};
Link to comment
Share on other sites

Ok that is weird I don't see any error there, but your code is formatted like shit, sorry had to say it learn proper code indentation then it's far easier to read! lol

Anyway the doc https://community.bistudio.com/wiki/addPublicVariableEventHandler says:

_this select 1: Anything - broadcast variable value 

So "_this select 1" is just the value of the public variable, I have no idea why it is expecting a number in your script, maybe just dump the value to the log file to see what actually is in there (should be boolean, true or false):

ALSO "_snow" is never initialized thats an error in the script, i change it for you...

if (isServer) then {
	_snowrun = true;
	letItSnow = false; // public variable

	while {_snowrun} do {
		snowchance = random 100;
		if (snowchance > 10) then {
			if (!letItSnow) then {
				letItSnow = true;
				publicVariable "letItSnow"; // sends variable to all clients
			};
		}
		else {
			if (letItSnow) then {
				letItSnow = false;
				publicVariable "letItSnow"; // sends variable to all clients
			};
		};
		sleep 20;
	};
};

if (!isDedicated) then { //change it to !isDedicated like in the init.sqf, maybe better but should not matter for DayZ servers since you can't host them in the game!?
	_snow = nil;
	"letItSnow" addPublicVariableEventHandler {
		_letItSnow = _this select 1; // variable value send from the server
		diag_log format ["SNOW_DEBUG _letItSnow = %1, _letItSnow];
	​	if (_letItSnow) then {
			_snow = [] execvm "custom\spawn_snow.sqf";
		} else {
			terminate _snow;
			sleep 20;
			setviewdistance 1600;
			0 setfog 0.3;
			0 setovercast 0.6;
		};
	};
};

Check you client log for a line with "SNOW_DEBUG _letItSnow". You can find the file at "C:\Users\YOURNAME\AppData\Local\ArmA 2 OA\arma2oa.RPT" maybe delete it before you start the game so its clean. :)

Link to comment
Share on other sites

Ok that is weird I don't see any error there, but your code is formatted like shit, sorry had to say it learn proper code indentation then it's far easier to read! lol

Anyway the doc https://community.bistudio.com/wiki/addPublicVariableEventHandler says:

_this select 1: Anything - broadcast variable value 

So "_this select 1" is just the value of the public variable, I have no idea why it is expecting a number in your script, maybe just dump the value to the log file to see what actually is in there (should be boolean, true or false):

ALSO "_snow" is never initialized thats an error in the script, i change it for you...

 

Check you client log for a line with "SNOW_DEBUG _letItSnow". You can find the file at "C:\Users\YOURNAME\AppData\Local\ArmA 2 OA\arma2oa.RPT" maybe delete it before you start the game so its clean. :)

Thank you!

I just ran in and there is no error anymore. The clear is clear about the snow script. There is no snow effect on the server. So something has to wrong somewhere. Since there is no SNOW_DEBUG message, I think it does not get executed.

Link to comment
Share on other sites

Thank you!

I just ran in and there is no error anymore. The clear is clear about the snow script. There is no snow effect on the server. So something has to wrong somewhere. Since there is no SNOW_DEBUG message, I think it does not get executed.

That is one of the issues of ArmA scripting, very hard to debug and find the logic errors in my opinion, you can't just quickly see the values of variables while you execute the script, just show it in game or log to the report file that is it! :/

I was trying to get some debug tools running, but couln't get any to work with Epoch, I've tested most of these mentioned here: http://community.bistudio.com/wiki/Debugging_Techniques#Arma_2 not much choice.. I would love at least DevCon to run code on the fly ingame and watch variables and not always have to change the script, restart the server wait 2 minutes and try again.. that thats really annonying and with scripts getting more complex takes up most of the time and not developing the code! :D

 

I would suggest you use the squint syntax checker before starting the server, it detects most errors and has some fixes for those, but it also runs an old version of the ArmA functions it seems since it shows errors where no are, that might be more confusing in some situations :p (e.g. _object getVarible ["foo", 0] is not known by squint but often used in Epoch)

Link to comment
Share on other sites

Just shared one of my debugging tools: http://dayzepoch.com/forum/index.php?/topic/3850-client-side-player-logging-to-server-log/

 

I would love to get that devcon working, restarting servers is the biggest pain for me when testing. I believe, in the early days of arma, that the PBOs weren't locked, would make reloading a mission a lot easier..

Link to comment
Share on other sites

  • 4 weeks later...

Untested:

if (isServer) then {
	_snowrun = true;
	letItSnow = false; // public variable
 
	while {_snowrun} do {
		snowchance = random 100;
		if (snowchance > 10) then {
			if (!letItSnow) then {
				letItSnow = true;
				publicVariable "letItSnow"; // sends variable to all clients
			};
		}
		else {
			if (letItSnow) then {
				letItSnow = false;
				publicVariable "letItSnow"; // sends variable to all clients
			};
		};
		sleep 300;
	};
};
 
if (!is_Dedicated) then { //change it to !isDedicated like in the init.sqf, maybe better but should not matter for DayZ servers since you can't host them in the game!?
	_snow = nil;
	"letItSnow" addPublicVariableEventHandler {
		_letItSnow = _this select 1; // variable value send from the server
		diag_log format ["SNOW_DEBUG _letItSnow = %1", _letItSnow];
	​	if (_letItSnow) then {
			_snow =  "xmas\effects.sqf";
		} else {
			terminate _snow;
			sleep 300;
			setviewdistance 800;
			0 setfog 0.3;
			0 setovercast 0.6;
		};
	};
};

Might have to make an exception for the pubV (!"letItSnow" ?)
Il ltry to test it later today

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×
×
  • Create New...