This is the test for my ideas I mentioned earlier. Aleph One doesn't even want to make it seem to work, so I figure there's a stupid mistake in here somewhere, I'm just not experienced or knowledgeable to see where it is.

Code: Select all

```
Triggers = {}
--Mnemonic Definitions
--Scenery
--Security Monitor (c22s12): Hinged Door
SceneryTypes["security monitor"] = "hinged door"
--Init Routines
function Triggers.init()
for p in Players() do
p.overlays[0].text = "Hinged Door Test Active"
end
for s in Scenery() do
if s.type == "hinged door" then
s._is_door = true
Set_Hinge(s)
end
end
end
--Idle Routines
function Triggers.idle()
if Players[0].action_flags.action_trigger then
Players.print("You just pressed the action key at something.")
local o, x, y, z, polygon = Players[0]:find_target()
if is_scenery(o) then
Players.print("Ok, it's scenery.")
Check_Object_Type(o)
end
end
for s in Scenery() do
if s._is_door and s._is_moving then
if s._direction == opening then
if s.facing < s._objective_angle then
s.facing = s.facing + 1
local dx = s._hinge_x + (math.cos(math.rad(s.facing) * 0.25)
local dy = s._hinge_y + (math.sin(math.rad(s.facing) * 0.25)
s:position(dx, dy, s.z, s.polygon)
else
s._is_moving = false
end
else
if s.facing > s._objective_angle then
s.facing = s.facing - 1
local dx = s._hinge_x + (math.cos(math.rad(s.facing) * 0.25)
local dy = s._hinge_y + (math.sin(math.rad(s.facing) * 0.25)
s:position(dx, dy, s.z, s.polygon)
else
s._is_moving = false
end
end
end
end
end
--This determines the x,y coordinates of where the door's hinge will be, depending on the door's starting position
function Set_Hinge(target)
local hx = math.cos(math.rad(target.facing + 180) * 0.25
local hy = math.sin(math.rad(target.facing + 180) * 0.25
target._hinge_x = hx + target.x
target._hinge_y = hy + target.y
end
--This makes sure that it's a door we're opening.
--For later use, this will also determine if it is any other kind of interactive scenery, such as a terminal.
function Check_Object_Type(target)
if target.type == "hinged door" then
Players.print("Ok, it's a hinged door. Let's open it.")
Open_Door(target)
end
end
--This toggles the door's status.
function Open_Door(target)
if target._is_open then
target._direction = closing
target._objective_angle = target.facing - 90
else
target._direction = opening
target._objective_angle = target.facing + 90
end
target._is_moving = true
end
```