Product Chat (Early Access) / Using a Trigger Zone to open or close a door

Author
Message
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 10th Jul 2022 16:35
It is possible?
Julian - increasingly disillusioned and jaded
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 10th Jul 2022 16:57
Opening seems to work ok.

Doesn't close though. Would need a change to the trigger zone behaviour.
Been there, done that, got all the T-Shirts!
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 10th Jul 2022 18:38 Edited at: 10th Jul 2022 19:09
I can't even get the Trigger Zone to open the door. Also, my health HUD has suddenly started to flash green for a few seconds when the level starts.

And I can't seem to find Max's scriptbank folder to examine the stock Lua scripts.
Julian - increasingly disillusioned and jaded
PM
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 11th Jul 2022 11:44 Edited at: 11th Jul 2022 11:45
The initial green flashing hud is normal in the latest build. Something they are messing with i guess.
It depends if you have the Steam or Downloadable version of Max as to what path you look for but either way there are in the same place as classic. \ GameGuru MAX \ Files \ scriptbank \
No one ever really leaves.
PM
UNIRD12B
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd May 2014
Location: Canada
Posted: 11th Jul 2022 13:59 Edited at: 11th Jul 2022 14:03
to close the door also is quite simple..
your first ( opening ) trigger is near the closed door..
your second ( closing ) trigger is placed somewhere on the
other side of the door...
when you touch the first one..it opens
when you touch the second one ..it closes.

Don't forget you have to be in SHOOTER MODE to be able to attach the triggers...and
use the DOOR SLIDING behaviour on the chosen door and USE PHYSICS checked ON

I've used this method and know it works well and,,,easy...

UNIRD12B
Let\'s actually make something happen with this one !
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 11th Jul 2022 20:10
@ lordjulian
If you want to open/close the door you can use just 1 trigger zone.
if player in zone then open door else close door. (just pseudocode here)
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 12th Jul 2022 15:59
OK. Thanks, guys. You have given me some things to try. BTW, I am using the Steam version. I can find a folder where user-made scripts go but still searching for the stock scripts. Even doing a full PC search of *.lua didn't seem to reveal it.
Julian - increasingly disillusioned and jaded
PM
UNIRD12B
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd May 2014
Location: Canada
Posted: 12th Jul 2022 16:52
try this place....

D:\Steam\steamapps\common\GameGuru MAX\Files\scriptbank

UNIRD12B
Let\'s actually make something happen with this one !
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 12th Jul 2022 18:02 Edited at: 12th Jul 2022 18:06
The Steam location only has this.

BTW, I just tried the trigger zone with a sliding door. This does indeed work. The trouble is, my house has rotating doors.
Julian - increasingly disillusioned and jaded
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 12th Jul 2022 18:22
I suspect this is the file location. But I can't seem to find it.
Julian - increasingly disillusioned and jaded
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 12th Jul 2022 20:44
I found the scriptbank, finally. I was looking at the wrong bally drive!

Anyway, I have been looking through the sliding door script. I am not much good at Lua and I can't identify anything in that allows it to be linked to a Trigger Zone.
Julian - increasingly disillusioned and jaded
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Jul 2022 13:15
When you link something to an entity, say a switch to a door, then when the switch is used it sets the 'activated' flag in the door.

The sliding door script triggers from the activated flag IIRC, although check the behaviour settings as you may need to set the door type first.
Been there, done that, got all the T-Shirts!
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 13th Jul 2022 18:32
Thanks. Do I need to edit the Trigger Zone script to activate the flag?
Julian - increasingly disillusioned and jaded
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Jul 2022 20:06 Edited at: 13th Jul 2022 20:09
The default trigger zone is a one shot deal (i.e. it destroys itself after use).

So the same default zone can't open and close a door.

All three door scripts really need to honour the activated state though.

btw, what exactly are you trying to achieve? The Auto setting for the sliding door will open the door when the player is within a certain range and close it automatically when the player is beyond that range. (Star trek door effect I call it) Again that needs to be copied to the other door behaviours.
Been there, done that, got all the T-Shirts!
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 13th Jul 2022 20:20
It's a haunted house where I want a door to open by itself when the players enters a trigger zone.

