[Mod-Assets] Keys in locks. (re-usable keys)

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
spectre900
Posts: 124
Joined: Fri Sep 14, 2012 1:47 am

[Mod-Assets] Keys in locks. (re-usable keys)

Post by spectre900 »

So after a bit of fiddling I managed to convert my old mod to G2.

What this mod does is enable keys in custom dungeons to be visually put inside locks and then be taken out again without consuming the key. If you have ever played Dungeon Master 2 then you know what I mean.

Image

How to install/use:
SpoilerShow
1) Extracts files into your mod folder.

2) Add this line to your "init.lua" file found in: mod_assets/scripts

Code: Select all

import "mod_assets/scripts/keys_in_locks.lua"
3) To make a key click sound add the following lines in a cript entity on your map and link your locks to it.

Code: Select all

function playLock()
   playSound("key_lock")
end

--hints--

> B locks are used for wallsets with deeper "depth" to them such as the castle walls.
> The door locks fits best on dungeon doors and some mine doors.
> Use the lock_stone if you can't find a good surface to place your locks on.

--You may use and edit this mod in any way you like. crediting is not necessary but would be nice. --
Dropbox Download: https://www.dropbox.com/s/p1n6qqbh6zsks ... 2.rar?dl=0

This mod for Grimrock 1:
viewtopic.php?f=14&t=6469

If you find any problems please report them to me.
Last edited by spectre900 on Wed Jun 10, 2015 10:34 pm, edited 1 time in total.
User avatar
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by st1nger »

very nice work, thanks alot.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by minmay »

spectre900 wrote:3) To make a key click sound add the following lines in a cript entity on your map and link your locks to it.

Code: Select all

function playLock()
   playSound("key_lock")
end
Why not just add this to the onInsertItem hook? Then you don't need an extra connector on every lock.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by Isaac »

I like the look of it, but quite often the keys are used in the logic, and having one key fit multiple locks would cause havoc. The mod would certainly need to be designed with reusable keys in mind; (and a lot of unique keys).

The first area in my ORRR2 room, had three doors, but only one key, because it was a choice of which one to unlock; and it affected the way the room worked.
User avatar
spectre900
Posts: 124
Joined: Fri Sep 14, 2012 1:47 am

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by spectre900 »

minmay wrote:
spectre900 wrote:3) To make a key click sound add the following lines in a cript entity on your map and link your locks to it.

Code: Select all

function playLock()
   playSound("key_lock")
end
Why not just add this to the onInsertItem hook? Then you don't need an extra connector on every lock.
I did ask if that was possible in another thread but didn't get an answer for it, plus some may want it to "click" on both inserting and removing the key or just use a different sound altogether, or no sound.

Isaac wrote:I like the look of it, but quite often the keys are used in the logic, and having one key fit multiple locks would cause havoc. The mod would certainly need to be designed with reusable keys in mind; (and a lot of unique keys).

The first area in my ORRR2 room, had three doors, but only one key, because it was a choice of which one to unlock; and it affected the way the room worked.
There are ways to build around that, like requiring a key to stay inside to keep a door open so you can't take it with you or even requiring multiple keys to open the next section. Plus there are a lot of key variants in the game. (although not sure prison locks count anymore as they don't appear to have textures.)

Not sure if it's possible to force a key to stay in the lock, but that could be an option too for certain locks.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by JohnWordsworth »

Neat - I like it. I get the impression that it would be a good idea to either use this for the entirety of your mod or not at all, because mixing up mechanics for things is only going to confuse players. BUT, with that said, I always thought it a bit weird that keys were "consumed" and, while this likely means having a wider set of different keys, I like the extra realism this gives.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Eleven Warrior
Posts: 745
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by Eleven Warrior »

+ 1 to john _ This is cool thxs :)
User avatar
spectre900
Posts: 124
Joined: Fri Sep 14, 2012 1:47 am

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by spectre900 »

New version is out. it fixes the issue with the lock_stone and stops that rather annoying message to pop up all the time.

Just download again and replace the "keys_in_locks.lua and make sure the lock_stone model file added to your models folder. (should not affect your dungeon when replacing the scripts.)
User avatar
Vandalar
Posts: 31
Joined: Sun Jan 18, 2015 6:05 pm
Location: Montreal, Canada

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by Vandalar »

I like a lot this mod assets. Most likely you already figured this out, but for those searching the forums, you can add this little function inside a script and attach it on the onRemoveItem hook. The key is actually removed and destroyed immediately, but another one is added immediately in the lock. So visually, it's like if the key is "stuck" in the lock.

In this example, I "re-added" the gold key for a golden lock. Simply change the name of the key for the associated key lock.

Code: Select all

function lockRemoveItem(self)
	setMouseItem(nil)
	self:addItem(spawn("gold_key").item)
end
Once again, great asset.

Cheers !

Vand
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Mod-Assets] Keys in locks. (re-usable keys)

Post by minmay »

Vandalar wrote:I like a lot this mod assets. Most likely you already figured this out, but for those searching the forums, you can add this little function inside a script and attach it on the onRemoveItem hook. The key is actually removed and destroyed immediately, but another one is added immediately in the lock. So visually, it's like if the key is "stuck" in the lock.

In this example, I "re-added" the gold key for a golden lock. Simply change the name of the key for the associated key lock.

Code: Select all

function lockRemoveItem(self)
	setMouseItem(nil)
	self:addItem(spawn("gold_key").item)
end
Once again, great asset.

Cheers !

Vand
Uh, a MUCH better way to do this is to just disable the ItemComponent of the key after it's added to the lock. Your approach doesn't even retain the original object.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply