Timed door EXP2

From GMod Wiki

Jump to: navigation, search



Contents

Expression 2 Timed Door

Timed door EXP2: Expression 2 Timed Door
Page white text.png Description:Pressing a button will open a door for a set time, then it will close.
User.png Original Author:snipeissilent
Calendar.png Created:30 June 2010
Page white text.png Notes:You can switch the button with a wired keypad, or have two buttons.


This tutorial will teach you how to make a simple timed door using Expression 2 that will open when a button is pressed, and then close on its own.

Materials

1. Door (I use a PHX 2x2 plate ball socketed to another plate on one side so it swings freely)
2. Expression 2 chip
3. Wired hydraulic (not fixed)
4. Non-toggled wire button

Instructions

1. Place the button where you want.
2. Place the Hydraulic between the door frame and the door so it opens in the direction you want.
3. Place the E2 chip somewhere. The code should be:


Expression 2 Code

@name Timed Door
@inputs Button
@outputs Hydraulic
if(Button)
{
Hydraulic=100
timer("door", 2000)
}
if(clk("door")) {Hydraulic=0}

Wiring

1. Wire the hydraulic to the E2 chip.
2. Wire E2 "Button" to your wired button.

Modifications

1. To make the door open by pressing one of two wired buttons, make two inputs, Button1 and Button2 (delete the "Button" input).
Then, replace "if (Button)" with "if (Button1 | Button2)". The "|" is an "OR", so if you press Button1 OR Button2, the action will be carried out.

2. The time can be changed to your liking. On the line of code that says, "timer", the 2000 may be changed to any other time desired.
Note that 2000 = 2 seconds, 3000 = 3 seconds, etc. The E2 here keeps the door open for 2 seconds, but that may be increased or decreased.

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox