Jump to content

Sign in to follow this  
tpw

TPW HOUSELIGHTS - automatic house light addon

Recommended Posts

Incredibly simple, yet adds such atmosphere. Highly appreciated, thanks!

Share this post


Link to post
Share on other sites

Great work tpw! Love this addition to the game. Thank you.

This would really benefit from a userconfig file with tweaks for color, brightness and distance.

I know i know, use the script version. ;)

Share this post


Link to post
Share on other sites
  Alex72 said:
Great work tpw! Love this addition to the game. Thank you.

This would really benefit from a userconfig file with tweaks for color, brightness and distance.

I know i know, use the script version. ;)

Actually the way the PBO is set up (thanks to Das Attorney) enables straightforward reading of an external userconfig. I'll have a crack at it for you.

---------- Post added at 09:59 ---------- Previous post was at 08:11 ----------

OK Alex72, I'm as good as my word. Here's a version that you can configure via a hpp file in userconfig. The hpp is well commented and easy to understand.

http://www.gamefront.com/files/21707245/TPW_HOUSELIGHTS_101.zip

Please try it out and if it's OK I'll "officially" release it on the 1st post and via Armaholic.

Share this post


Link to post
Share on other sites

Too late! As well as the configuration ability, I've also made the system delete lights once a player moves from the area. First post has been updated accordingly.

Share this post


Link to post
Share on other sites

Check this script in pvp cqb :D :D :D :D!!!

broke all pvp sense, must be improved, maby need add timers for switching lights

Propose: make lights switching up randomly

Share this post


Link to post
Share on other sites
  J-Guid said:
Check this script in pvp cqb :D :D :D :D!!!

broke all pvp sense, must be improved, maby need add timers for switching lights

Propose: make lights switching up randomly

Sorry J-Guid, I'm not really sure what you are actually referring to when you say "broke all PVP sense". If you can give me a better description then I can give you a fix that I don't have to guess.

Share this post


Link to post
Share on other sites

nice addon :thumb: takistan buildings look so much better with this

while testing it i noticed that sometimes buildings would switch light on when very close to them (10m)

i also thought it might be better if just a few random buildings would have lights and not all, its a bit weird when u walk through a town and all buildings have lights when u r close but when u move away a the town is completely dark

Share this post


Link to post
Share on other sites

Great effect with simple code - best thing imaginable in scripting. Lately tested many illumination codes for magick effects, and noticed, that unfortunatelly, if you want to see light from bigger distance, you must to make it brighter. Often much brighter. Light of given brightness seems to disappear at given distance rapidly, not smoothly (?). For used here levels of brightness - rather small chance to see illuminated city from distant position. If I'm not mistaken, of course. Range of view in video options probably will affect this.

Share this post


Link to post
Share on other sites

Basing on the original code by the OP, I have modified the script to have persistent lights.

It is to be executed with the parameters:

_handle = [objectname,radius,percentage] execVM "houselights.sqf";

1. central object on the map which the lights are created around (can be a logic or empty helipad)

2. radius around the central object

3. percentage of houses in the circle which have lights

In this example 75% of the houses in a radius of 500 meters around "logic1" will have lights:

_handle = [logic1,500,75] execVM "houselights.sqf";

As Rydygier said, the lights disappear too suddenly when you exceed a certain distance to them (around 30m). On the other hand, when you increase their brightness, they are too bright and illuminate their environment like flak/AA searchlights. I've mainly tested in with [center,500,90] in Zargabad with "center" a bit left to the mosque (Zargabad is a really nice town).

if !(isServer) then { exit };

_center = position (_this select 0);
_radius = _this select 1;
_chance = _this select 2;

if (_chance <= 0) then { exit };

_houses     = [];
_brightness = 64;
_red        = 255;
_green      = 127; 
_blue       = 24;
_br         = (_brightness / 255) * 0.1;

_r   = _red /255;
_g   = _green /255;
_b   = _blue /255;
_col = [_r,_g,_b];

_allhouses = nearestObjects [_center, ["House"], _radius];
{ if (random(100) <= _chance) then { _houses = _houses + [_x] } } forEach _allhouses;

if ((count _allhouses) == 0) then { exit };

{ _light = "#lightpoint" createVehicle (getpos _x); _light setLightBrightness _br; _light setLightColor _col; _light lightAttachObject [_x, [random 2,random 2,1]];} forEach _houses;

exit;

There is another problem. The iskindof-definition "House" encloses also the doors of stone walls. Maybe it could be solved by http://community.bistudio.com/wiki/ArmA_2:_CfgVehicles and this code (I'm too lazy right now):

_allhouses = nearestObjects [_center, ["House"], _radius];
_exclude = ["name1","name2"];
{ if ((random(100) <= _chance) and !(typeof _x in _exclude)) then { _houses = _houses + [_x] } } forEach _allhouses;

Edited by RogueTrooper

Share this post


Link to post
Share on other sites

Hi guys, thanks so much for all the suggestions and feedback and code - that's exactly what I'd hoped would happen when I released this.

RunForrest: What you're seeing is an engine limitation, where the engine can only display a fixed number of light sources. So as you move around, some flick on and off. I am working on implementing a random building function so that only a user defined percentage of buildings will light up.

Rydygier: Thanks. I pride myself on writing simple code to achieve simple things! You've identified the other engine limitation which is the fact that lights don't really fade according to the inverse square law. There's not much I can really do that won't look weird. I could implement code that changed light brightness the further the player was, but distant houses would end up looking like they were lit by a nuclear explosion!

RogueTrooper: I'm glad my code inspired you to write your own implementation. Yes, the "House" object also includes things like walls, wells, towers etc. However many of these things only have a single building position (ie non-enterable). That's why there's code in my script to identify those buildings with multiple building positions, which then excludes walls and wells etc.

The next release will contain the following:

  • Percentage houses lit - user can specify what percentage of houses to be lit up
  • Randomised brightness - user can select minimum and maximum light brightness values
  • Randomised colours - will randomly assign either warm yellow, white or blue/white to each

Rydygier kindly sent me some code to do the above things, but I had already almost completed my own implementation. He did however also send me some beautiful code to make the light sources flicker like candles or lanterns. So I will include this so that

  • A user defined percentage of light sources will flicker

I hope to have this released very shortly.

Edited by tpw

Share this post


Link to post
Share on other sites

To participate a bit more in brainstorming that fascinating topic...

Initially I misinterpreted your phrase "enterable houses". I thought of "non-enterable" houses as those you can find a lot in Chernarus, looking like a "house" but being actually only a solid block.

I was able to exclude doors of walls and such with

{ if ( (random(100) <= _chance) and ([color="#FF0000"]((_x buildingpos 0) select 0) != 0)[/color] ) then { _houses = _houses + [_x] } } forEach _allhouses;

Share this post


Link to post
Share on other sites

Ooh that code is much more elegant than mine! Do you mind if I include that in my script too?

  RogueTrooper said:
To participate a bit more in brainstorming that fascinating topic...

Initially I misinterpreted your phrase "enterable houses". I thought of "non-enterable" houses as those you can find a lot in Chernarus, looking like a "house" but being actually only a solid block.

I was able to exclude doors of walls and such with

{ if ( (random(100) <= _chance) and ([color="#FF0000"]((_x buildingpos 0) select 0) != 0)[/color] ) then { _houses = _houses + [_x] } } forEach _allhouses;

Share this post


Link to post
Share on other sites

Here is my clean and advanced version of your solution.

In this script, the lights will be created on the fly and dynamically and not at once every 250meters.

Additionally, the houses in Chernarus will turn the lights on too.

In the package is an additional fsm version for more performance.

Download

Script1:

/*
Advanced House Light Script
Version 1.00
Made by Rockhount
Original by TPW
example: nul=[Player,5,250,.02,[1,.5,.1],-160,-1,50,.1,20] exexVM "HouseLights.sqf";
*/
_Center = if (count _this > 0) then {_this select 0} else {Player};
_Time = if (count _this > 1) then {_this select 1} else {5};
_Radius = if (count _this > 2) then {_this select 2} else {250};
_Brightness = if (count _this > 3) then {_this select 3} else {.02};
_Color = if (count _this > 4) then {_this select 4} else {[1,.5,.1]};
_mAngle = if (count _this > 5) then {_this select 5} else {-180};
_xAngle = if (count _this > 6) then {_this select 6} else {-10};
_Random = if (count _this > 7) then {_this select 7} else {100};
_Flicker = if (count _this > 8) then {_this select 8} else {.1};
_RandomFlicker = if (count _this > 9) then {_this select 9} else {20};
_oldhouses = [];
_Pos = [.1,.1,.1];

