Page 1 of 3

Perfectly functioning Flashlight in RF for those who want it

Posted: Mon Nov 14, 2005 7:21 pm
by ZenBudha
Hello all thanks to AndyCR's flashlight demo, and QuestOfDreams for scripting assisitance.

I have managed to get a properly working flashlight or rather WE have managed to get a properly functioning flashlight into RF.

Unlike any older buggy flashlights that pitch or yaw funny this one doesn't. It points straight where the camera is looking all the time. Whether up or down, all directions etc.

You will need AndyCR's flashlight pawn demo which has everything you need for the flashlight to work.

Then you need to edit the flashpawn.s script to the following...
{

Spawn[()
{
LowLevel("setup");
}]

setup[()
{
SetNoCollision();
PawnRender(false);
self.yaw_speed = 100000;
self.pitch_speed = 100000;

self.think = "update";
}]

update[()
{
self.ThinkTime = 0.0;

self.ideal_yaw = self.player_yaw;
ChangeYaw();

PositionToPlayer(0, 30, 10, true);

self.ideal_pitch = -(self.camera_pitch);
ChangePitch();
}]

}
I hope many of you find this use. Of course if you want it to turn on and off you will need to script the pawn, and a trigger to switch on and off for whatever key you want to use for the flashlight.

Have fun with it as it's really nice. Although I have to give 90% of the credit to AndyCR who brought it halfway, and QOD who finished the job. All I really did was bring it up and start trying to fix it. My scripting ability sucks so QOD fixed my code errors, and added in the proper commands.

