Home   Help Search Login Register  

Author Topic: Add a light source at night (For Beginners only!)  (Read 9695 times)

0 Members and 1 Guest are viewing this topic.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Add a light source at night (For Beginners only!)
« on: 18 Jul 2009, 16:10:58 »
Sometimes it might be necessary to add some lights in night missions so you can see things or specific things.
To make it just a little script is needed :
-Make a script file(.sqs) and name it "streetlighter" (be sure it is in .sqs format,not .txt format).
-Open the script and paste the following :
Code: [Select]
_object  =  _this select 0 ;
_lightheight =  _this select 1 ;

_light="#lightpoint" createvehicle position _object
_light setpos [(getpos _object select 0),(getpos _object select 1),_lightheight]
_light setlightcolor [1,1,1];
_light setlightambient [0.5,0.5,0.5];
_light setlightbrightness [1/7] ;
;the syntax to call this script will be [obj,height] exec "streetlighter.sqs"

Explanations :

Save this script in your mission folder,to call it :
Code: [Select]
First place a invisible helipad.
In the init field of that helipad,just type :
[this,height] exec "streetlighter.sqs"

Quote
_object = the object at which the light will appear

_lightheight = height above the _object at which the light will appear (example-5 will make the light
appear 5 meters above _object)

lightcolor = the color of the light,its in [R,G,B]>>>>[1,1,1] for white;[0,0,0] for black

lightambient=the same as above (this affects environment while lightcolor only affects the color of light source)

lightbrightness= its the result of the first number divide by the second one;if 1/10 the result will be 0.1 and the light will appear dim.The greater value the number is ,the brighter the light is.
Note : Increasing the value also increases the range of the light
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Absolution

  • Members
  • *
Re: Add a light source at night (For Beginners only!)
« Reply #1 on: 01 Aug 2010, 19:09:07 »
I apologize for resurrecting such an old thread but this is the very best information I can find on the subject and I have a question:


How do I modify the code above to create multiple lights at different positions around the object in question? Would it be something like this?

Init field of the object I want to add lights to:
Code: [Select]
[this] exec "whatevernameiwant.sqs"

Script text in sqs file:
Code: [Select]
_object  =  _this select 0 ;

_light1="#lightpoint" createvehicle position _object
_light1 setpos [0,10,0]
_light1 setlightcolor [1,1,1];
_light1 setlightambient [0.5,0.5,0.5];
_light1 setlightbrightness [1/7] ;

_light2="#lightpoint" createvehicle position _object
_light2 setpos [0,-10,0]
_light2 setlightcolor [1,1,1];
_light2 setlightambient [0.5,0.5,0.5];
_light2 setlightbrightness [1/7] ;

I would expect to see one white light to the left of the object and one white light to the right (or maybe front/back, above/below). That correct?

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: Add a light source at night (For Beginners only!)
« Reply #2 on: 04 Aug 2010, 12:37:45 »
Code: [Select]
;usage :
;[object,[x,y,z]] exec "light.sqs"

;x = + for front/- for back
;y = + for right/- for left
;z = + to place above object/ - = below object


;example :
;[myCar,[3,2,0.5]] exec "light.sqs"  (this put a light at 3m infront of mycar and 2m to the right)
;[myCar,[3,-2,0.5]] exec "light.sqs" (this put 3m infront of myCar and 2m to the left)
;so you got a car with the headlights!

;example2 :
;[PoliceCar,[0,0,0.5]] exec "light.sqs" (you got a police car with a siren turned on!)


_object  =  _this select 0 ;
_lightPosition =  _this select 1 ;


_lightX= _lightPosition select 0
_lightY= _lightPosition select 1
_lightZ= _lightPosition select 2
_lightColor = []

;light colors
;format is [r,g,b]

_cred=[1,0,0]
_cblue=[0,0,1]
_cgreen=[0,1,0]
_cwhite=[1,1,1]

;change _white to any of the above to change the color(this affects ALL of the lights created by this script)
_lightColor = _cwhite

_light="#lightpoint" createvehicle position _object
_light setpos [(getpos _object select 0)+_lightX*sin(getDir _object)+_lightY*cos(getDir _object),(getpos _object select 1)+_lightX*cos(getDir _object)-_lightY*sin(getDir _object),(getPos _object select 2)+_lightZ]
_light setlightcolor _lightColor;
_light setlightambient [0.5,0.5,0.5];
_light setlightbrightness [1/7] ;
exit


If requested, I can further expand this script with additional features (light size,color,brightness,duration,movewithobject,etc ,etc)


Regards,
Haroon1992
« Last Edit: 04 Aug 2010, 12:59:18 by haroon1992 »
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Absolution

  • Members
  • *
Re: Add a light source at night (For Beginners only!)
« Reply #3 on: 06 Aug 2010, 03:28:38 »
Nevermind. Between your help and help from another thread I got it all working now.

Thanks!
« Last Edit: 06 Aug 2010, 04:24:40 by Absolution »