if ((!isServer && isMultiplayer) or (isServer && !isDedicated)) then
{
while
{
	if (typename _Center == typename "") then
	{
		(getMarkerpos _Center) select 0 != 0;
	}
	else
	{
		alive _Center;
	};
}
do
{
	_Lat = -1 * getNumber(configFile >> "CfgWorlds" >> worldName >> "latitude");
	_Day = 360 * (dateToNumber date);
	_Hour = (daytime / 24) * 360;
	_SunAngle = ((12 * cos(_day) - 78) * cos(_lat) * cos(_hour)) - (24 * sin(_lat) * cos(_day));
	if ((_SunAngle >= _mAngle) && (_SunAngle <= _xAngle)) then
	{
		if (typename _Center == typename "") then
		{
			_Pos = getMarkerpos _Center;
		}
		else
		{
			_Pos = getPos _Center;
		};
		_houses = nearestObjects [_Pos, ["House"], _Radius];
		for [{_i = 0},{_i < count _houses},{_i = _i + 1}] do
		{
			_Ramdon2 = random (100 / _Random);
			if ((_Ramdon2 <= 1) && (((_houses select _i) buildingPos 2) select 0 != 0) && !(_houses select _i in _oldhouses)) then
			{
				_lightbulb = "#lightpoint" createVehicleLocal [(((_houses select _i) buildingPos (round(random 5))) select 0),(((_houses select _i) buildingPos (round(random 5))) select 1),(((_houses select _i) buildingPos (round(random 5))) select 2) + (random 1) - (random .9)];
				_lightbulb setLightBrightness _Brightness;
				_lightbulb setLightColor _Color;
				if (_Flicker > 0) then
				{
					[_Center,_lightbulb,_Flicker,_Brightness,_Radius,_RandomFlicker] execVM "ChangeLight.sqf";
				}
				else
				{
					[_Center,_lightbulb] execVM "ChangeLight.sqf";
				};
			};
			if ((_Ramdon2 <= 1) && (((_houses select _i) buildingPos 0) select 0 == 0)) then
			{
				for [{_i2 = 0},{_i2 < round (random 2)},{_i2 = _i2 + 1}] do
				{
					(_houses select _i) animate [format ["Lights_%1",_i2],1];
				};
			};
		};
		_oldhouses = _houses;
		sleep _Time;
	}
	else
	{
		sleep 30;
	};
};
};

Script2:

/*
Advanced House Light Script
Version 1.00
Made by Rockhount
*/
_Center = _this select 0;
_Lightbulb = _this select 1;
_Flicker = if (count _this > 2) then {_this select 2} else {0};
_Brightness = if (count _this > 3) then {_this select 3} else {.02};
_Radius = if (count _this > 4) then {_this select 4} else {250};
_Random = if (count _this > 5) then {_this select 5} else {20};
if (_Random < 1) then
{
_Random = 1;
};
_Time = 5;
_Random2 = random (100 / _Random);

while 
{
if (typename _Center == typename "") then 
{
	(getMarkerpos _Center) distance _Lightbulb <= _Radius;
}
else
{
	_Center distance _Lightbulb <= _Radius;
};
} 
do
{
if ((_Random2 <= 1) && (_Flicker > 0)) then
{
	_Random = random (_Brightness / 6);
	_Time = random _Flicker;
	_Lightbulb setLightBrightness ((_Brightness - (_Brightness / 6)) + _Random);
};
sleep _Time;
};
deleteVehicle _Lightbulb;

Edited by Rockhount

Share this post


Link to post
Share on other sites

Wow Rockhount, everyone's really getting into the spirit of it now!

Here's my latest attempt, which does a few additional things

  • Allows a user specified percentage of houses to be lit
  • Randomly assigns one of three light types: warm yellow candle; white/yellow incandescent; and blue/white fluoro or tv
  • Slightly randomises each assigned colour and brightness
  • Allows a user specified percentage of each light type to flicker (flicker variation for each light type is user defined)

Many thanks RogueTrooper for the better building selection code, and to Rydygier for the flickering code which I have adapted slightly. The gently flickering lights in each house are mindblowing to behold!

  Reveal hidden contents

I think we might be able to combine everyone's contributions into a very nice little addon. Thanks to you all.

Edited by tpw

Share this post


Link to post
Share on other sites

How is the MP compatibility on this? I can't seem to get this to work in MP at all on a dedicated :/ It is also important to make sure that every player see the same light in the same house :)

Share this post


Link to post
Share on other sites

I don't play MP so haven't tested it. Mine and Rockhount's versions are player centric, but the randomness elements in the scripts might mean that each player sees something different even if at nearly the same point on the map. Someone better qualified than me should be able to answer or implement a solution!

Share this post


Link to post
Share on other sites
  Quote
tpw

Mine and Rockhount's versions are player centric

Thats not true. In my script you can use any object or Marker as central point.

  Quote
Pellejones

How is the MP compatibility on this?