I have kind of got it working. I just added RotateY(e,600) to the sliding door script. The door instantly completes the rotation when triggered but that's OK because the door won't be in view when triggered or might be nearly out of sight.

Weird stuff happens when the player manually opens or closes the door so I need to fix that somehow.
Julian - increasingly disillusioned and jaded
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Jul 2022 20:41
Try this one
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 14th Jul 2022 00:00
Quote: "Try this one"

Top Notch as usual Amen
No one ever really leaves.
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 14th Jul 2022 19:58
Thanks very much AmenMoses. At first, the script spewed an error message, complaining about attempting to do maths with a field of nil value, namely 'period'. I tried: if period == nil then period = 0 end

The problem persisted so I tried replacing 'period' with an actual number.

Now it works but I think I need to tweak the degree of rotation.

Nice work there! You might want to consider having it added to the stock behaviors.
Julian - increasingly disillusioned and jaded
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Jul 2022 20:18
That's because you replaced a script that was already called door_rotate.

When you do that you have to save it and restart MAX before it will pick up the new behaviours settings properly.

Then you can simply go set the period in the behaviours pane, the default should be 3 seconds.

It will rotate 90 degrees, as it is a door.
Been there, done that, got all the T-Shirts!
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 14th Jul 2022 21:40
Oh, cool. Thanks. I'm glad you told me because I just tested my workaround again and it's messed up.
Julian - increasingly disillusioned and jaded
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 14th Jul 2022 22:54
I really appreciate your help. Doubtless, I am being very thick, but I tried your instruction and still got the Lua error message.
So I decided to try changing the filename (and, of course, the init_ and main_):


-- Filename changed to door_rotate_triggered.lua
local Q = require "scriptbank\\quatlib"
local U = require "scriptbank\\utillib"

local deg = math.deg
local rad = math.rad

local doors = {}

