Game Development Community

Flashlights possible

by Ilidrake · in Torque 3D Professional · 09/22/2009 (5:17 pm) · 12 replies

Is it possible to create flashlights with scripts only? Are there any resources available for this yet? Thanks in advance.

#1
09/23/2009 (2:33 pm)
Create a shapeBaseImage of a flashlight and mount it just like a weapon. Then create a spotlight object through script, and then mount the light to the mountpoint that the flashlight is on. Ill post code in a few minutes, just wanna try and remember how to do it. :)
#2
09/23/2009 (2:42 pm)
To actually mount the light object to the player you do this:

%obj.mountobject(%light, 1);

Where 1 is, that would be the mountpoint on the player or vehicle.
#3
09/23/2009 (3:23 pm)
to add a flashlight to any weapon,
simply add
lightType = SpotLight;
into the datablock ShapeBaseImageData of the weapon
nothing else required.
#4
09/23/2009 (3:44 pm)
@deepscratch:
I had wondered when someone would figure that one out :D
#5
09/23/2009 (5:08 pm)
well, i've tried just deepscrath advice and it works fine. how can i add a switch on/off function? i think i need a full funktion in my weapons datablock? i just started to study software development, so i have to ask around and anoy you with my confused questions.
#6
04/05/2010 (10:54 am)
reviving old thread

Have a question regarding deepscratch's method. Is there any way to access the lights options/dynamic fields? Trying to do the same as Arne, switching on/off flashlight by enabling/disabling the light.

Thanks.
#7
04/05/2010 (12:52 pm)
I would assume you could just change the fieldvalue from script.

%weapon.setFieldValue("lightType", "");

*note: This is untested by me
#8
04/05/2010 (1:05 pm)
Thank you Jacob, worked perfectly.

For people with the same question, this is how you turn on/off flashlight:
%player.getMountedImage($WeaponSlot).setFieldValue("lightType", "SpotLight");

to turn on
%player.getMountedImage($WeaponSlot).setFieldValue("lightType", "");
to turn off

EDIT: Will only work singleplayer.
#9
04/05/2010 (11:45 pm)
Please note that you are modifying a datablock and not an instance of an object.
So everyone one who used this datablock will have the light or not and not just your player.
This can work for you, but just in case I warned :D
#10
04/06/2010 (4:59 am)
@ elvince
Ahh, true, true. How do you suggest doing achieving this then?
#11
04/06/2010 (9:14 am)
also what all lighttypes are available or is it just spotlight.
and can the spotlight be rotated in a way to make it more like a lantern light on the player so it lights a sperical area around the player?
#12
04/06/2010 (9:19 am)
@ Donald
Then you can use "ConstantLight". In your lantern ShapeBaseImage file just add
lightType = "ConstantLight";
lightRadius = 2; //If you want to control the radius