Jump to content

Trouble locking/unlocking a chest!


PkSanTi

Recommended Posts

First of all, my problem seems to be a silly one. I hope you can help me.

 

My first "real" mode (the first one I did with a level of dedication and care enough to be respected as a mod) has been finished... at least, is almost finished. There's this slight issue: in one moment, an NPC is supossed to give you a key, wich opens a chest that belongs to him and is locked on impossible level (can't be opened with picklocks). The problem is the next: if I remove that chest ownership, it doesn't get locked ever, and is important that the player can not see what's in the chest till the NPC handles you the key. But when I set the chest ownership to the NPC, though is locked, opening it when he gives you the key still counts as steeling, and I don't know what to do so is not a criminal act looking in it after you get the key.

 

I tried a script that counted if you had the key, wich, if it was true, seted the chest ownership to you too, so it wouldn't be steeling. But as soon as the ownership passes to the player, the lock disappears, so it didn't really solve the problem. Any idea is welcome.

 

Thank you in advance.

Edited by PkSanTi
Link to comment
Share on other sites

Would setting the ownership to player, but not giving the player a key before the player is supposed to see the contents work? Like, if the player owns the chest, then that is fine, but if the player does not have a key, they cannot open it even though they own it? Would what work? Even as an idea? Obviously, it would display the chest as player-owned (which could affect immersion for some people) so it would not necessarily look as neat as having the chest owned by someone else.

 

Or is there something more to the ownership of the chest... ? :unsure:

Link to comment
Share on other sites

I was thinking about setting the ownership of the chest to player originally in the Construction Set already. If that would be possible even, thinking about it, it might need the cell to also be owned by something the player is part of, etc. Hmmmm. Unless the chest were an ordinary "dungeon loot" chest that has no owner. Depends on the chest, I think.

 

About the scripted approach, have you tried forcing the lock level and open key after you have changed the ownership? There exist the Lock and SetOpenKey commands that might help, or might not. Something like:

YourChestRef.SetOwnership            ; omit Owner param to make player-owned
YourChestRef.Lock 100                ; requires key
YourChestRef.SetOpenKey YourKeyHere  ; assign the key as the one to open it

But that is just an idea, if it helps, I have not tested it (which means it might not actually help). :blush:

Edited by Contrathetix
Link to comment
Share on other sites

I do remember trying to solve the problem by scripting (I say I remember so since the chest issue came across to me several weeks ago; not being able to solve it, I continued with the rest of the mod), and I'm certain that it didn't work. But, nevertheless, I don't remember if those were the precise scripts I used, so I'll try that and let you know. Thank you!

Edited by PkSanTi
Link to comment
Share on other sites

The problem you're running into actually has to do with the way ownership is processed by the game engine. If something that can be locked (such as a container or door) is owned by the Player or an NPC, the owner will be able to access it without a key regardless of lock level. That's something that can't be changed at the modder level. There is a possible workaround, but it requires a few steps:

 

1. Place two unique chests in the cell; one owned by the NPC and the other without ownership of any kind.

2. Make both chests persistent references with their own unique RefIDs and set the Player's chest to "Initially disabled" (I'll use PkNpcChestRef and PkPlayerChestRTef as examples, but you can choose whatever you want for a RefID as long as it's unique).

3.Add a script to the key that will disable the NPC's chest, enable the Player's chest, and copy everything in the NPC's chest to the Player's chest once the Player is given the key. The script itself should look like this:

scn PkStanTiKeyScript
 
Short DoOnce
 
Begin OnAdd Player ; this block will only run when the key is added to the Player's inventory
 
  If DoOnce == 0
 
    PkNpcChestRef.DuplicateAllItems PkPlayerChestRef
    PkNpcChestRef.Disable 
    PkPlayerChestRef.Enable
    Set DoOnce to 1
 
  EndIf
 
End

That should fix the "stealing" problem (as long as the cell isn't owned by anyone) while also requiring the player to have the key in order to open it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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