How To Make Switchable Model Light Source

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!

Moderators: GZDoom Developers, Raze Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Magnus1972
Posts: 12
Joined: Wed Aug 23, 2023 9:17 pm
Operating System Version (Optional): Windows 7
Graphics Processor: Not Listed

How To Make Switchable Model Light Source

Post by Magnus1972 »

I have a model ceiling light that I would like to be able to turn on and off with a switch but I can't find any information about doing it. I did try a bit of ACS, but my knowledge of ACS is very limited at this stage. Any help would be appreciated.

Modeldef

Code: Select all

//=== Scifi Celing Light===//
model scifilight1
{
	path "models/Lightfixtures/scifilight1"
	model 0 "scifilight1.md3"
	skin 0 "scifilight2.png"
	scale 80 80 80
	PITCHFROMMOMENTUM
	useactorpitch
	useactorroll
	ZOffset 0
	FrameIndex 0001 A 0 0 //on
}

model scifilight1 
{
	path "models/Lightfixtures/scifilight1"
	model 0 "scifilight1.md3"
	skin 0 "scifilight1.png"
	scale 80 80 80
	PITCHFROMMOMENTUM
	useactorpitch
	useactorroll
	ZOffset 0
	FrameIndex 0001 B 0 0 //off
}
Decorate

Code: Select all

//--- Scifi Celing Light 1 ---//
actor scifilight1
{
	//$Category Model Light Sources
	//$Title Scifi Celing Light 1


	height 2
	radius 8
	-SHOOTABLE
	+NODAMAGE
	+NOGRAVITY
	-SOLID
	scale .1
//$Arg0 Lightmode-0-2
//$Arg0Default 0
	States {
		Spawn:
			0001 A 1
			0001 A 0 A_JumpIf(Args[0] ==0, "Off")
			0001 A 0 A_JumpIf(Args[0] ==1, "On")
			0001 A 0 A_JumpIf(Args[0] >1, "Flicker")
			//0001 A 1 A_Jump (256, "On", "Off", "Flicker") // <-- Always jumps to either...
			0001 A 1
loop
  
  On: // <-- This state...
  0001 A -1  
  loop
  
  Off: // <-- This state...
  0001 B -1 
  loop		
	
  Flicker: // <-- This state...
  0001 B 10 
  0001 B 1 A_Jump (64, "flick1", "flick2", "flick3")
  loop
  
  flick1: // <-- This state...
  0001 A 5 
  goto flicker	
  
    flick2: // <-- This state...
  0001 A 20 
  goto flicker
  
    flick3: // <-- This state...
  0001 A 50 
  goto flicker
  }
}
ACS

Code: Select all

#include "zcommon.acs"

//Space Base Lights Switch
Script "Space Base Lights Switch" (void)
{
    Thing_Activate(22);
}
GLDEFS

Code: Select all

//--- Scifi Ceiling Light ---//
brightmap texture "models/lightfixtures/scifilight1/scifilight2.png"
{
	map "brightmaps/models/scifilight1bm.png"
}
DOOMDEFS

Code: Select all

//--- Space Station Ceiling Light ---//
object scifilight1
{
    frame 0001A { light CEILING_LAMPlight }
}

pointlight CEILING_LAMPlight
{
    color .8 1.0 .8
    size 128
	    offset 0 200 0
}
Magnus1972
Posts: 12
Joined: Wed Aug 23, 2023 9:17 pm
Operating System Version (Optional): Windows 7
Graphics Processor: Not Listed

Re: How To Make Switchable Model Light Source

Post by Magnus1972 »

I was hoping this was possible.

After a lot more messing about, I got this to work how I wanted. Not sure if it's the best way but it works none the less...

Solution
Decorate

Code: Select all

//--- Scifi Celing Light 1 ---//
actor scifilight1 : SwitchableDecoration
{
	//$Category Model Light Sources
	//$Title Scifi Celing Light 1


	height 2
	radius 8
	-SHOOTABLE
	+NODAMAGE
	+NOGRAVITY
	-SOLID
	scale .1

	States {
		Spawn:
		Active:
			0001 A 1
			0001 A 0 A_JumpIf(Args[0] ==0, "Off")
			0001 A 0 A_JumpIf(Args[0] ==1, "On")
			0001 A 0 A_JumpIf(Args[0] >1, "Flicker")
			//0001 A 1 A_Jump (256, "On", "Off", "Flicker") // <-- Always jumps to either...
			0001 A 1
			Stop
		Inactive:
			0001 B -1
			Stop
loop
  
  On: // <-- This state...
  0001 A -1  
  loop
  
  Off: // <-- This state...
  0001 B -1 
  loop		
	
  Flicker: // <-- This state...
  0001 B 10 
  0001 B 1 A_Jump (64, "flick1", "flick2", "flick3")
  loop
  
  flick1: // <-- This state...
  0001 A 5 
  goto flicker	
  
    flick2: // <-- This state...
  0001 A 20 
  goto flicker
  
    flick3: // <-- This state...
  0001 A 50 
  goto flicker
  }
}
ACS

Code: Select all

//Space Base Lights Switch
int x = 1;
Script "Space Base Lights Switch" (void)
{
	if(x==0)
{
	x = 1;
    Thing_Deactivate(22);
}
	else
{
	x = 0;
	Thing_Activate(22);
}
}

Return to “Assets (and other stuff)”