Sure, here's a code for a flashlight action. Just move closer to the flashlight
entity with your player ent to get the flashlight "attached". When it is, it
becomes invisible and the flashlight comes on whenever you press the f key. The
light will turn with the player.
Code:
/****************************************************************************************
2007-01-17
Dynamic Flashlight and Torch: type dynamic spotlight
becomes "attached" to player as the player gets closer than 100 from the model that has
the flashlight action attached to it, in example below it is plBiped01_entity.
Make it work by placing a flashlight model (any model) in your level, attach
the action "flashlight" to it and change the player (plBiped01_entity) to
whatever your player entity name is, and yes include this wdl in your include
list at the end.
This kind of lighting on block geometry looks "blocky". It's a property of
dynamic lighting, looks great on models though.
cheers
tindust
****************************************************************************************/
var energy = 100;
action flashlight
{
// d3d settings optional;
d3d_lightres = off; // quality of dynamic light setting. set to "on" can give better result sometimes
//d3d_spotlightcone[0] = 30; // optional settings, look up in manual. Applies to all spotlights in level
//d3d_spotlightcone[1] = 15;
//d3d_spotlightcone[2] = 1;
//
while (plBiped01_entity == null) {wait (1);}
my.passable = on;
while (vec_dist (plBiped01_entity.x, my.x) > 100) {wait (1);}
my.invisible = on;
my.lightrange = 0;
my.spotlight = on; // off for using as Torch
my.lightred = 250;
my.lightgreen = 250;
my.lightblue = 170;
while(1)
{
vec_set(my.x,plBiped01_entity.x);
vec_set(my.pan,plBiped01_entity.pan);
while (energy > 0 && key_f == 1) // press the "F" key to use the flashlight
{
my.lightrange = 1000;
vec_set(my.x,plBiped01_entity.x);
vec_set(my.pan,plBiped01_entity.pan);
my.tilt += 5; // degree upward tilt of flashlight, value depends on using third or first person view
//energy -= 0.5 * time;
wait (1);
}
my.lightrange = 0;
wait (1);
}
}