Jump to content

Auto closing door script


Rumpiraten

Recommended Posts

Hmm nope I was wrong, it's still semi random, any tips on how to fix that? :)

 

Uhm... It OUGHTN'T be semi-random. At least no more random than your framerate in the area. Unless you're running a mod that plays with the GameTimeMultiplier settings.

 

If not, then it could be that your framerate's fluctuating wildly. That GameMode block means the script executes every frame. If you're dropping to 15 or 10 frames per second the next tick after the timer cleans out could take a perceptible length of time.

 

As for the switch, you can call the animation on it if you know what it is. Make it persistent and link the door to it as a linked reference, then use GetLinkedRef and PlayGroup or maybe PlayForward/PlayBackward. I'm too lazy and honestly don't care enough to try and hunt it down for you, but you can look at the pickable activator scripts to see how it would work.

 

.

Link to comment
Share on other sites

Uhm... It OUGHTN'T be semi-random. At least no more random than your framerate in the area. Unless you're running a mod that plays with the GameTimeMultiplier settings.

 

If not, then it could be that your framerate's fluctuating wildly. That GameMode block means the script executes every frame. If you're dropping to 15 or 10 frames per second the next tick after the timer cleans out could take a perceptible length of time.

 

Yeah a good ol' fashioned reboot, and closing all other programs helped with the randomness, my bad :)

 

As for the switch, you can call the animation on it if you know what it is. Make it persistent and link the door to it as a linked reference, then use GetLinkedRef and PlayGroup or maybe PlayForward/PlayBackward. I'm too lazy and honestly don't care enough to try and hunt it down for you, but you can look at the pickable activator scripts to see how it would work.

 

Haha fair enough man, I'll see if I can figure something out with the switch animation, if not, oh well, it's just a minor detail :)

Thanks once again, I appreciate all your help :)

Link to comment
Share on other sites

Well, the FPS thing was a guess. I've thought of two other things that could be causing the issue. The auto-close script might not be resetting fTick as it should be, or the door is reporting it's state as 'open' somewhat randomly.

 

To go a little further with this, I need to know how your switch works. Is the switch scripted, or are you just using an activate parent? If it's scripted, please post the switch script, and also please post the exact door script you're using. And we'll see... what we can see.

Link to comment
Share on other sites

I think you guys are doing it the hard way...

Put a trigger around the door, with a script on the trigger:

 

 

Begin OnTriggerEnter Player

doorref.setopenstate 1

End

 

Begin OnTriggerLeave Player

dorrref.setopenstate 0

End

 

This will open the door when the player gets close and close it behind him.

 

I intentionally did not put in code box, it is just an outline.

If you have lots of doors, you will probably want to set set up linked refs first.

Link to comment
Share on other sites

Hey again.

 

The script I'm using on my switch is this

 

SCN 00HiddenDoorScript

Ref MyLink

Begin OnActivate

Set MyLink to GetLinkedRef

If MyLink.GetOpenState == 3

MyLink.SetOpenState 1
Activate

ElseIf MyLink.GetOpenState == 1

MyLink.SetOpenState 0
Activate

EndIf

END

 

And for the door I'm currently using this one

 

scn 00DummyDoorAutoClose

ref rMe
float fTick

Begin onLoad

       Set rMe to GetSelf

end

Begin GameMode

       if rMe.GetOpenState
               Set fTick to fTick + GetSecondsPassed
               if fTick > 5
                       Set fTick to 0
                       rMe.SetOpenState 0
               endIf
       endIf

end

 

Hehe thanks for the suggestion Quetzlsacatanango, that does seem a lot less complicated, but I would really like it, if I could get the door to just auto close after 3 seconds or so.

I've got a nice little switch on a desk, sorta like an alarm button in a bank, that I would very much like to keep :)

Edited by Rumpiraten
Link to comment
Share on other sites

Guest Messenjah

Or you could just do a combination of things.

 

 

The poster above is referring to trigger activator.... not just a normal activator. It is basically an invisible box that detects if the player is inside of it or not and triggers depending if the player enters it, is currently inside of it, or has recently left it.

 

So, OnTriggerLeave only detects if the player has been inside the trigger and has moved outside of the trigger box area. When this happens, it will run whatever script is attached to it song long as it is an OBJECT script.

 

Then just tell the OnTriggerLeave event to open the door if it is closed when the player leaves the trigger box.

 

Now, just set your normal activate script on your activator button on the desk.

 

This works much nicer because that way, the door doesn't keep closing while you are trying to access whatever is behind the door but WILL close when you walk away from it. :)

 

So you would put this on your trigger box:

scn TriggerActivatorSCRIPT

begin OnTriggerLeave
doorref.setopenstate 0
End

 

doorref would be whatever reference name you gave your door. Also, make sure that you tick the checkbox on your in-game door for "persistent reference."

 

Now, for your button activator:

 

scn SecretDoorActivatorSCRIPT

ref linked

begin OnActivate

set linked to GetLinkedRef

if linked.getopenstate == 3
linked.setopenstate 1
else
Return
endif
End

Edited by Messenjah
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...