How do I script this door to unlock with a key?

Post » Sat Nov 07, 2009 1:44 am

We're using these scripts for Pelagiad Expanded doors for shops and homes. The doors themselves are not locked and have no keys assigned. They are only locked because of these scripts.
What would I need to add to this script so that this door would unlock at night (between 2000 and 0800 as written) with a Key? Like, say it's midnight and the door to the mages guild is locked. Since I'm a member, I have a Mages Guild Key so I can enter at any time. I enter the door at midnight and when I leave, will it still be locked? Is there a way to script it so the door relocks itself if I leave anytime before 0800?

begin IS_Locked_Night_Mediumshort doonceif doonce != 1; day    if gamehour >= 8        if gamehour <= 20            unlock            set doonce to 1        endif    endifendifif doonce != 2; night    if gamehour < 8        lock 50        set doonce to 2    endifendifif doonce != 2; night    if gamehour > 20        lock 50        set doonce to 2    endifendifend

User avatar
Brandon Wilson
 
Posts: 3487
Joined: Sat Oct 13, 2007 1:31 am

Post » Sat Nov 07, 2009 2:53 am

Begin IS_Locked_Night_Mediumif ( GetLocked == 0 ) ; unlocked    if ( ( player->GetItemCount "key_MagesGuild" ) >= 1 ) ; do not lock        return    elseif ( Gamehour < 8 )        Lock 50    elseif ( Gamehour >= 20 )        Lock 50    endifelse ; locked    if ( ( player->GetItemCount "key_MagesGuild" ) >= 1 )        Unlock    elseif ( Gamehour >= 8 )        if ( Gamehour < 20 )            Unlock        endif    endifendifEnd

User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am

Post » Fri Nov 06, 2009 11:43 pm

Thank you. That's interesting how if I have the key in my inventory, the door will always be unlocked between those times. But if I set it on the ground, the door is locked. If I pick it back up, the door is unlocked. Which, role-play wise, makes sense. Thanks.
User avatar
Nienna garcia
 
Posts: 3407
Joined: Wed Apr 25, 2007 3:23 am


Return to III - Morrowind