Jump to content
tpw

Simple Breath Fog Script

Recommended Posts

Alright all?

Here's another simple script that just adds foggy breath to a specified unit. This adds a lot of immersion if you're playing on a cold map like Thirsk or Namalsk, especially at night.

Save the script below as you wish. The easiest way to give everyone in your group foggy breath is to put this in your init.sqf:

{nul = [_x, 0.01] execvm "nameofscript.sqf" } foreach units (group player);

For any other unit just put this in their init:

nul = [this, 0.01] execvm "nameofscript.sqf"

0.01 = slightly foggy breath

0.1 = fairly foggy

1 = very dense fog. Use on antarctic maps!

This is a very simple script, I haven't synchronised the breathing rate with the sound of breathing etc. If you like it, good. If you can think of improvements, even better!

Script below

// Foggy breath 20110122

private ["_unit"];
_unit = _this select 0;
_int = _this select 1; //intensity of fog (0 to 1)

while {alive _unit} do {
sleep (2 + random 2); // random time between breaths

_source = "logic" createVehicleLocal (getpos _unit);
_fog = "#particlesource" createVehicleLocal getpos _source;
_fog setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 12, 13,0],
"", 
"Billboard", 
0.5, 
0.5, 
[0,0,0],
[0, 0.2, -0.2], 
1, 1.275,	1, 0.2, 
[0, 0.2,0], 
[[1,1,1, _int], [1,1,1, 0.01], [1,1,1, 0]], 
[1000], 
1, 
0.04, 
"", 
"", 
_source];
_fog setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];
_fog setDropInterval 0.001;

_source attachto [_unit,[0,0.15,0], "neck"]; // get fog to come out of player mouth

sleep 0.5; // 1/2 second exhalation
deletevehicle _source;
}

Edited by tpw

Share this post


Link to post
Share on other sites
Guest

Will this work in multiplayer?

Share this post


Link to post
Share on other sites

Interesting script, I'll check it out for sure. Thanks.

Share this post


Link to post
Share on other sites

Thanks guys, I appreciate the interest!

Share this post


Link to post
Share on other sites

Little error in the RPT:

Error in expression <; 

sleep 0.5; 
deletevehicle _source;
}}>
 Error position: <}>
 Error Missing ;
File C:\Users\Ryan\Documents\ArmA 2 Other Profiles\Animal%20Mother\missions\co@04_Snow_Leopards.ThirskW\foggy_breath.sqf, line 35

Share this post


Link to post
Share on other sites
Little error in the RPT:

Error in expression <; 

sleep 0.5; 
deletevehicle _source;
}}>
 Error position: <}>
 Error Missing ;
File C:\Users\Ryan\Documents\ArmA 2 Other Profiles\Animal%20Mother\missions\co@04_Snow_Leopards.ThirskW\foggy_breath.sqf, line 35

Thanks animal, I'll have a quick look into it.

EDIT:

Doh, just an extra } at the end of the script. I've removed it, you should be right now.

Edited by tpw

Share this post


Link to post
Share on other sites

Hey, actually, it's unnecessary to use wile {} do {} loop because setDropInterval itself is a kinda of loop. You can replace it by

WaitUntil {!alive _unit};
sleep 0.5;
deleteVehicle _Source;

:D

Share this post


Link to post
Share on other sites
This is a very simple script, I haven't synchronised the breathing rate with the sound of breathing etc. If you like it, good. If you can think of improvements, even better!

Maybe someone knows the fatiguee-values and how to read them.

Since the fatigue-value increases your crosshair size..

EDIT: Maybe with this command?

http://community.bistudio.com/wiki/getFatigue_%28VBS2%29

Share this post


Link to post
Share on other sites
Maybe someone knows the fatiguee-values and how to read them.

Since the fatigue-value increases your crosshair size..

EDIT: Maybe with this command?

http://community.bistudio.com/wiki/getFatigue_%28VBS2%29

Excellent idea, I'll have a look into it. Thanks Egosa-U!

Share this post


Link to post
Share on other sites

This is a great idea! Very original!

I'll make a video of it on saturday.

Share this post


Link to post
Share on other sites

Maybe it won't work because of the limitation to VBS 2.

But i've searched the commands-list and found that:

http://community.bistudio.com/wiki/precision

Still can't find anything really useful about the breathingrate/tiredness/weapon-accuracy..

I'll keep looking.

Edit: Furthermore you could combine the breathing-script with the mission-time. Especially when the mission plays from dusk until night, the enabling of Breath Fog would increase the atmosphere.

Edited by Egosa-U

Share this post


Link to post
Share on other sites

I tried now to combine the fog with the mission-time, but haven't got that much experience with sqf-scripting :( .

I tried to define on which times the fog should be dense and when not.

Basically I setup the following times:

From 0am to 3am : dense fog

from 3am to 6am : less dense fog

from 6am to 6pm: nofog

from 6pm to 20pm: less dense fog

and from 20pm to 24pm: dense fog

So i expanded the code with additional parameters, but can't get it to work.

I think it may have something to do with passing the _int parameter.

Additionally, it should continue checking the time to make sure the fog-density is right.

Hoping, someone can help...

Heres the modified code:

/ Foggy breath 20110122
// Save the script below as you wish. The easiest way to give everyone in your group foggy breath is to put this in your init.sqf:
// {nul = [_x, 0, 0.01, 0.1, 0, 3, 6, 18, 20, 24] execvm "fogbreath2.sqf" } foreach units (group player);

// For any other unit just put this in their init:
// nul = [this, 0, 0.01, 0.1, 0, 3, 6, 18, 20, 24] execvm "fogbreath2.sqf"

// 0.01 = slightly foggy breath
// 0.1 = fairly foggy
// 1 = very dense fog. Use on antarctic maps!

private ["_unit"];
_unit = _this select 0;
_intlow = _this select 1;  // low intensity of fog (0 to 1)
_intmid = this select 2;   // medium intensity of fog (0 to 1)
_inthigh = _this select 3; // high intensity of fog (0 to 1) 


_time1 = _this select 4; // time from x am (common: 0 am)
_time2 = _this select 5; // time to x am
_time3 = _this select 6; // time from "without fog"
_time4 = _this select 7; // time to "without fog"
_time5 = _this select 8; // time from x pm
_time6 = _this select 9; // time to x pm (common: 24 pm)

while {alive _unit} do {
If ((daytime > _time1) && (daytime <= _time2)) then {_int = _inthigh};
If ((daytime > _time2) && (daytime <= _time3)) then {_int = _intmid};
If ((daytime > _time3) && (daytime <= _time4)) then {_int = _intlow}; 
If ((daytime > _time4) && (daytime <= _time5)) then {_int = _intmid}; 
If ((daytime > _time5) && (daytime <= _time6)) then {_int = _inthigh};
};


sleep (2 + random 2); // random time between breaths

_source = "logic" createVehicleLocal (getpos _unit);
_fog = "#particlesource" createVehicleLocal getpos _source;
_fog setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 12, 13,0],
"", 
"Billboard", 
0.5, 
0.5, 
[0,0,0],
[0, 0.2, -0.2], 
1, 1.275,	1, 0.2, 
[0, 0.2,0], 
[[1,1,1, _int], [1,1,1, 0.01], [1,1,1, 0]], 
[1000], 
1, 
0.04, 
"", 
"", 
_source];
_fog setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];
_fog setDropInterval 0.001;

_source attachto [_unit,[0,0.15,0], "neck"]; // get fog to come out of player mouth
WaitUntil {!alive _unit};
sleep 0.5; // 1/2 second exhalation
deletevehicle _source;

Share this post


Link to post
Share on other sites

Hi egosa-u. I'm not in front of my arma box but looking at your code I can't really see why it shouldn't work. I actually combine my fog script with another one which determines the angle of the sun from the horizon. When the sun is below horizon = foggy breath. I will post this when I get home.

I tried now to combine the fog with the mission-time, but haven't got that much experience with sqf-scripting :( .

I tried to define on which times the fog should be dense and when not.

Basically I setup the following times:

From 0am to 3am : dense fog

from 3am to 6am : less dense fog

from 6am to 6pm: nofog

from 6pm to 20pm: less dense fog

and from 20pm to 24pm: dense fog

So i expanded the code with additional parameters, but can't get it to work.

I think it may have something to do with passing the _int parameter.

Additionally, it should continue checking the time to make sure the fog-density is right.

Hoping, someone can help...

Heres the modified code:

/ Foggy breath 20110122
// Save the script below as you wish. The easiest way to give everyone in your group foggy breath is to put this in your init.sqf:
// {nul = [_x, 0, 0.01, 0.1, 0, 3, 6, 18, 20, 24] execvm "fogbreath2.sqf" } foreach units (group player);

