This is my version of key Alcove..
1 - 1 x lever on wall and 1 x lock on wall: Lever is called (fake_lever_1) and Lock called: (KeyAlcove)
When the player uses the fake lever nothing happens ahy
**** The name KeyAlcove must be inside the object itself (ID KeyAlcove) ***
2 - 1 x door: What door you want does not matter. Mine is called: fake_library_door
3 - The lock (KeyAlcove) is connected to the Script Function: function checkKey(self)
When the right key is inserted into the Lock the fake lever is destroyed and a new lever is Spawned in it's place, which is then connected to the Door, via Script:
spawn("lever",2, 9,11,3, "bkd1") -- Spawns level at location replaces, fake_lever_1 --
:addConnector("activate", "dungeon_door_wooden_1", "toggle")
:addConnector("activate", "leverSndSet", "ActivateButtonSound")
4 - If the wrong Key is inserted into the KeyAlcove it prints a message and the wrong key can still be retrieved from the Lock. The right Key is destroyed when inserted into the KeyAlcove.
(The KeyAlcove is a custom object of course.)
This system works nicely and I am still fine tuning it. I will now be putting the lock and lever next to each other..
I hope you can understand how this system works..
--- Key Object ---
defineObject{
name = "lock_A",
class = "Alcove",
model = "mod_assets/models/wall_lock_A.fbx",
replacesWall = false,
anchorPos = vec(0.02, 1.40, -0.1),
anchorRotation = vec(-70, 90, 0),
targetPos = vec(0,1.4,-0.3),
targetSize = vec(0.5, 0.5, 0.5),
placement = "wall",
onInsertItem = function(self, item)
return ((self:getItemCount() == 0 ) and ( string.find(item.name, "_key")~=nil ))
end,
editorIcon = 8,
}
--- Script Function ---
function checkKey(self)
local alcove = findEntity("KeyAlcove")
if (alcove ~= nil)and(alcove:getItemCount()>0) then
local item for item in alcove:containedItems() do
if item.name == "brass_key" then
-----------------------------------------------------------------
--- My Functions Here --- Key inserted and does the following ---
--- Destroy Items here ---
KeyAlcove:destroy()
spawn("lock_A",2, 9,13,3, "fl1") -- Needed in case they use 2nd Brass Key --
--self:destroy() -- This will Destroy the LOCK REM THIS if you want to ---
item:destroy() -- Destroy the Key --
fake_lever_1:destroy()
Magic_Trap_2:destroy()
Fake_Library_Door_1:destroy()
spawn("lever",2, 9,11,3, "bkd1") -- Spawns level at location replaces, lever_1 --
:addConnector("activate", "dungeon_door_wooden_1", "toggle")
:addConnector("activate", "leverSndSet", "ActivateButtonSound")
-- HudPrints Here and Key lock Sounds and Fx's --
playSound("key_lock")
hudPrint("The Brass Key unlocks the lock to the door.")
-----------------------------------------------------------------
else
hudPrint("Wrong Key")
EDIT: Ohh sorry I almost forgot Credits to ArdTru for the Script and Model.. 