Perfectly functioning Flashlight in RF for those who want it

Topics regarding Scripting with Reality Factory
User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Post by bernie » Sun Jan 08, 2006 12:33 pm

Try as i may I cannot get Jay's script to work for me. Zen's script works fine. I think I may be doing something wrong with the trigger. I set up a trigger to work the dynamic light entity and a model to trip the trigger. This works fine with zen's script and the light triggers when I colide with the model. However when I replace the script with Jay's script the light will neither trigger with collision or the script. I have tried to trigger with SetEventState(TRIGGER_NAME, true); as follows

KEYNUMBER [29] //Add your keynumber...
ON [false]
TRIGGER_NAME [flash] //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;
SetEventState(TRIGGER_NAME, true);
ON=true
}

and the light still does not trigger even with collison with the model. I even tried the scripts (Jay's and mine) without a model but still nothing.
Any ideas lads??
Thanks.

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

Post by hike1 » Mon Jan 16, 2006 2:19 am

I'm using Andy's overwrite of Zen's? flashlight script. It used to
work in all directions, but in 075 it only works to the west.

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

Post by AndyCR » Mon Jan 16, 2006 4:22 am

try changing

PositionToPlayer(0, 30, 10, true);

to

PositionToPlayer(0, 30, 10, true, true);

User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Post by bernie » Mon Jan 16, 2006 9:50 am

Works perfectly for me now.
I modified the script so that once lit it burns until exhausted after a set time period. You can have as many torches as you like depending on the limit you set in player.ini file.

{
KEYNUMBER [29] //Add your keynumber...ONKEY
ON [false]
TRIGGER_NAME [flash] //Add name of the trigger for the light itself...
TIM [0] // timer
LENGTH [180] // Length of time torch can remain lit in seconds...

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

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

self.think = "update";
}]

update[()
{
self.ThinkTime = 1;

if(GetAttribute("torch","player") > 0) //Check if player has torch!
{
self.think = "fll";
}//HAVE TORCH
}]

fll[ ()
{
if(ON) //if torch is lit...
{
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 torch-key is being pressed
{
if(ON = false)//if torch is off
{
SetEventState(TRIGGER_NAME,true);
ON = true;

TIM=self.time;//Start timer


}//OFF
}//ON KEYPRESSED

if(ON=true)//if torch lit
{
if(self.time >TIM+LENGTH)//if torch exhausted after set time
{
ModifyAttribute("torch" , -1 , "player");
SetEventState(TRIGGER_NAME,false);
ON = false;

}//EXHUSTED
}//LIT
if(GetAttribute("torch","player") = 0) //Player lost torch...
{
SetEventState(TRIGGER_NAME,false);
ON = false;
self.think = "update";
}//HAVE NO TORCH
}]



} //SCRIPT END

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

Post by hike1 » Mon Jan 16, 2006 6:25 pm

Are you talking to me about the position to player, Andy?
because it didn't help, still points west only.

//flashpawn.s
{

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,true);

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

}

User avatar
sriram
Posts: 19
Joined: Sat Jan 14, 2006 12:15 pm
Location: India
Contact:

Post by sriram » Tue Jan 17, 2006 7:28 am

I'm facing the same problem as hike1 :( ....the light is pointing only to the west...and changing the position to player didnt help....Andy's first script worked...but the new one is not working for me[RF075]...
Can anyone who got it working on RF075 post the sample level and the script ?
Thanks :)

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis » Tue Jan 17, 2006 2:16 pm

Hi all,

thanks very much for this flashlight thingy... I've been thinking very long how to get scripted weapons (including inaccuracy etc...) until now... You gave me the tools to make my perfect weapons. :wink:

Thank you for this idea. :D

And... I had that problem too. The light was facing the wrong direction but changing the light entity's Y-axis rotation to -68.011719 in the level editor worked for me.
Pain is only psychological.

User avatar
sriram
Posts: 19
Joined: Sat Jan 14, 2006 12:15 pm
Location: India
Contact:

Post by sriram » Tue Jan 17, 2006 5:20 pm

Thanks for the tipoff Juutis,that Y-Axis rotation of the DSpotlight was the problem..I've tried your value first but still didnt get it right,but after rotating it in such a way that its direction is parallel to the direction of "playerStart" ,I got it working :D [Angles >> X=0,Y=180,Z=0]

Thx for the wonderful script Andy,ZenBuddha and QOD :D

But,this doesnt seem to be working "properly" on Normalmapped entities...plz see these screens :
ImageImageImage

The position of the light is affecting the model's lighting[which is really cool] but the model is being lit even when the flashbeam is away from it...destroying the illusion of darkness.....Is it possible to fix this ? Or is there any setting for my model that i need to toggle to get it right ?Or has it got anything to do with the Specular map of my model :? I couldnt get the "Stencil Shadows" to work either...I did enable the option in the ini and I did try setting FSAA option to 0....but the shadow doesnt showup for my model[I did enable StencilShadows for it,and enabled "cast shadows" for the light in the editor and added the EnvironmentSetup entity,configured it as mentioned in RFFAQ] How di I get Stencil Shadows ? :?

Also,it'd be cool if there is a projection[decal] of a bitmap onto the walls [similar to the one we have in Doom 3's flashlight]...is this possible ?

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

Post by QuestOfDreams » Fri Mar 24, 2006 9:09 am

Code: Select all

update[() 
{ 
self.ThinkTime = 0.0; 

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

PositionToPlayer(0, 30, 10, true,true); 

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

Code: Select all

update[() 
{ 	
self.ThinkTime = 0.0;

PositionToPlayer(0, 30, 10, true, false);

self.ideal_yaw = self.player_yaw + 3.1415; 
ChangeYaw(); 
	
self.ideal_pitch = -self.camera_pitch;
ChangePitch();    
}]

incenseman2003
Posts: 320
Joined: Sat Mar 11, 2006 11:41 pm

Flashlight vertical?

Post by incenseman2003 » Wed Mar 29, 2006 10:05 pm

This script allows the flashlight to work horizontally. How would one make it work vertically as well, to look everywhere the player does?

{
Spawn[ ()
{
SetNoCollision();
FadeOut(0, 0);
LowLevel("Update");
//MoveForward("Idle", 10000, 10000, "");
}]

Update[ ()
{
MatchPlayerAngles();
PositionToPlayer(0, 0, 0);
PositionToPlayer(0, 0, GetCollideDistance("Bip01", 0, 0, 500000)-20, true);

RestartOrder();
}]
}



I have also tried the script below and it produced no light at all:

{

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();
}]

}


Can someone please shed some light on the subject. :lol:
Get it? :lol: :lol:
Light. :lol:
It was a joke I say.
I kill me!!! Hah!!!!!!!!! :lol: :lol: :D :? :oops:
Patience and tolerance are the keys to the passage of knowledge. Even those that are the most knowledgeable started with many questions.

User avatar
Ransom
Posts: 30
Joined: Sat Jan 14, 2006 7:16 pm

Post by Ransom » Fri Jul 28, 2006 7:56 am

I can't get the light to move vertically either. I tried both the dynamic light and the dSpotLight...

Code: Select all

{

Spawn[()
{
    Console(true);
    Gravity(false);
    LowLevel("Setup");
}]
    
Setup[()
{
    SetNoCollision(); 
    PawnRender(false);
    self.yaw_speed=100000;
    self.pitch_speed=100000;
    self.think="ShineOn";
}]
    
ShineOn[()
{ 

    self.ThinkTime = 0.0;
    PositionToPlayer(0,20,300,true,false);
    self.ideal_yaw=self.player_yaw + 3.1415; 
    ChangeYaw();
    self.ideal_pitch = -self.camera_pitch;
    ChangePitch();

}]

}

User avatar
Ransom
Posts: 30
Joined: Sat Jan 14, 2006 7:16 pm

Post by Ransom » Fri Jul 28, 2006 8:30 am

I should add that using debug(self.current_pitch) reveals that the flashlight actor is in fact changing its pitch, but the attached D-light's pitch won't rotate with it. Horizontally, the light rotates fine, but vertically, it's as if the pitch of dynamic lights cannot be dynamically altered... ?

Since Zen, at one point, had this working, did something change in the code for 075 which could have affected this?

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

Post by AndyCR » Fri Jul 28, 2006 2:08 pm

Ransom wrote:I should add that using debug(self.current_pitch) reveals that the flashlight actor is in fact changing its pitch, but the attached D-light's pitch won't rotate with it. Horizontally, the light rotates fine, but vertically, it's as if the pitch of dynamic lights cannot be dynamically altered... ?

Since Zen, at one point, had this working, did something change in the code for 075 which could have affected this?
You mean of the DLight itself? It is an omni light, it does not need to have it's rotation changed to work, it shines in all directions.

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

Post by QuestOfDreams » Fri Jul 28, 2006 4:06 pm

No, he means the DSpotlight entity

I've looked into this issue again and found out that it depends on the actor file you are using. If you use for example the Xanibot3.act it works fine, if you use the proj.act it doesn't work. The reason for this is that the root bones of the actors have a different initial rotation. So with the wrong actor the spotlight's cone will rotate around its symmetric axis, which you can't see.
I think I have some code now, which allows you to compensate this effect by giving the spotlight entity an initial rotation (this currently doesn't work). Will be in the next release...

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

Post by AndyCR » Fri Jul 28, 2006 5:48 pm

QuestOfDreams wrote:No, he means the DSpotlight entity
Oh, sorry about that! I got confused because the original version used a point light not a spotlight and I havn't been following the changes since then.

Post Reply