// For any other unit just put this in their init:
// nul = [this, 0, 0.01, 0.1, 0, 3, 6, 18, 20, 24] execvm "fogbreath2.sqf"

// 0.01 = slightly foggy breath
// 0.1 = fairly foggy
// 1 = very dense fog. Use on antarctic maps!

private ["_unit"];
_unit = _this select 0;
_intlow = _this select 1;  // low intensity of fog (0 to 1)
_intmid = this select 2;   // medium intensity of fog (0 to 1)
_inthigh = _this select 3; // high intensity of fog (0 to 1) 


_time1 = _this select 4; // time from x am (common: 0 am)
_time2 = _this select 5; // time to x am
_time3 = _this select 6; // time from "without fog"
_time4 = _this select 7; // time to "without fog"
_time5 = _this select 8; // time from x pm
_time6 = _this select 9; // time to x pm (common: 24 pm)

while {alive _unit} do {
If ((daytime > _time1) && (daytime <= _time2)) then {_int = _inthigh};
If ((daytime > _time2) && (daytime <= _time3)) then {_int = _intmid};
If ((daytime > _time3) && (daytime <= _time4)) then {_int = _intlow}; 
If ((daytime > _time4) && (daytime <= _time5)) then {_int = _intmid}; 
If ((daytime > _time5) && (daytime <= _time6)) then {_int = _inthigh};
};


sleep (2 + random 2); // random time between breaths

_source = "logic" createVehicleLocal (getpos _unit);
_fog = "#particlesource" createVehicleLocal getpos _source;
_fog setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 12, 13,0],
"", 
"Billboard", 
0.5, 
0.5, 
[0,0,0],
[0, 0.2, -0.2], 
1, 1.275,	1, 0.2, 
[0, 0.2,0], 
[[1,1,1, _int], [1,1,1, 0.01], [1,1,1, 0]], 
[1000], 
1, 
0.04, 
"", 
"", 
_source];
_fog setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];
_fog setDropInterval 0.001;

_source attachto [_unit,[0,0.15,0], "neck"]; // get fog to come out of player mouth
WaitUntil {!alive _unit};
sleep 0.5; // 1/2 second exhalation
deletevehicle _source;

Share this post


Link to post
Share on other sites
Hi egosa-u. I'm not in front of my arma box but looking at your code I can't really see why it shouldn't work. I actually combine my fog script with another one which determines the angle of the sun from the horizon. When the sun is below horizon = foggy breath. I will post this when I get home.

That would be great! I haven't thought of the possibility to go along with the sun.

Share this post


Link to post
Share on other sites
That would be great! I haven't thought of the possibility to go along with the sun.

OK, here's the weay I do it. The sun angle stuff is adapted from some code that CarlGustaffa gave me, so props to him!

Let me know if you have probs with it.

// Determine the angle of the sun (ie is it dark or not), adapted from CarlGustaffa 
[] spawn {while {alive player} do {
private ["_lat", "_day", "_hour", "_angle", "_isday"]; //Not 100% correct to BIS own code, but it does the trick.
_lat = -1 * getNumber(configFile >> "CfgWorlds" >> worldName >> "latitude"); //Arma latitude is negated for some odd reason.
_day = 360 * (dateToNumber date); //Convert current day to 360 for trigonometric calculations.
_hour = (daytime / 24) * 360; //Convert current hours to 360 for trigonometric calculations.
sunangle = ((12 * cos(_day) - 78) * cos(_lat) * cos(_hour)) - (24 * sin(_lat) * cos(_day)); 
//update every 5 minutes
sleep 300; 
};
};

private ["_unit"];
_unit = _this select 0;
_int = _this select 1; //intensity of fog (0 to 1)

while {alive _unit} do {
if (sunangle < 0) then {  // only fog breath if sun is below horizon
sleep (2 + random 2); // random time between breaths

_source = "logic" createVehicleLocal (getpos _unit);
_fog = "#particlesource" createVehicleLocal getpos _source;
_fog setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 12, 13,0],
"", 
"Billboard", 
0.5, 
0.5, 
[0,0,0],
[0, 0.2, -0.2], 
1, 1.275,	1, 0.2, 
[0, 0.2,0], 
[[1,1,1, _int], [1,1,1, 0.01], [1,1,1, 0]], 
[1000], 
1, 
0.04, 
"", 
"", 
_source];
_fog setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];
_fog setDropInterval 0.001;

