[Solved!] Want to make a chest openable with a key
[Solved!] Want to make a chest openable with a key
I would like to make a chest that has to be opened with a key instead of lock picks. I am quickly running into problems.
I see ChestComponet already has a lock component on it but it gives no options in the editor to customize it. So I thought to define a LockComponent of my own on it. That actually worked to a point in that it recognizes only using the correct key unlocks. But when I try to unlock it, it blows up.
Looks like I need to define animations here but I really don't know how or what to define. Being able to re-use the chest opening animation for a lock pick is perfectly fine by me if I knew how to use it. Does anyone know much about how to do this? Or am I out of luck until the asset definition comes out.
Thanks
I see ChestComponet already has a lock component on it but it gives no options in the editor to customize it. So I thought to define a LockComponent of my own on it. That actually worked to a point in that it recognizes only using the correct key unlocks. But when I try to unlock it, it blows up.
Looks like I need to define animations here but I really don't know how or what to define. Being able to re-use the chest opening animation for a lock pick is perfectly fine by me if I knew how to use it. Does anyone know much about how to do this? Or am I out of luck until the asset definition comes out.
Thanks
Last edited by MrChoke on Tue Nov 18, 2014 1:52 am, edited 1 time in total.
Re: Want to make a chest openable with a key
You add something like
Edit: There seems to be more quirks to work out... This was alot trickier than i thought... ill have a look later..
Edit2: The above sortof works.. trouble is you cant interact with anything in the chest, even if you unlock it with a regular lockpick... Hell even if you leave it totally unlocked. The surface just doesn't react. (There is some magic ingame code to disable and enable a Surface inside the chest). Even tried manually manipulating it through the console.
Code: Select all
defineObject {
name = "chest_padlocked",
baseObject = "chest",
components = {
{
class = "Lock",
name = "keylock",
openedBy = "iron_key",
onActivate = function(self)
self.go.chest:setLocked(false)
self.go.animation:stop()
end,
},
{
class = "Animation",
animations = {
lock = "assets/animations/env/treasure_chest_open.fbx",
open = "assets/animations/env/treasure_chest_open.fbx",
close = "assets/animations/env/treasure_chest_close.fbx",
}
},
}
}
Edit2: The above sortof works.. trouble is you cant interact with anything in the chest, even if you unlock it with a regular lockpick... Hell even if you leave it totally unlocked. The surface just doesn't react. (There is some magic ingame code to disable and enable a Surface inside the chest). Even tried manually manipulating it through the console.
Links to my YouTube playlist of "tutorials" and to my forum thread.
Re: Want to make a chest openable with a key
This is how I did it for my dungeon, though I'm pretty sure it would also be opened with a lockpick so you might have to figure out a way to disable that.
A connector that runs a function onClick, in this case the function unlockChest() in my library script
and the function:
That'll unlock the chest and delete the iron key in hand.
A connector that runs a function onClick, in this case the function unlockChest() in my library script
Code: Select all
spawn("chest",level_index, herei, herej, 0, 0, chest_ID).clickable:addConnector("onClick", "library", "unlockChest")
Code: Select all
function unlockChest(entity)
if getMouseItem() ~= nil then
if entity.go.chest:getLocked() and getMouseItem().go.name == "iron_key" then
setMouseItem()
entity.go.chest:setLocked(false)
end
end
end
Re: Want to make a chest openable with a key
Prozail, your code almost worked, just rename the keylock to lock.
It had 2 lock (lock and keylock) components so that's why it didn't work.
Code: Select all
defineObject {
name = "chest_padlocked",
baseObject = "chest",
components = {
{
class = "Lock",
name = "lock",
openedBy = "iron_key",
onActivate = function(self)
self.go.chest:setLocked(false)
self.go.animation:stop()
end,
},
{
class = "Animation",
animations = {
lock = "assets/animations/env/treasure_chest_open.fbx",
open = "assets/animations/env/treasure_chest_open.fbx",
close = "assets/animations/env/treasure_chest_close.fbx",
}
},
}
}
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: Want to make a chest openable with a key
Thanks for your help. I thought it would be easy to do. I see I am not the only one who found this not so easy.
@JKos, your solution looks almost exactly like mine and it didn't work right... let me try yours out though. Maybe I am missing something.
@Scotty, I couldn't get Clickable to override for a chest. Even when I used the exact same offset and size as the original one. I tried override in defineObject though, not with addConnector(). That must be why.
Also at @Scotty. I played your dungeon a bit. Nice! You know we are going to be competing right?
@JKos, your solution looks almost exactly like mine and it didn't work right... let me try yours out though. Maybe I am missing something.
@Scotty, I couldn't get Clickable to override for a chest. Even when I used the exact same offset and size as the original one. I tried override in defineObject though, not with addConnector(). That must be why.
Also at @Scotty. I played your dungeon a bit. Nice! You know we are going to be competing right?
Re: Want to make a chest openable with a key
Game on!Also at @Scotty. I played your dungeon a bit. Nice! You know we are going to be competing right?
Re: Want to make a chest openable with a key
It was not my solution but Prozail's, so credits to him I just happened to notice that he didn't overwrite the default lock-component. And I tested it and it seemed to work pretty well, but it can still be opened with lock-picks too, so some fine tuning may be needed.MrChoke wrote: @JKos, your solution looks almost exactly like mine and it didn't work right... let me try yours out though. Maybe I am missing something.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: Want to make a chest openable with a key
I was actually consciously avoiding to remove the lock-Component as it is a Model (the lock on the chest) that gets disabled when you unlock it.
But your solution works! And why? Because the normal chesthandler CALLS DISABLE ON THE LOCK when it gets unlocked...
But your solution works! And why? Because the normal chesthandler CALLS DISABLE ON THE LOCK when it gets unlocked...
Links to my YouTube playlist of "tutorials" and to my forum thread.
Re: Want to make a chest openable with a key
Yeah, I had the exact same thing you had, except I typed "onActivated" and not "onActivate" for the lock hook. Sigh.JKos wrote:It was not my solution but Prozail's, so credits to him I just happened to notice that he didn't overwrite the default lock-component. And I tested it and it seemed to work pretty well, but it can still be opened with lock-picks too, so some fine tuning may be needed.MrChoke wrote: @JKos, your solution looks almost exactly like mine and it didn't work right... let me try yours out though. Maybe I am missing something.
A minor thing with the solution is the chest doesn't unlock first, it goes straight to open. With lock picks, first you unlock it, then you click to open it. This is minor though. Who wouldn't want to look into the chest right away anyway!
The lock picks still work though. Hmmmm... I guess I could always just remove them from my dungeon. I may not want them anyway. Still wish we can get this thing to work 100%
Re: Want to make a chest openable with a key
Ok.. this is getting wierd
The code below will work fine, as long as you DONT unlock it with a lockpick.. then it bug's out (as the lock-Component doesn't get removed, and then you cant click stuff in the chest)... If you use a key its fine, but the native click-event still fires, and types "Locked." on the hud.
It's basically the same as my first one (where i dont override the "lock") but here i remove the LockComponent after it has triggered.
Problem is the click-event can't be replaced, because it does things that are not available through the modding-script-Engine at this time. (onBeginMouseLook etc)
tbh... if i was to implement it, i would prob. use scotty's version of just putting a custom click-event after the original one.
The code below will work fine, as long as you DONT unlock it with a lockpick.. then it bug's out (as the lock-Component doesn't get removed, and then you cant click stuff in the chest)... If you use a key its fine, but the native click-event still fires, and types "Locked." on the hud.
It's basically the same as my first one (where i dont override the "lock") but here i remove the LockComponent after it has triggered.
Problem is the click-event can't be replaced, because it does things that are not available through the modding-script-Engine at this time. (onBeginMouseLook etc)
Code: Select all
defineObject {
name = "chest_padlocked",
baseObject = "chest",
components = {
{
class = "Lock",
name = "keylock",
openedBy = "iron_key",
onActivate = function(self)
self.go.chest:setLocked(false)
self.go.animation:stop()
self.go:removeComponent("keylock")
end,
},
{
class = "Animation",
animations = {
lock = "assets/animations/env/treasure_chest_open.fbx",
open = "assets/animations/env/treasure_chest_open.fbx",
close = "assets/animations/env/treasure_chest_close.fbx",
}
},
}
}
Links to my YouTube playlist of "tutorials" and to my forum thread.