Using Models as Switch

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom 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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
HAL9000
Posts: 266
Joined: Fri Mar 16, 2018 7:44 am
Contact:

Using Models as Switch

Post by HAL9000 »

So.... I have a small question here, and someone already probably did this.

Lets say that I have a MD3 model switch with 2 states ON/OFF
Whats the easiest way to set this model as a functional Switch?
Does anyone have a working example?

I will probably need some ZSCRIPT magic with this, not sure if this is possible in DECORATE

Thanks
User avatar
Enjay
 
 
Posts: 26535
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Using Models as Switch

Post by Enjay »

Set it up as a switchable decoration with the +USESPECIAL flag? (should work in ZScript or DECORATE I think)
Jarewill
 
 
Posts: 1768
Joined: Sun Jul 21, 2019 8:54 am

Re: Using Models as Switch

Post by Jarewill »

Wouldn't creating an actor, inheriting from SwitchableDecoration work?
I haven't used models before, but it's probably possible to play an animation in the Active state that ends with "Wait" keyword. (So the last frame loops to not play it again)
Then in the same state you could use ACS_(Named)Execute to execute a script which does things.

There's a handy reference on the wiki here that might help.
User avatar
Enjay
 
 
Posts: 26535
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Using Models as Switch

Post by Enjay »

The other thing that might be useful is to make the switch visual (and possibly audio too) only. It would depend on what you needed, of course, but if the switch was a just switchable decoration, the activation could be on a line (as per normal) and the line could run a script that, as well as doing whatever the script needs to do, it would activate/deactivate the switch actor to get it to change appearance.

