Perfectly functioning Flashlight in RF for those who want it

Topics regarding Scripting with Reality Factory
User avatar
ZenBudha
Posts: 285
Joined: Wed Aug 17, 2005 6:06 am
Contact:

Perfectly functioning Flashlight in RF for those who want it

Post by ZenBudha » Mon Nov 14, 2005 7:21 pm

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.
Fear not the textures for the almighty stylus is with thee - Book of Zen

hike1
RF FAQ-Keeper
Posts: 607
Joined: Tue Jul 05, 2005 4:19 am
Contact:

Post by hike1 » Wed Nov 16, 2005 3:54 pm

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.

User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR » Wed Nov 16, 2005 5:01 pm

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.

Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout » Wed Nov 16, 2005 8:09 pm

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?

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay » Thu Nov 17, 2005 6:19 pm

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)
Last edited by Jay on Fri Nov 18, 2005 8:52 pm, edited 1 time in total.
Everyone can see the difficult, but only the wise can see the simple.
-----

User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post by fps » Thu Nov 17, 2005 8:44 pm

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

User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR » Thu Nov 17, 2005 9:00 pm


User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post by fps » Fri Nov 18, 2005 4:38 pm

thanks :)

Guest

Post by Guest » Sat Nov 19, 2005 6:27 pm

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.

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay » Sun Nov 20, 2005 1:46 pm

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 
}] 
}
Everyone can see the difficult, but only the wise can see the simple.
-----

User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Post by QuestOfDreams » Sun Nov 20, 2005 2:29 pm

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)

Nate

Post by Nate » Mon Nov 21, 2005 7:48 am

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.

User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Post by QuestOfDreams » Mon Nov 21, 2005 5:25 pm

increase the MaxRadius/MinRadius :roll:

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Mon Nov 21, 2005 6:57 pm

Nout added scripted lights features. This can provide you a decreasing battery effect for the flashlight... :D

Nate

Post by Nate » Tue Nov 22, 2005 8:56 am

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.

Post Reply