-- DESCRIPTION: Rotates a non-animating door.
-- DESCRIPTION: Hinge type [@TYP=1(1=Right,2=Left)]
-- DESCRIPTION: Opening time (seconds) [Period#=3]
-- DESCRIPTION: When the door is opening, play <Sound1> and when closing, play <Sound2>.

local hingeTypes = {'left','right'}
function door_rotate_properties( e, typ, period )
local door = doors[ e ]
if door == nil then return end
door.hinge = hingeTypes[ typ ]
door.period = period * 1000 / 20
end

local keyPressed = false

function door_rotate_triggered_init( e )
doors[ e ] ={ state = 'init' }
end

local function rotateDoor( e, door )
local rotAng = door.angle
if door.hinge == 'right' then rotAng = -rotAng end
local rotq = Q.FromEuler( 0, rad( rotAng ), 0 )
local ax, ay, az = Q.ToEuler( Q.Mul( door.quat, rotq ) )
CollisionOff( e )
ResetRotation( e, deg( ax ), deg( ay ), deg( az ) )
CollisionOn( e )
end

local timeLastFrame = nil
local timeDiff = 1
local controlEnt = nil

function door_rotate_triggered_main( e )
local door = doors[ e ]
if door == nil then return end

local Ent = g_Entity[ e ]

if controlEnt == nil then controlEnt = e end

local timeThisFrame = g_Time

if controlEnt == e then
if timeLastFrame == nil then
timeLastFrame = timeThisFrame
timeDiff = 1
else
timeDiff = ( timeThisFrame - timeLastFrame ) / 20
timeLastFrame = timeThisFrame
end
end

if door.state == 'init' then
local x, y, z, ax, ay, az = GetObjectPosAng( Ent.obj )
door.obj = Ent.obj
door.timer = math.huge
door.quat = Q.FromEuler( rad( ax ), rad( ay ), rad( az ) )
door.origx = Ent.x
door.origy = Ent.y
door.origz = Ent.z
door.actvd = Ent.activated == 1
door.rInc = 90 / door.period
if door.actvd then
door.angle = 90
door.state = 'open'
rotateDoor( e, door )
else
door.angle = 0
door.state = 'closed'
RDBlockNavMesh( door.origx, door.origy, door.origz, 30, 1 )
end

elseif
door.state == 'closed' then
if Ent.activated == 1 then
door.state = 'opening'
PlaySound( e, 1 )

elseif
U.PlayerLookingNear( e, 100, 140 ) then
-- looking at door so prompt
Prompt( "Press E to open door" )
if g_KeyPressE == 1 then
PlaySound( e, 1 )
door.state = 'opening'
keyPressed = true
end
end

elseif
door.state == 'open' then
if Ent.activated == 0 then
door.state = 'closing'
PlaySound( e, 2 )

elseif
U.PlayerLookingNear( e, 100, 140 ) then
Prompt( "Press E to close door" )
if g_KeyPressE == 1 then
door.state = 'closing'
keyPressed = true
PlaySound( e, 2 )
end
end

elseif
door.state == 'opening' then
if door.angle < 90 then
door.angle = door.angle + door.rInc * timeDiff
rotateDoor( e, door )
else
door.state = 'open'
SetEntityActivated( e, 1 )
RDBlockNavMesh( door.origx, door.origy, door.origz, 30, 0 )
end

elseif
door.state == 'closing' then
if door.angle > 0 then
door.angle = door.angle - door.rInc * timeDiff
rotateDoor( e, door )
else
door.state = 'closed'
SetEntityActivated( e, 0 )
RDBlockNavMesh( door.origx, door.origy, door.origz, 30, 1 )
end
end
end


Apologies... the forum Code>Lua function won't seem to work for me.

I also tried copying the script to the folder of the stock behavior scripts, but the result was the same,
Julian - increasingly disillusioned and jaded
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Jul 2022 16:12
It was clashing with the stock one, even though it was in a different folder. Grrr.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 16th Jul 2022 09:23
Quote: "So I decided to try changing the filename (and, of course, the init_ and main_):"

Quote: "function door_rotate_properties( e, typ, period )"

in max you also need to change the properties function name
(and ideally you would have a main list that is called the same (i.e. g_door_rotate_triggered = {} ) which you would also want to rename)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 16th Jul 2022 12:36
MAX doesn't seem to refresh the dynamic Lua doodads when you change to a different script with the same name.

So for example in my local file I have a my_objects folder into which I copy the stock scripts and edit them.
Then in MAX I will select the behaviour from that folder and all is well on an empty level ... but if the level is already using the stock version (from the objects folder) and even if I select the new one the dynamic Lua doodads shown will be for the old script, even though the properties function used is for the new behaviour!

Just another MAX 'feature' to get in the way of productivity.

Only reason I didn't really notice this before is that I usually create a new level every time I test a script.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 16th Jul 2022 17:52 Edited at: 16th Jul 2022 17:53
Try this one:

When in 'slide' mode the angle and distance work as they did before, when in 'rotate' mode the angle specifies the angle of rotation and distance does nothing.
I've changed some of the behaviour value names to be more obvious as to what they do (e.g. "Opening Time" rather than period.
So now you can have rotating doors that do all the stuff that sliding ones did before, i.e. in 'Auto' they trigger from player proximity only, 'DelayedClose' means that after triggering from a switch or whatever the door will stay open a specified time and then close again etc.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
lordjulian
10
Years of Service
User Offline
Joined: 10th Jan 2014
Location:
Posted: 16th Jul 2022 19:52
Wow! That's great. Thanks!
Julian - increasingly disillusioned and jaded
PM
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 16th Jul 2022 20:10
@AmenMoses
Perfection !!
The ultimate door script. No other is needed as it covers pretty much everything.
Sliding or Rotating, Left or right Hinges, Totally blown away mate.
No one ever really leaves.
PM

Login to post a reply

Server time is: 2024-12-21 17:58:03
Your offset time is: 2024-12-21 17:58:03