dynamic lighting ON/OFF Key

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
Vertex
Posts: 108
Joined: Fri May 22, 2015 1:01 am
Location: Colombia
Contact:

dynamic lighting ON/OFF Key

Post by Vertex » Fri Jun 26, 2015 5:50 am

Any suggestions on how enceder and Apgar light by a key.

My character takes a flashlight and desire that on or apage mendiante the L key is a DSpotLight Light
http://www.iris3dgames.com Reality Factory Spanish :wink:

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: dynamic lighting ON/OFF Key

Post by Allanon » Fri Jun 26, 2015 9:29 am

Maybe something like this:

Code: Select all

{
    ON [false]             // indicates if flashlight is on or off
    KEYPRESSED [false]    // indicates key has been pressed

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

    setup[()
    {
        // flashlight setup code goes here
        self.think = "update";               
    }]

    update[()
    {
        self.ThinkTime = 0.1;   //  call this function every .1 seconds

        if (GetAttribute("flashlight", "player") > 0)    // Check if player has flashlight
        {
            if ((Input.IsKeyDown(Input.Key.L)) and (not KEYPRESSED))     // if flashlight key is being pressed 
            {
                ON = not ON         // toggle flashlight on or off
                KEYPRESSED = true   // key is pressed
                //  do something
            }
            else
            {
                KEYPRESSED = false  // key is not pressed
            }
                         
            if (ON)    
            {
                //  Flashlight is on
                //  do something
            }
            else
            {
                //  Flashlight is off
                //  do something
            }
        }
    }]
}
NOTE: KEYPRESSED will stop the flashlight from toggling on and off if the flashlight key is held down.

User avatar
Vertex
Posts: 108
Joined: Fri May 22, 2015 1:01 am
Location: Colombia
Contact:

Re: dynamic lighting ON/OFF Key

Post by Vertex » Fri Jun 26, 2015 4:18 pm

But as I turn on the light and turn off ? The light is called zsNameEntity LIGHTplayer in their properties .
http://www.iris3dgames.com Reality Factory Spanish :wink:

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: dynamic lighting ON/OFF Key

Post by Allanon » Fri Jun 26, 2015 7:15 pm

I'm having trouble understanding your translations. Can you post your player script and any other script that deals with the light?

User avatar
Vertex
Posts: 108
Joined: Fri May 22, 2015 1:01 am
Location: Colombia
Contact:

Re: dynamic lighting ON/OFF Key

Post by Vertex » Fri Jun 26, 2015 9:05 pm

What I try to do is the following.

The player takes takes a flashlight. ( Achieved )
The next step is to press the L key , the flashlight emits light . Then if we want the flashlight does not emit light , again pressed the L key , and the flashlight stops emitting light.

OFF.
Image
ON
Image
http://www.iris3dgames.com Reality Factory Spanish :wink:

User avatar
Vertex
Posts: 108
Joined: Fri May 22, 2015 1:01 am
Location: Colombia
Contact:

Re: dynamic lighting ON/OFF Key

Post by Vertex » Fri Jun 26, 2015 9:43 pm

Ok, no problem. Entity Trigger and Entity LogicGate :)
http://www.iris3dgames.com Reality Factory Spanish :wink:

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: dynamic lighting ON/OFF Key

Post by Allanon » Fri Jun 26, 2015 9:56 pm

You need to create a light with a trigger. We will call this trigger Flashlight_Trigger.

flashlight script:

Code: Select all

{
    ON [false]             // indicates if flashlight is on or off
    KEYPRESSED [false]    // indicates key has been pressed

    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", "player") > 0)    // Check if player has flashlight
        {
            if ((Input.IsKeyDown(Input.Key.L)) and (not KEYPRESSED))     // if flashlight key is being pressed 
            {
                ON = not ON         // toggle flashlight on or off
                KEYPRESSED = true   // key is pressed
                SetEventState("Flashlight_Trigger", ON);  // set flashlight trigger on / off
            }
            else
            {
                KEYPRESSED = false  // key is not pressed
            }

            if (ON)    
            {
                self.ideal_yaw = self.player_yaw; 
                ChangeYaw(); 
                PositionToPlayer(0, 30, 10, true); 
                self.ideal_pitch = self.camera_pitch*(-1); 
                ChangePitch(); 
            }
        
        }
    }]
}
NOTE: KEYPRESSED will stop the flashlight from toggling on and off if the flashlight key is held down.