_source attachto [_unit,[0,0.15,0], "neck"]; // get fog to come out of player mouth

sleep 0.5; // 1/2 second exhalation
deletevehicle _source;
}}

Share this post


Link to post
Share on other sites

Sorry to revive this thread, but how do you set the breath (fog) to dissapear faster?

In my mission I have:

setWind [0,10, true];

And the breath looks like it's ejecting out of the player at maximum speed in a straight line. :rolleyes:

Edit:

Hah, nevermind. Figured it out by counting how long the fog was alive for and turned out to be ~2. So I looked for something that equaled "2" and it's here:

_fog setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];

Just change the 2 to something like:

_fog setParticleRandom [[color="Red"].1[/color], [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];

Edited by Semedar

Share this post


Link to post
Share on other sites

Glad you figured it out Semedar, because I can't remember how I did it! Also, glad that someone is actually using the script!

Share this post


Link to post
Share on other sites

We're making use of it in

:D Though it might not be too visible in that video. Great subtle effect that definitely adds a lot to the atmosphere ingame!

Share this post


Link to post
Share on other sites
We're making use of it in
:D Though it might not be too visible in that video. Great subtle effect that definitely adds a lot to the atmosphere ingame!

Thanks PacUK, I appreciate the feedback. It's great being able to contribute to the community even with simple little things.

Share this post


Link to post
Share on other sites

Hi

I really like this script and I have just put into one of my missions. The problem is however that we need "INSTANT" respawn but after a player respawns foggy breath is gone. The script is referred to in init.sqf. I have also tried to put it in the init field of the playable units but the script is only started once.

Do you have any idea how to solve this?

Thanks in advance

Share this post


Link to post
Share on other sites

Hi b1944

I never use MP so have never had to think about this. There is probably a way to specify the script in the init field of a newly spawned unit, I just don't know enough about it to help you. I'm sure one of the other scripting rocket scientists on this forum can help you!

Share this post


Link to post
Share on other sites

you could try adding this EH to the players init

player addEventHandler ["killed", {_this execVM "playerKilled.sqf"}];

playerKilled.sqf

_body = _this select 0;

_string = format["%1",_body];

_obj = call compile format ["%1", _string];

_timeout = (time + 1);

while {(!(alive _obj) && (time > _timeout))} do

{

_obj = call compile format ["%1", _string];

_timeout = (time + 1);

};

_nil = [_obj, 0.01] execvm "nameofscript.sqf"

Share this post


Link to post
Share on other sites

Hey guys!

I was kicking around making something like this for one of my missions and I decided to go for it. This script adds breath condensation to all units. The particles are created locally on each client so there is very little network traffic. I've included a version that has ACRE functionality so you can see condensation when people are talking. Should be 100% JIP, respawn compatible (also dead people don't breath ;) Although I didn't test it with respawn). I think I'll throw in ACE stamina at some point when I feel like it but it shouldn't be too hard to add if your up for it. Major props to Nou for some help with the per frame event handler.

You can change the drop interval ( _fog setDropInterval (0.01-random(0.005)); ) and particle color ( [[1,1,1, (.01+random(.03))], [1,1,1, 0.01], [1,1,1, 0]], ) to get the effect you want

To run add something like this to the init.sqf

if (!isDedicated) then
{
    	[] execVM "scripts\breath.sqf";	
};

ACRE Version:

//Adds Condensation to Units (ACRE)
//By Falcon (Original by tpw)
//Last Updated 23.01.2012

private ["_unit","_int","_nextTime", "_source", "_mylogic", "_fog"];