Switchable decorations work just fine with models. I don't think I've ever used "wait" with them (not saying it's bad). A sprite duration of -1 followed by Stop (for both active and inactive states) works in the actors I've made.
User avatar
HAL9000
Posts: 266
Joined: Fri Mar 16, 2018 7:44 am
Contact:

Re: Using Models as Switch

Post by HAL9000 »

Thanks Everyone, I will try your suggestions.
User avatar
Enjay
 
 
Posts: 26535
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Using Models as Switch

Post by Enjay »

I just threw this together. It's a bit rough and ready, but it does the job.
User avatar
HAL9000
Posts: 266
Joined: Fri Mar 16, 2018 7:44 am
Contact:

Re: Using Models as Switch

Post by HAL9000 »

Enjay wrote:I just threw this together. It's a bit rough and ready, but it does the job.
Thanks Enjay , I really appreciate it :D :D
It's working great!
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Using Models as Switch

Post by ramon.dexter »

I can remember that I used voxel based switches back in the days. Also, I can recall that I've downloaded it from somewhere around here ( I mean this forum), but that's all I can remember.
edit: Yup, Doom voxel project has working voxel switches. So you can look how voxel doom did it. If my memory is correct, it is made purely in decorate (which fully supports it).
https://doomwiki.org/wiki/Doom_voxel_project
User avatar
Enjay
 
 
Posts: 26535
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Using Models as Switch

Post by Enjay »

I think it looks as if they are doing something very similar to my initial suggestion: a switchable decoration that activates its special when used.
User avatar
HAL9000
Posts: 266
Joined: Fri Mar 16, 2018 7:44 am
Contact:

Re: Using Models as Switch

Post by HAL9000 »

@Enjay, Its working like a charm :D, Thanks
Image
Image

What other states can i use with Switch actor? Just curious...
Attachments
Zrift-Switch03-Testmap.pk3
Here is the file:
(74.75 KiB) Downloaded 35 times
User avatar
Enjay
 
 
Posts: 26535
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Using Models as Switch

Post by Enjay »

Nice.

I'm sure you are aware but the off-to-on animation shows the lever moving smoothly through its arc. The on-to-off animation just snaps back to the off position. You can, of course, set it up to have a smooth animation in both directions.
User avatar
HAL9000
Posts: 266
Joined: Fri Mar 16, 2018 7:44 am
Contact:

Re: Using Models as Switch

Post by HAL9000 »

Enjay wrote:Nice.

I'm sure you are aware but the off-to-on animation shows the lever moving smoothly through its arc. The on-to-off animation just snaps back to the off position. You can, of course, set it up to have a smooth animation in both directions.
Yes i was trying to do that but did not figure how to do it properly.
User avatar
Enjay
 
 
Posts: 26535
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Using Models as Switch

Post by Enjay »

Basically in exactly the same way as you did for the other direction. To make it look neat you just need to make sure that you skip the animation when the switch first spawns.

[edit]
Actually, this would be better with your example.

DECORATE

Code: Select all

ACTOR ModelSwitch1 : SwitchableDecoration 
{
	Radius 16
	Height 16
	+NOGRAVITY
	+DONTSPLASH
	States
	{
	 Spawn:
	 goto Inactive +8
	 Inactive:
	    POSS IHGFEDCB 1
	    POSS A -1
	    Stop

    	Active:
    	    POSS BCDEFGHI 1
	    POSS Z -1
    	    Stop
	 }
}
No need to change the MODELDEF at all.


Forget the bit that follows this edit.
[/edit]

e.g. you could do it this way:

DECORATE

Code: Select all

ACTOR ModelSwitch1 : SwitchableDecoration 
{
	Radius 16
	Height 16
	+NOGRAVITY
	+DONTSPLASH
	States
	{
	 Spawn:
	 goto Inactive +8
	 Inactive:
	    POSS JKLMNOPQ 1
	    POSS A -1
	    Stop

    	Active:
    	    POSS BCDEFGHI 1
	    POSS Z -1
    	    Stop
	 }
}
MODELDEF

Code: Select all

Model ModelSwitch1
{ 
   Path "Models" 
   Model 0 "SWITCH03.md3" 
   Skin 0 "Switch03_redlight.png"
   Scale 0.55 0.55 0.4
   AngleOffset 90         
   PitchOffset 0		     
   RollOffset 90  	     
   
   FrameIndex POSS A 0 0
}


Model ModelSwitch1
{ 
   Path "Models" 
   Model 0 "SWITCH03.md3" 
   Skin 0 "Switch03_nolight.png"
   Scale 0.55 0.55 0.4
   AngleOffset 90         
   PitchOffset 0		     
   RollOffset 90  	     
   
   FrameIndex POSS B 0 1
   FrameIndex POSS C 0 2
   FrameIndex POSS D 0 3
   FrameIndex POSS E 0 4
   FrameIndex POSS F 0 5
   FrameIndex POSS G 0 6
   FrameIndex POSS H 0 7
   FrameIndex POSS I 0 8
}


Model ModelSwitch1
{ 
   Path "Models" 
   Model 0 "SWITCH03.md3" 
   Skin 0 "Switch03_light.png"
   Scale 0.55 0.55 0.4
   AngleOffset 90         
   PitchOffset 0		     
   RollOffset 90  	
   
   FrameIndex POSS Z 0 9
   
   FrameIndex POSS J 0 8
   FrameIndex POSS K 0 7
   FrameIndex POSS L 0 6
   FrameIndex POSS M 0 5
   FrameIndex POSS N 0 4
   FrameIndex POSS O 0 3
   FrameIndex POSS P 0 2
   FrameIndex POSS Q 0 1
}
It would probably need a bit of tweaking but replacing your DECORATE and MODELDEF with that has the switch working in both directions.
User avatar
HAL9000
Posts: 266
Joined: Fri Mar 16, 2018 7:44 am
Contact:

Re: Using Models as Switch

Post by HAL9000 »

Got it, Thanks !
Working like a charm
Attachments
Zrift-Switch03-Testmap-Rev1.pk3
(75.07 KiB) Downloaded 30 times
User avatar
lulle
Posts: 152
Joined: Fri May 06, 2022 9:39 pm
Location: Germany

Re: Using Models as Switch

Post by lulle »

Hi,
the switch is cool, but...

I fixed some more issues to make it easier to work with:
-fixed x,y,z offsets and removed lines from modeldef
-scaled to 50%
-added Icon
-changed frames from POSS to SWT3

No more fiddling around in Doombuilder, just stick the switch to the wall and done. Bonus: Nice Icon :lol:

Tnx for starting this threat, it always helps a lot!

Info: Testmapfixed and pulled out of pk3
Attachments
MAP01.wad
(6.22 KiB) Downloaded 20 times
SWITCH03Rev2.pk3
(145.61 KiB) Downloaded 24 times
ss2.jpg
Post Reply

Return to “Scripting”