Most of my code was taken from a mixture of code from this post:
viewtopic.php?f=8&t=490

User avatar
Vertex
Posts: 108
Joined: Fri May 22, 2015 1:01 am
Location: Colombia
Contact:

Re: dynamic lighting ON/OFF Key

Post by Vertex » Fri Jun 26, 2015 10:07 pm

My code.

Code: Select all

{
	// -------------------------------------------------
	// Nombre Fichero 	: Jugador.s.
	// Nombre Projecto 	: Pawn.
	// Sitio Web		: http://www.iris3dgames.com
	// Scripter			: Yue Rexie
	// Fecha			: 13 - Jun - 2015
	// -------------------------------------------------
	// Notas			: Fichero encargado de crear
	//				 	  el personaje jugador scripteado. 
	//					  
	// -------------------------------------------------
	
	// Teclas control personaje.
	TECLA				[0]										// Tecla Verificada.
	TECLA_W				[15]									// Mover Adelante.
	TECLA_S				[27]									// Mover Atras.
	TECLA_ESPACIO		[46]									// Salto.
	TECLA_C             [39]									// Agacharse.
	TECLA_E				[16]									// Interactuar.	
	TECLA_ESPACIO		[46]									// Saltar.
	TECLA_RD			[73]									// Boton derecho Raton.
    TECLA_L				[34]									// Tecla L Luz.
	
	VELOCIDAD			[200]
	
	// Animaciones.
	ANIM_DESCANSO		[Descanso]								// Animacion Descanso.
	ANIM_CORRER			[Correr]								// Animacion Correr.
	ANIM_SALTAR			[Saltar]								// Animacion de Salto.
	ANIM_INITSALTO		[InicioSalto]							// Iniciando el Salto.
	ANIMACION			[Descanso]								// Animacion Actual.
	
	
	CAMBIO_ANIM			[0]										// Cambio Animacion.
	AT 					[0.5]
    SALTO				[false]									// Salto.
	
	DISTANCIA_GORRA		[0.0]
	TOMAR_GORRA			[false]
	
	DISTANCIA_LINTERNA	[0.0]
	TOMAR_LINTERNA		[false]
	
	// Orden de Entrada.
	InicioJugador[()
	{
	
		Jugador.Console(Camara.CONSOLA);						// Se activa la Consola.
							
		Jugador.BoxHeight(60);									// Altura de Colision Jugador.
		Jugador.BoxWidth(10);									// Anchura de Colision Jugador.
		
		Jugador.yaw_speed = 1500;
		
	
		TECLA = 0;
		
		
		
		Jugador.LowLevel("Update"); 							// Orden de bajo nivel "ControlJugador".
		
	
	}]
	
	Update[()
	{
		
               // HERE LIGHT OFF/ON
		if(IsKeyDown(TECLA_L))
		{
		
		ActivateTrigger("Cables");
	
		}
		
		DISTANCIA_GORRA = GetDistanceTo("Gorra");
		if(DISTANCIA_GORRA <= 35.0)
		{
			if(IsKeyDown(TECLA_E) and (TOMAR_GORRA=false))
			{
				TOMAR_GORRA = true;
				
			}
			
		}
		
		DISTANCIA_LINTERNA = GetDistanceTo("Linterna");
		
		
		if(DISTANCIA_LINTERNA <= 35.0)
		{
			if((IsKeyDown(TECLA_E)) and (TOMAR_GORRA=true))
			{
				TOMAR_LINTERNA = true;
				
			}
			
		}
		
		
		
		PlayerToPosition(0,0,0);
		Jugador.ControlJugador();								// Controlando Jugador.
		Jugador.Animaciones();									// Animando Jugador.
		
	
		
		TECLA = 0;												// No se oprime ninguna tecla.
		AnimationSpeed(1.0);									// Velocidad Animacion.
	   	VELOCIDAD = 200;									
		
	}]
	
	
	// ---------------------------------------------------------------------
	
	
	// Animaciones.
	Animaciones[ ()
	{
		
	
		// Jugador Corre.
		if (Jugador.IsKeyDown(TECLA_W) or Jugador.IsKeyDown(TECLA_S))
		{
			TECLA = 1;
			
			ANIMACION = StringCopy(ANIM_CORRER);
		}

	
		// Jugador Cayeno.
		if (Jugador.IsFalling = true)
		{
			TECLA = 2;
			ANIMACION = StringCopy(ANIM_SALTAR);
			VELOCIDAD = Integer(100);
			
		}
		
		if((Jugador.IsKeyDown(TECLA_ESPACIO)))
		{
			
			
			TECLA = 3;
			ANIMACION = StringCopy(ANIM_INITSALTO);
			SALTO=true;
			
			
		}
		
		debug(TECLA);
		
		
		
		// Ninguna tecla presionada. 
		if (TECLA < 1)
		{
			
			ANIMACION = StringCopy(ANIM_DESCANSO);
			
			
			
		} 
		
		// Animacion de cambio.
		if (Integer(CAMBIO_ANIM) != Integer(TECLA))
		{
			AnimateBlend(ANIMACION,0.3);
			
		}
		
		CAMBIO_ANIM = Integer(TECLA);
	
		// Animando personaje.
		if(Jugador.animate_at_end)
		{
			
			AnimateHold(ANIMACION);
			
           
		}
		
		
	}]
	
	// Controlando el Jugador.
	ControlJugador[()
	{
		
		PivoteJugador.MatchPlayerAngles();
	
		// Jugador gira hacia el frente de la camara.
		if ( Jugador.IsKeyDown(Jugador.TECLA_W) ) 
		{
			
			if(SALTO = false)
			{
				Jugador.walkmove(Jugador.current_yaw,-VELOCIDAD);
			}
			
			if (Jugador.IsKeyDown(TECLA_RD)=false)
			{
				Jugador.ideal_yaw = PivoteJugador.current_yaw;
				Jugador.ChangeYaw();
			}
		} 
		
		// Jugador gira hacia la camara.
		if ( Jugador.IsKeyDown(Jugador.TECLA_S) ) 
		{
			if(SALTO = false)
			{
			
				Jugador.walkmove(Jugador.current_yaw, -VELOCIDAD);
			}
			
			
			if (Jugador.IsKeyDown(TECLA_RD)=false)
			{
				Jugador.ideal_yaw = PivoteJugador.current_yaw+ConvertDegrees(180);
				Jugador.ChangeYaw();
			}
		} 
	
	
		if((Jugador.IsKeyDown(TECLA_ESPACIO)=false) and  (SALTO = true))
		{
			
			VELOCIDAD = Integer(100);
			TECLA = 3;
			ANIMACION = StringCopy(ANIM_INITSALTO);
			Jugador.ForceUp(40);
			SALTO=false;
		
		}
		

				
		
		
		
	}]
	
	

	
}
I must honestly say that much and is not'm constantly learning.
http://www.iris3dgames.com Reality Factory Spanish :wink:

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: dynamic lighting ON/OFF Key

Post by Allanon » Fri Jun 26, 2015 10:28 pm

You don't have to do everything in the player script. You can create a flashlight pawn and attach a light and trigger then have that pawn run a flashlight script.

User avatar
Vertex
Posts: 108
Joined: Fri May 22, 2015 1:01 am
Location: Colombia
Contact:

Re: dynamic lighting ON/OFF Key

Post by Vertex » Fri Jun 26, 2015 11:41 pm

It's the only way I 've found to do this , look at the video on my facebook account .

It seems that looks good , what I've done is use a trigger entity and a LogicGate entity for the on-off light. For purposes of hat and lantern are pawns that the player hooked . :D

Video Pawn Items.
https://www.facebook.com/iris3dgames
http://www.iris3dgames.com Reality Factory Spanish :wink:

Post Reply