sleep 5;
my_breath_func = {
{
	_unit = _x;
	if(alive _unit) then {
		_nextTime = _unit getVariable ["myNextBreathTime", -1];
		if(_nextTime == -1) then {
			_unit setVariable ["myNextBreathTime", diag_tickTime + (1+random(3))];
			_source = "logic" createVehicleLocal (getpos _unit);
		    _unit setVariable ["myBreathingParticleLogic", _source];
			if(_unit == player) then {_source attachto [_unit,[0,0.1,.04], "neck"];} else {_source attachto [_unit,[0,0.05,-0.08], "pilot"];};
			_unit setVariable ["myBreathingParticleSource", nil];
		};
		_myParticleSource = _unit getVariable ["myBreathingParticleSource", nil];
		if(diag_tickTime >= _nextTime || (([_unit] call acre_api_fnc_isSpeaking) && isNil "_myParticleSource")) then {
			if (isNil "_myParticleSource") then {
				_unit setVariable ["myNextBreathTime", diag_tickTime + 0.5];
				_mylogic = _unit getVariable "myBreathingParticleLogic";
				_fog = "#particlesource" createVehicleLocal (getpos _mylogic);
				_fog setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 12, 13,0],
					"", 
					"Billboard", 
					0.5, 
					0.5, 
					[0,0,0],
					[0, 0.0, -0.3], 
					1, 1.275,    1, 0.2, 
					[0, 0.2,0], 
					[[1,1,1, (.01+random(.03))], [1,1,1, 0.01], [1,1,1, 0]], //Change  (.01+random(.03)) for different effect 0 (less) 1 (more)
					[1000], 
					1, 
					0.04, 
					"", 
					"", 
					_mylogic];
					_fog setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];
					_fog setDropInterval (0.01-random(0.005)); //change drop interval for particle density 0.001 (most dense) -> .999 (least dense)

					_unit setVariable ["myBreathingParticleSource", _fog];
				} else {
				if(!([_unit] call acre_api_fnc_isSpeaking)) then {
					_unit setVariable ["myNextBreathTime", diag_tickTime + (2+random(3))];
					deletevehicle (_unit getVariable "myBreathingParticleSource");
					_unit setVariable ["myBreathingParticleSource", nil];
					};
				};				
		};
	} else {
			_unit setVariable ["myNextBreathTime", -1]; 
			deletevehicle (_unit getVariable "myBreathingParticleLogic");
			deletevehicle (_unit getVariable "myBreathingParticleSource");
		};
} forEach allUnits;
};

[my_breath_func, 0.1] call cba_fnc_addPerFrameHandler;

Non-ACRE Version:

//Adds Condensation to Units (Non-ACRE)
//By Falcon (Original by tpw)
//Last Updated 23.01.2012

private ["_unit","_int","_nextTime", "_source", "_mylogic", "_fog"];

sleep 5;
my_breath_func = {
{
	_unit = _x;
	if(alive _unit) then {
		_nextTime = _unit getVariable ["myNextBreathTime", -1];
		if(_nextTime == -1) then {
			_unit setVariable ["myNextBreathTime", diag_tickTime + (1+random(3))];
			_source = "logic" createVehicleLocal (getpos _unit);
		    _unit setVariable ["myBreathingParticleLogic", _source];
			if(_unit == player) then {_source attachto [_unit,[0,0.1,.04], "neck"];} else {_source attachto [_unit,[0,0.05,-0.08], "pilot"];};
			_unit setVariable ["myBreathingParticleSource", nil];
		};
		_myParticleSource = _unit getVariable ["myBreathingParticleSource", nil];
		if(diag_tickTime >= _nextTime) then {
			if (isNil "_myParticleSource") then {
				_unit setVariable ["myNextBreathTime", diag_tickTime + 0.5];
				_mylogic = _unit getVariable "myBreathingParticleLogic";
				_fog = "#particlesource" createVehicleLocal (getpos _mylogic);
				_fog setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 12, 13,0],
					"", 
					"Billboard", 
					0.5, 
					0.5, 
					[0,0,0],
					[0, 0.0, -0.3], 
					1, 1.275,    1, 0.2, 
					[0, 0.2,0], 
					[[1,1,1, (.01+random(.03))], [1,1,1, 0.01], [1,1,1, 0]], //Change  (.01+random(.03)) for different effect 0 (less) 1 (more)
					[1000], 
					1, 
					0.04, 
					"", 
					"", 
					_mylogic];
					_fog setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];
					_fog setDropInterval (0.01-random(0.005)); //change drop interval for particle density 0.001 (most dense) -> .999 (least dense)

					_unit setVariable ["myBreathingParticleSource", _fog];
				} else {
				        _unit setVariable ["myNextBreathTime", diag_tickTime + (2+random(3))];
					deletevehicle (_unit getVariable "myBreathingParticleSource");
					_unit setVariable ["myBreathingParticleSource", nil];
				};				
		};
	} else {
			_unit setVariable ["myNextBreathTime", -1]; 
			deletevehicle (_unit getVariable "myBreathingParticleLogic");
			deletevehicle (_unit getVariable "myBreathingParticleSource");
		};
} forEach allUnits;
};

[my_breath_func, 0.1] call cba_fnc_addPerFrameHandler;

-Falcon

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

×