2022-01-17 04:09:27 +00:00
|
|
|
// Electric Door
|
|
|
|
|
|
|
|
let animating = false;
|
|
|
|
let opened = false;
|
|
|
|
let powerState = false;
|
2021-03-31 06:33:25 +00:00
|
|
|
|
|
|
|
// Function to handle the door opening or closing.
|
|
|
|
function setPoweredState(powered) {
|
|
|
|
powerState = powered;
|
|
|
|
|
|
|
|
if (powered) {
|
|
|
|
if (animating || opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
animating = true;
|
2022-02-20 19:48:36 +00:00
|
|
|
opened = true;
|
2021-03-31 06:33:25 +00:00
|
|
|
Sound.Play("electric-door.wav")
|
2022-01-17 04:09:27 +00:00
|
|
|
Self.PlayAnimation("open", () => {
|
2021-03-31 06:33:25 +00:00
|
|
|
animating = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
animating = true;
|
|
|
|
Sound.Play("electric-door.wav")
|
2022-01-17 04:09:27 +00:00
|
|
|
Self.PlayAnimation("close", () => {
|
2021-03-31 06:33:25 +00:00
|
|
|
opened = false;
|
|
|
|
animating = false;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 01:15:05 +00:00
|
|
|
function main() {
|
2019-05-07 05:57:32 +00:00
|
|
|
Self.AddAnimation("open", 100, [0, 1, 2, 3]);
|
|
|
|
Self.AddAnimation("close", 100, [3, 2, 1, 0]);
|
2021-03-31 06:33:25 +00:00
|
|
|
|
2020-12-30 01:24:42 +00:00
|
|
|
Self.SetHitbox(0, 0, 34, 76);
|
2019-06-24 00:30:12 +00:00
|
|
|
|
2021-03-31 06:33:25 +00:00
|
|
|
// A linked Switch that activates the door will send the Toggle signal
|
|
|
|
// immediately before the Power signal. The door can just invert its
|
|
|
|
// state on this signal, and ignore the very next Power signal. Ordinary
|
|
|
|
// power sources like Buttons will work as normal, as they emit only a power
|
|
|
|
// signal.
|
2022-01-17 04:09:27 +00:00
|
|
|
let ignoreNextPower = false;
|
|
|
|
Message.Subscribe("switch:toggle", (powered) => {
|
2021-03-31 06:33:25 +00:00
|
|
|
ignoreNextPower = true;
|
|
|
|
setPoweredState(!powerState);
|
|
|
|
})
|
2019-04-19 01:15:05 +00:00
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
Message.Subscribe("power", (powered) => {
|
2021-03-31 06:33:25 +00:00
|
|
|
if (ignoreNextPower) {
|
|
|
|
ignoreNextPower = false;
|
|
|
|
return;
|
2019-06-24 00:30:12 +00:00
|
|
|
}
|
2021-03-31 06:33:25 +00:00
|
|
|
|
|
|
|
setPoweredState(powered);
|
2019-06-24 00:30:12 +00:00
|
|
|
});
|
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
Events.OnCollide((e) => {
|
2019-06-24 00:30:12 +00:00
|
|
|
if (e.InHitbox) {
|
|
|
|
if (!opened) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-07 05:57:32 +00:00
|
|
|
}
|
2019-06-24 00:30:12 +00:00
|
|
|
});
|
2019-04-19 01:15:05 +00:00
|
|
|
}
|