With this code in tpw's script you will never see the lights as a normal multiplayer client:

if (!isServer) exitWith {};

In my script you would see it as a normal multiplayer client, but every client would see different lights.

Additionally, this commands, which I and twp uses, will not be broadcasted:

createVehicleLocal, setLightBrightness, setLightColor

The solution:

Every client would have to broadcast his position in a specific interval and his unit name once.

The server would check every broadcasted position and, if needed, he would boradcast an array with the properties for every new single light.

To delete the old lights, the server would have to scheck if every broadcasted unit is further away than the specific range.

And all this would cost a lot of traffic and performance.

For example:

On a server with 30 players, the server would have to run till 18000 loops, because every lightpoint have his own loop.

Edited by Rockhount

Share this post


Link to post
Share on other sites

I used this code, and got it working in MP on dedicated:

//_handle = [object,radius, % of houses] execVM "houselights.sqf";
//example: _handle = [logic1,500,100] execVM "houselights.sqf";

if !(isServer) then { exit };

_center = position (_this select 0);
_radius = _this select 1;
_chance = _this select 2;

if (_chance <= 0) then { exit };

_houses     = [];
_brightness = 64;
_red        = 255;
_green      = 127; 
_blue       = 24;
_br         = (_brightness / 255) * 0.1;

_r   = _red /255;
_g   = _green /255;
_b   = _blue /255;
_col = [_r,_g,_b];

_allhouses = nearestObjects [_center, ["House"], _radius];
{ if ( (random(100) <= _chance) and (((_x buildingpos 0) select 0) != 0) ) then { _houses = _houses + [_x] } } forEach _allhouses;

if ((count _allhouses) == 0) then { exit };

{ _light = "#lightpoint" createVehicle (getpos _x); _light setLightBrightness _br; _light setLightColor _col; _light lightAttachObject [_x, [random 2,random 2,1]];} forEach _houses;

exit;

It should create the same light for each client, since it is run on the server only.

//EDIT

And after testing on Dedi with 4 players, the random thing is random... for every player :( no synced random.

Edited by Pellejones

Share this post


Link to post
Share on other sites

I know nearly nothing about MP scripting specificty, but wonder, how heavy will be traffic generated by attempt to synchronize randomization, especially for flickering...

BTW I see that night walks through Zaghrabad will become my new habit... :)

Share this post


Link to post
Share on other sites

@Pellejones

Sry, but you have written a waste of code.

This should never be included in a sqf script:

if !(isServer) then {exit};

Why?

Because

exit

will always be ignored in a sqf script. BI Wiki Source

That means, that everyone would run this script (The server and the clients).

The right code would look like this:

if (isServer) then 
{
...
};

But then, the clients would never see any light.

So the right code should look like this:

if (!isDedicated) then 
{
...
};

And remember, the two important scripting commands, which we all use, will never be broadcasted automatically.

So we must broadcast it manually.

setLightBrightness, setLightColor

Everyone, who doesn't have much multiplayer scripting experience, should take a look at this.

Edited by Rockhount

Share this post


Link to post
Share on other sites

Awesome tpw! Similar to Rydygier I make missions at night time a lot, or use the time excelleration script along side it.

Share this post


Link to post
Share on other sites
  Rockhount said:
Thats not true. In my script you can use any object or Marker as central point.[/Quote]

Sorry, I stand corrected. I saw the word "player" in your code and assumed. On the other hand a few (any) comments in the code would have helped :)

  Rockhount said:
With this code in tpw's script you will never see the lights as a normal multiplayer client:

if (!isServer) exitWith {};

In my script you would see it as a normal multiplayer client, but every client would see different lights.

Hmm, http://www.kylania.com/ex/?p=26 suggests otherwise, which is why I and many others use if (!isServer) exitWith {}; to make our scripts run on clients but not servers.

Other have reported this script to work in MP

http://forums.bistudio.com/showthread.php?134139-TPW-HOUSELIGHTS-automatic-house-light-addon&p=2147005&viewfull=1#post2147005

This thread has proved that there are many ways to skin a cat! That's the great thing about this community - people share their code so you can pick and choose and modify to get the solution that suits you best.

I'll pbo up my script shortly for those who'd like a non-server version.

Thanks again to all who are contributing to this thread.

Edited by tpw

Share this post


Link to post
Share on other sites

This:

if (!isServer) exitWith {};

would stop every multiplayer client to run your script, because "!isServer" is always true as a multiplayer client.

  Quote
MULTIPLAYER CLIENT

isMultiplayer returns true

isServer returns false <-----

isDedicated returns false

Edited by Rockhount

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  

×