Advertisement
Guest User

Untitled

a guest
Jul 30th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.76 KB | None | 0 0
  1. //House / Building / Object Lighting for dayZ by axeman
  2. while {alive player}
  3. do
  4. {
  5. if(daytime<6||daytime>17)//EDITABLE - Change the stop and start times for the script. No need to create lights in the day. If server set to Static time then assume time is 12.
  6. then {
  7. private ["_strMessage","_brightness","_objLightPoint","_awayx","_awayy","_lp","_test","_hcount","_animlightpoint","_switching","_switchpercent"];
  8. //
  9. //VARIABLES
  10. //
  11. //These can be edited to change the behaviour and style of the lighting.
  12. //
  13. //_range | Distance to scan for buildings / houses in metres.
  14. _range=1500;
  15. //_switchpercent | Percentage for reliability of power supply. eg. 65 will be 65% chance of lights coming on in each house (for lit house a 65% chance of second lights coming on if house has them) and 35% chance that lights will fail and flicker off.
  16. _switchpercent = 100;
  17. // _objHouse | The array of houses, generally non enterable, that have windows that light up. Add more custom buildings within the square brackets []. Must be contained in double quotes and separated by a comma.
  18. // House lighting does a special check to see if there is a window that is lit up before creating the ambient light point. Check the building config and ensure your house has a class of 'Lights_1' before adding here. If not sure use one of the next arrays (Industrial or Misc)
  19. _objHouse = nearestObjects [player, [], _range];
  20. // _houseColour | Set the colour for the house lighting
  21. _houseColour=[1, 1, 1];
  22. // _objIndustrial | The array of industrial buildings to add a light source to. Add more custom buildings within the square brackets []. Must be contained in double quotes and separated by a comma.
  23. // No checks are done on this beyond looking for an existing lighpoint and animating that. Add any object here to emit an industrial light..
  24. _objIndustrial = nearestObjects [player, [], _range];
  25. //_indColour | Set the colour for the industrial building lighting
  26. _indColour=[1, 1, 0];
  27. // _objMisc | The array of misc. objects to add a light source to. Add more custom buildings within the square brackets []. Must be contained in double quotes and separated by a comma.
  28. // No checks are done on this beyond looking for an existing lighpoint and animating that. Add any object here to emit an misc light..
  29. _objMisc = nearestObjects [player, ["Land_runway_edgelight"], _range];
  30. //_miscColour | Set the colour for the misc. building lighting
  31. _miscColour=[1, 1, 1];
  32.  
  33. //
  34. //NO NEED TO EDIT BELOW HERE
  35. //BUT FEEL FREE TO PLAY :)
  36. //
  37.  
  38. {
  39. _switching = random 100;
  40. [_miscColour,0.01,[3, 3, 3],[_x],0] call fnc_lightpoint;
  41. } forEach _objMisc;
  42.  
  43. {
  44. _switching = random 100;
  45. [_indColour,0.01,[3, 3, 3],[_x],0] call fnc_lightpoint;
  46. } forEach _objIndustrial;
  47.  
  48. {
  49. _switching = random 100;
  50. _switching2 = random 100;//Second random to mix it up, eg. some houses have two lots of windows that light up..
  51.  
  52. _lightstate = _x animationPhase "Lights_1";//Current Lightstate of windows IMPORTANT first run lights are off !
  53.  
  54. if(_lightstate==0) then
  55. {
  56. [[_x]] call fnc_lightson;
  57. };
  58. [_houseColour,0.01,[5, 5, 5],[_x],1] call fnc_lightpoint;
  59.  
  60. if(_lightstate==1) then
  61. {
  62. [[_x]] call fnc_lightfail;
  63. };
  64.  
  65. } forEach _objHouse;
  66.  
  67. // hint format ["All buildings within %1 metres dealt with.",_range];
  68. //sleep 0.5;
  69.  
  70. //
  71. //FUNCTIONS
  72. //
  73. //Switch glowing windows on in houses that have them
  74. fnc_lightson={
  75. _building = _this select 0 select 0;
  76.  
  77. if(_switching <_switchpercent) then
  78. {
  79. _building animate ["Lights_1",1];
  80. if(_switching2 <_switchpercent) then
  81. {
  82. _building animate ["Lights_2",1];
  83. };
  84. sleep 0.1;//REQUIRED
  85. };
  86. };
  87. //flicker lights off (for houses with glowing windows only) Runs after all other light sources have been switched on.
  88. fnc_lightfail={
  89. _building = _this select 0 select 0;
  90.  
  91. if(_switching>_switchpercent)then
  92. {
  93. _animlightpoint = nearestObject [_building, "#lightpoint"];
  94. for "_s" from 1 to 5 do {
  95. if(_s%2==0)then
  96. {
  97. _brightness=0;
  98. for "_l" from 1 to 2 do {
  99. _building animate [format ["Lights_%1",_l],0];
  100. };
  101. }
  102. else
  103. {
  104. _brightness=0.4;
  105. for "_l" from 1 to 2 do {
  106. _building animate [format ["Lights_%1",_l],1];
  107. };
  108. };
  109. _animlightpoint setLightBrightness _brightness;
  110. _sleeptime=(random 100)/800;
  111. //_sleeptime=_sleeptime/500;
  112. sleep _sleeptime;
  113. };
  114. for "_l" from 1 to 2 do {
  115. _building animate [format ["Lights_%1",_l],0];
  116. };
  117. _animlightpoint setLightBrightness 0;
  118. //hint format ["Failing light for:%1 | Last Sleeptime:%2",_building,_sleeptime];
  119. sleep 6;
  120. };
  121. };
  122. //Create a lightpoint when called
  123. //eg. [_indColour,0.01,[3, 3, 3],[_x],0] call fnc_lightpoint;
  124. // array is [colour array,brightness,ambience array,this building / house object, run check to see if window lit first(for houses only)]
  125. fnc_lightpoint={
  126. _building = _this select 3 select 0;
  127. _doCheck = _this select 4;
  128. _runfunc=true;
  129.  
  130. if(_doCheck==1&&_building animationPhase "Lights_1"<1)then{
  131. _runfunc=false;
  132. //hint format ["Do Check:%1 | Light Phase:%2",_doCheck,_building animationPhase "Lights_1"];
  133. //sleep 0.5;
  134. };
  135. if(_runfunc)then
  136. {
  137. _lightColour = _this select 0;
  138. _lightBrightness = _this select 1;
  139. _lightAmbient = _this select 2;
  140. _objLightPoint = nearestObject [_building, "#lightpoint"];
  141. _xpos = getPos _building select 0;
  142. _ypos = getPos _building select 1;
  143. _lightposX = getPos _objLightPoint select 0;
  144. _lightposY = getPos _objLightPoint select 1;
  145. _awayx=_xpos-_lightposX;
  146. _awayy=_ypos-_lightposY;
  147. if((_awayx>1 or _awayx<-1)or(_awayy>1 or _awayy<-1))then
  148. {
  149. if(_switching<_switchpercent)then
  150. {
  151. _lp = "#lightpoint" createVehicle [0,0,0];
  152. _lp setLightColor _lightColour;
  153. _lp setLightBrightness _lightBrightness;
  154. _lp setLightAmbient _lightAmbient;
  155. _lp setPos [getPos _building select 0,getPos _building select 1,-3];
  156. _lp setDir getDir _building;
  157. //sleep 0.5;
  158. };
  159. }
  160. else
  161. {
  162. _objLightPoint setLightColor _lightColour;
  163. _objLightPoint setLightBrightness _lightBrightness;
  164. _objLightPoint setLightAmbient _lightAmbient;
  165. //sleep 0.5;
  166. };
  167. //hint format["X:%1 | Y:%2 | AwayX:%3 | Building:%4 | Lightpoint:%5 | Switching:%6 | ",_xpos,_ypos,_awayx,_building,_objLightPoint,_switching];
  168. //sleep 0.5;//for hint
  169. };
  170. };
  171. };
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement