Jump to content

Need a script for closing a door then locking (req premade key)


RedNinja029

Recommended Posts

WORKED!!!! AMAZEBALLS For some reason it didnt save properly! +1 Awesome It functions

 

Now If possible to add a message into the activation but return in the door script along the lines of "Door activated through cardreader"?

And also Maybe one for the switch along the lines of "Keycard required" if keycard is not in inventory

 

Maybe If the Door Appeared As locked/inaccessible through the crosshair as an added bonus but the main is achieved so far.

Edited by RedNinja029
Link to comment
Share on other sites

Fantastic.

 

So, it took me a moment but I realised you named the script and the switch/door IDs identically. You can't do that. So, typically, a naming convention many people at least loosely follow involves naming the object something like BunkerDoor1, an attached script BunkerDoor1Script, a relevant quest (which we narrowly avoided needing here) BunkerDoor1Quest, and the script for the quest BunkerDoor1QuestScript. Make sense? Nothing can share an ID with anything else. Two objects with the same 'name' is grand, but not the same ID.

 

So, for the door, you can just change the name to something that indicates you need to use the switch, or, similar to Vault doors, replace Return in the door script with a line of code that shows a message of your choosing. If using NVSE, you can use MessageEx and type your message right there (enclosed in quotes). If there's an OnActivate block in a script attached to an activator (doors, terminals, and anything else you can 'activate' is an activator, at least informally), it overrides the standard Activate function, so it will still block AI. Although, you should do a check to make sure it's the player once you go this route (so AI don't trigger the message), and if it is not the player, you can put Return for that condition. Use IsActionRef for this, as the way it was intended to work is bugged.

 

For the switch, you can make a dummy version with a different prompt, have it show a message when activated based on conditions like a GetItemCount for the key, or if using JIP LN, change the prompt with an OnAdd block in a script attached to the key.

 

Edit: Link to the wiki entry on MessageEx, as well as an excuse to tell you to make sure you use this wiki or the technodeep one (they're identical), and not the old Bethesda one. These are up to date, and the Bethesda one is not.

https://geckwiki.com/index.php/MessageEx

Edited by EPDGaffney
Link to comment
Share on other sites

Awesome, your awesome! Another new thing I learned today, got the message working for the door. i'm going to do one for the switch message now. Well while waiting around I've made the doors inside the safehouse automatically close after about 10 seconds. I'd like to if possible add a similar function into the main switch operated doors but fear it will not work with them perhaps?

 

I'm assuming it would be attached to the door of course. Not sure if would still be possible

 

SCN BunkerDoor1REF


Float Timer


Begin OnLoad                        ; if the player left the door open the last time he was in here, close it.
    If GetOpenState == 1
        SetOpenState 0
        If GetLockLevel > 0
            Lock
        EndIf
    EndIf
End


Begin OnActivate                    
    
    Set Timer to 10            
    Return; I do remember you not to do this as it ends the rest of the script<<<<< but not sure how else to keep it functional


End


Begin GameMode
    
    If Timer > 0
        Set Timer to Timer - GetSecondsPassed
    ElseIf GetOpenState == 1
        SetOpenState 0
        Set Timer to 0
        If GetLockLevel > 0
            Lock
        EndIf
    EndIf




    If GetOpenState == 3
        Set Timer to 0
    EndIf
End

So it actually works. but it closes as soon as it opens. I got the script from elsewhere but I'm not sure how to implement the closing of the door. Thinking now maybe it would be through the switch but I cannot think of how if that is the case. Maybe somehow the switch deactivates after a set period of time if the door is not already closed hmmm not sure exactly.

 

 

As for the message in the switch, would it be along the lines of

 

SCN BunkerDoorSwitch1REF


Begin OnActivate
       If IsActionRef Player
         If player.GetItemCount BunkerKeyCard >= 0
           MessageEx "You do not have the required Key Card!"
Return ;Again not sure this is correct but not sure how else to stop the rest of the script sequence or the message displaying if I DID have the keycard
else
          If player.GetItemCount BunkerKeyCard >= 1
            BunkerDoorA.Activate Player
        EndIf
     EndIf
End

Not sure how accurate the above would be either

Link to comment
Share on other sites

Glad to see you experimenting. That's really all it is.

 

So, OnLoad is probably not a good idea in most cases, as it's not reliable. If you exit and enter the cell several times, OnLoad blocks won't be called each time. You can actually use another door or a trigger box. Say for example the door to another cell would be a good place to close the bunker door(s), you'd run an OnActivate block on the door that leaves the cell, and you'd use SetOpenState 0 as you have, but in this case be sure to make it use the bunker door as the calling reference. And then you'd have to make sure there's an Activate in there as well so that in addition to closing the other door, the door leaving the cell remains functional. A trigger box would use an OnTriggerEnter Player block and do the same. Note that you do not need to be in the same cell for SetOpenState to work.

 

Running OnActivate for your timer probably isn't the best idea for a script attached to the door, because that door doesn't actually do anything anymore. You probably want something like that attached to your switch, though I personally would probably use a quest script that I start via the switch's script and include in the quest's script a line to end the quest once it's not needed. This can be done as many times as you like. Also, I again wouldn't bother locking the door. It will only make things more complex than needed as the door is inoperable to begin with, save via the switch, which for all intents and purposes is locked.

 

Don't use Return unless you are trying to make sure literally nothing happens. The way it works is that if no script is attached to an activable object, Activate is called whenever something in the game activates that object, and it behaves as normal. However, once you attach a script with an OnActivate block, The OnActivate block completely replaces the normal functionality of the Activate event, so no door will open, no terminal will give you the terminal screen, and so on and so forth, unless you explicitly tell the game to do that via script (which is done by calling Activate from within the script).

 

I'm fairly staunch in my stance that you should sort out your naming convention now whilst you still can, so I've named your last script and its door accordingly, but you can do whatever makes you happy.

scn BunkerDoorSwitch1Script

Begin OnActivate
    If IsActionRef Player
        If player.GetItemCount BunkerKeyCard == 0
            MessageEx "You do not have the required Key Card!"
        ElseIf player.GetItemCount BunkerKeyCard >= 1
            BunkerDoor1.Activate Player
        EndIf
    EndIf
End

Note that MessageEx works only if you have NVSE, which is of course an indication not that you shouldn't use MessageEx, but that you should be using NVSE.

 

Let me know how it goes.

Edited by EPDGaffney
Link to comment
Share on other sites

Hey EPDGaffney, I'm back. Had to rest and get some sleep. I actually tried something similar before going to sleep but i put the activate in the wrong place and I can see what I did there wrong now.

 

Not sure how else id display the message without nvse but if its easier with it, then why not use it. I'll have another look at the auto door script now.

Link to comment
Share on other sites

The other method of doing messages involves making a mesage form with its own ID and all that, and then in a script calling ShowMessage for that message. It works, and is occasionally nicer to look at in the editor depending on the circumstances, but this is so much faster and easier. There are other advanced functions, like MessageBoxEx, which does message boxes similarly (but denies a few options), and MessageBoxExAlt, which is the clear winner but requires a UDF script. There's MessageExAlt as well, but I've never needed it.

 

Tell me how you get on.

Link to comment
Share on other sites

Taken me while but eventually came up with this,

 

going to try this one out now

 

Im really not sure how quest scripts work. Im completely alien to it and it sounds daunting. As if this wasnt enough for me XD

but here's what I want to try.

 

SCN BunkerDoorSwitch1Script


Float Timer


Begin OnActivate
    If IsActionRef Player
        If player.GetItemCount BunkerKeyCard == 0
            MessageEx "You do not have the required Key Card!"
        ElseIf player.GetItemCount BunkerKeyCard >= 1
            BunkerDoorA.Activate Player
Set Timer to 8
If Timer= 0
If Timer - GetSecondsPassed
BunkerDoorA.Activate ;Tried setting this to SetOpenState= 0 and still nothing. Not even saving the script


If GetOpenState == 3
Set Timer to 0


        EndIf
    EndIf
End

I Can't save the script as its telling me "Invalid If/ EndIf on line 21"

 

p.s. I Now realise what you mean by bad habits with the naming of scripts. I worked out the REF was an indication to a specific item reference ID's in the render window but thought the script would reference the other script. I see now but it was just a bit cloudy before.

Edited by RedNinja029
Link to comment
Share on other sites

Cleared my head and tried again. Came up with this

 

SCN BunkerAutoDoorScript


Float Timer


OnActivate= akActionRef
If openState = 1
Set Timer To 8

Set Timer to Timer - GetSecondsPassed

If Timer= 0
SetOpenState=0

EndIf
EndIf
End

Still Nothing error at the endif line or thereabouts

Doesn't Even Save the script

Door activated by anyone, will close itself in 10 seconds. Seems simple but not working for me other than the script you told me to avoid using for OnLoad

Edited by RedNinja029
Link to comment
Share on other sites

I have to be honest, your script is really hard to read like that, especially knowing that somewhere is a mistake, so I think you should write these scripts in the GECK or Notepad or something first, make sure you use the Tab key where applicable, and then paste it in here.

 

Basically, each indent is a 'level' of code. So, I keep Begin and End at the left, and the next level has one indent. If statements start and end at that level after Begin or End, but the code contained within an If statement is a new level and gets indented twice instead of once.

 

For nested If statements, each level of nesting gets an additional indent. This shows which lines are dependent on which other lines, and the result is any remotely complex condition checks result in a sort of right-facing horseshoe shape. This makes it really easy to see where you may have missed an EndIf or ElseIf or something, once you get an error like the one you have.

 

Right so, I tried to make sense of it after attempting to indent it correctly and it's clear that some of it has more mistakes than simply forgetting an EndIf and I'm not absolutely certain where you were going with it. First, when you set the timer to 8, I think you wanted to end that statement rather than nest another one. Second, your next line uses = instead of ==. Third, If Timer - GetSecondsPassed is confusing to me and I assume you copied and pasted or deleted something partially or whatever, as I don't think that line makes sense to yourself, either. You can use SetOpenState in the following line. That's not your problem. But look again at the documentation; it doesn't use an operator, just a peramater (meaning, SetOpenState 0, not SetOpenState == 0, and certainly not the one you have with one equality sign).

https://geckwiki.com/index.php/SetOpenState

 

A quest script does seem daunting, but it isn't. The way I would handle this is by making your switch turn on the quest via StartQuest as long as the door is not closed or closing and as long as the quest isn't running, and if the player should close the door early, the quest should then stop running (using StopQuest).

 

Then in the quest, you'd give it a low quest delay and don't tick the box for 'start game enabled'. Then you'd save your mod, then start a script that does most of what you're trying to do now with just the timer portion of your script. It's going to take a few more checks to make it nice and clean, so I'll let you have a go using all this information and then see what you come up with, as you may not need me to lay it all out at this point. (I think you made a few oversights in your above offer, not that you have absolutely no idea how this works, even if you think that's the case yourself).

 

Edit: Just seen your new post. What I've said above still stands, but this is a bit cleaner and easier to see where you were going with some of it. You are setting Timer to 8 every time the script is called, so it's never going down. You need a check for that. A lot of people use variables like DoTimer or something, set the timer to 8 (or whatever they want) only when that check is passed, and then set the variable to the value that will make the check fail.

 

Edit 2: Also, don't forget that you can always count up. I usually just do it that way, but either is fine.

Edited by EPDGaffney
Link to comment
Share on other sites

Mind blown. I understand what your saying but I'm not grasping the concept.

 

Breaking it down the 2nd script seems cleaner

 

After setting the timer to 8, How would I initiate it to countdown to 0 (I know not the first thing of even starting a quest script I wont lie probably just as much as you wouldn't understand quantum physics lol thats how alien it is to me)

 

It just seems plausible if Ive got nvse plugin to the Geck maybe its possible or easier now somehow?

you mentioned dotimer but couldnt see anything about it?

 

SCN BunkerAutoDoorScript
Float Timer


Begin OnActivate AkPlayerRef ;Also see the function of OnOpen maybe it wouldwork better I Dont know
    if timer < 10
       Set timer to timer + GetSecondsPassed
 else
    SetOpenState=4
       Set timer to 0
   endif
end

I do write these all in the Geck but I use Tab for indents it seems they dont copy over in this format here.

 

I found this source here about timers and just changed the relevancy of the door being closed to 4 (start closing)

 

not entirely sure what "Set timer ti timer + Gets Seconds Passed" does the same for if the + was a - I'm looking around reading and piecing together. Id rather keep it as simple as possible. I do presume its telling the timer to count upwards from 0 with the +

 

Not letting me save it still. NVSE Plugin isnt giving any errors but doesnt let me close the box (keeps prompting to save no matter how many times I do)

 

Source here https://forums.nexusmods.com/index.php?/topic/388933-help-understanding-timer-scripts/

 

Tried this one also (see below)

 

SCN BunkerAutoDoorScript


Float Timer


     Begin OnActivate


          Set Timer To 10


End


      Begin GameMode
    
           If Timer > 0
               Set Timer to Timer - GetSecondsPassed


     Else


           If GetOpenState == 1
                SetOpenState 0
                     Set Timer to 0


        EndIf
    EndIf


    If GetOpenState == 3
        Set Timer to 0
    EndIf
End

But it doesn't work, the doors don't even open, tried all 4 doors running the script and nada, none of them work.

Edited by RedNinja029
Link to comment
Share on other sites

  • Recently Browsing   0 members

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