Posted: Wed Nov 16, 2005 3:54 pm
by hike1
Yep, it works, but how would I integrate it with my normal flashlight scheme, which is an item I pick up in the level and can
turn it off and on? Also, what is so special about the xanibot3.act? I thought it was just a place holder, but when I substituted proj.act and landmine.act (don't want to load any unneeded polys) the flashlight didnt' work. All 3 have the 0 180 0
orientation if that's important.

Posted: Wed Nov 16, 2005 5:01 pm
by AndyCR
its just the bone name that it needs; change that to whatever bone in the proj.act, and that would work just as well. nothing special.

to relate it to an attribute, you would, i believe, make the script check if the player has attribute "flashlight", and if so, then and only then shine. you could aolso set it up so a key toggled it if you wanted.

Posted: Wed Nov 16, 2005 8:09 pm
by Nout
All 3 have the 0 180 0 orientation if that's important.
This is a bug in genesis. There exists a new routine in Rf that can be used to replace the genesis routine. Likely this new routine is not yet used in the failing commands?

Which commands / entities are failing for this rotation?

Posted: Thu Nov 17, 2005 6:19 pm
by Jay
hike1 wrote:Yep, it works, but how would I integrate it with my normal flashlight scheme, which is an item I pick up in the level and can
turn it off and on?

{

KEYNUMBER [] //Add your keynumber...
ON [false]
TRIGGER_NAME [] //Add name of trigger for the light itself

Spawn[()
{
LowLevel("setup");
}]

setup[()
{
SetNoCollision();
PawnRender(false);
self.yaw_speed = 100000;
self.pitch_speed = 100000;

self.think = "update";
}]

update[()
{
self.ThinkTime = 0.0;
if(GetAttribute("flashlight")=1) //Check if player has flashlight
{
self.think = "fll";
}//HAVE FLASHLIGHT
}]

fll[ ()
{
if(ON) //if flashlight is on...
{

self.ideal_yaw = self.player_yaw;
ChangeYaw();

PositionToPlayer(0, 30, 10, true);

self.ideal_pitch = -(self.camera_pitch);
ChangePitch();
}//ON
if(self.key_pressed=KEYNUMBER) //if flashlight-key is being pressed
{
if(ON = false)//if flashlight is off
{
SetEventState(TRIGGER_NAME, true);
ON = true;
}//OFF
else //if it's on
{
SetEventState(TRIGGER_NAME, false);
ON = false;
}//ON
}//KEYPRESSED
if(GetAttribute("flashlight")=0) //Player lost flashlight...
{
self.think = "update";
}//HAVE NO FLASHLIGHT
}]
}

This should do it i think.
the fll is to save time. so that not the whole function has to be done when the player doesn't even have the flashlight. it's not much, but when you have a script for nearly everything(which is what i have; i have a script for the soundtrack, a script for the things that move around with the player(such as rain, because then the rain doesn't eat your fps because there are just 200-500 particles per second rather than 600000) a huge fighting script and more)

Posted: Thu Nov 17, 2005 8:44 pm
by fps
this is great.
I will get it on a disk and to my home computer as soon an i can,
just where is that demo you reffered to?

thanks,
fps

Posted: Thu Nov 17, 2005 9:00 pm
by AndyCR

Posted: Fri Nov 18, 2005 4:38 pm
by fps
thanks :)

Posted: Sat Nov 19, 2005 6:27 pm
by Guest
Hi, I was having trouble getting the new flashlight script to work.
I downloaded AndyCR's example and it worked the way it was supposed to but when I changed the script to the one ZenBudda posted and compiled and ran the level the flashlight no longer worked. Moving around in the level I could not see any light coming from the player except a faint glow when I walked right up to a wall. When switching to third person view there appeared to be a slight glow on the floor around the player. The only thing that I changed in the demo was the script. Anyone have any ideas on what I am doing wrong or what might be causing the problem.

Posted: Sun Nov 20, 2005 1:46 pm
by Jay
did you use ZenBudda's script or my script? i forgot, mine only works if the player has EXACTLY one flashlight. I will correct this issue right now:


New Code:

Code: Select all

KEYNUMBER [] //Add your keynumber... 
ON [false] 
TRIGGER_NAME [] //Add name of the trigger for the light itself...

Spawn[() 
{ 
LowLevel("setup"); 
}] 

setup[() 
{ 
SetNoCollision(); 
PawnRender(false); 
self.yaw_speed = 100000; 
self.pitch_speed = 100000; 

self.think = "update"; 
}] 

update[() 
{ 
self.ThinkTime = 0.0; 
if(GetAttribute("flashlight")>0) //Check if player has flashlight! 
{ 
self.think = "fll"; 
}//HAVE FLASHLIGHT 
}] 

fll[ () 
{ 
if(ON) //if flashlight is on... 
{ 

self.ideal_yaw = self.player_yaw; 
ChangeYaw(); 

PositionToPlayer(0, 30, 10, true); 

self.ideal_pitch = self.camera_pitch*(-1); 
ChangePitch(); 
}//ON 
if(self.key_pressed=KEYNUMBER) //if flashlight-key is being pressed 
{ 
if(ON = false)//if flashlight is off 
{ 
SetEventState(TRIGGER_NAME, true); 
ON = true; 
}//OFF 
else //if it's on 
{ 
SetEventState(TRIGGER_NAME, false); 
ON = false; 
}//ON 
}//KEYPRESSED 
if(GetAttribute("flashlight")=0) //Player lost flashlight... 
{ 
self.think = "update"; 
}//HAVE NO FLASHLIGHT 
}] 
}

Posted: Sun Nov 20, 2005 2:29 pm
by QuestOfDreams
Hi, I was having trouble getting the new flashlight script to work...
You may want to replace the DynamicLight entity by a DSpotLight entity (set Rotate to True)

Posted: Mon Nov 21, 2005 7:48 am
by Nate
I replaced the Dynamic light with a DSpotLight (rotate = true) and it works perfectly now. Thank you very much for your help.

I was also wondering if there is a way to change the brightness of the light so that it can be seen further.

Posted: Mon Nov 21, 2005 5:25 pm
by QuestOfDreams
increase the MaxRadius/MinRadius :roll:

Posted: Mon Nov 21, 2005 6:57 pm
by federico
Nout added scripted lights features. This can provide you a decreasing battery effect for the flashlight... :D

Posted: Tue Nov 22, 2005 8:56 am
by Nate
Thanks for all your help, I didn't realize what a difference changing the radious could make.

A battery effect for a flashlight is a cool idea.