Page 1 of 1

A little help creating a new Keys-in-locks mod.

Posted: Sun May 24, 2015 2:40 pm
by spectre900
Haven't done any modding in a long while now and I'm a bit rusty so I would like some help creating a new mod that enables keys to be placed inside locks and then be retrievable all the same like in this mod here > viewtopic.php?f=14&t=6469

I guess I may have to create new models using the LoG2 assets as simply copying the old scrips and models didn't seem to work.

I will play around with GMT and look around a bit more to see what I can come up with, but any help would be appreciated.


My main concern is how do I take this...

Code: Select all

defineObject{
	name = "lock_alcove_iron",
	class = "Alcove",
	model = "mod_assets/models/wall_lock_A.fbx",
	replacesWall = false,
	anchorPos = vec(0.015, 1.41, -0.08),
	targetPos = vec(0, 1.37, -0.58),
	targetSize = vec(0.3, 0.3, 0.3),
	anchorRotation = vec(-70, 90, 0),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "iron_key" and self:getItemCount() == 0
	end,
	placement = "wall",
	editorIcon = 20,
}
and make it fit into something like this without crashing the game??

Code: Select all

defineObject{
	name = "dungeon_alcove",
	baseObject = "base_alcove",
	components = {
		{
			class = "Model",
			model = "assets/models/env/dungeon_wall_alcove.fbx",
			staticShadow = true,
		},
		{
			class = "Occluder",
			model = "assets/models/env/dungeon_wall_alcove_occluder.fbx",
		}
	},
}
Cause the new format is confusing to say the least, especially since I am really really bad at reading scrips in general. Only way I make things work is to find patterns in things by comparing multiple scrips, but I don't have any good references here. >.<

Re: A little help creating a new Keys-in-locks mod.

Posted: Mon May 25, 2015 12:11 pm
by spectre900
No one knows how to convert old code to the new format? I really need to have this working before I can start working on new dungeons. :<

Re: A little help creating a new Keys-in-locks mod.

Posted: Mon May 25, 2015 1:02 pm
by JohnWordsworth
I am at work at the moment, so cannot just convert the code directly - but I think you would just need to add a Socket component in order to accept the key as an object. You shouldn't have to mess around with model files or anything.

Unfortunately, the Scripting Reference is down at the moment, so I can't give you any more specific pointers at this second!

Re: A little help creating a new Keys-in-locks mod.

Posted: Mon May 25, 2015 4:06 pm
by spectre900
I think I may have found a solution. G2 doesn't seem to have an "eye_socket" anywhere which is where I got the idea and reference from in the first place, so not finding that I had a bit of a problem..... until I found something else.
G2 does have something else that uses a "socket" for specific items.... torch holders! Sooooo, I used that for a reference and came up with this:

Code: Select all

defineObject{
	name = "Lock_Alcove_Brass",
	components = {
		{
			class = "Model",
			model = "mod_assets/models/wall_lock_A.fbx",
			staticShadow = true,
		},
		{
			class = "Clickable",
			offset = vec(0.0, 1.4, 0.0),
			size = vec(0.35, 0.6, 0.15),
			--debugDraw = true,
		},
		{
			class = "Socket",
			offset = vec(0.02, 1.395, -0.08),
			rotation = vec(-70, 90, 0),
			onAcceptItem = function(self, item)
				return (item.go.name == "brass_key") and self:count() == 0
			end,
			--debugDraw = true,
		},
	},
	placement = "wall",
	editorIcon = 20,
}
Boom! keys inside locks! \o/

Only thing I'm curious about now is if I can add a key_click sound each time you insert a key, to this script instead of manually having to add it in the editor every time. Would save a lot of time and clutter.

Edit: Oh I almost forgot. did they remove the function to add item into alcoves? How do I re-enable this for my locks as sometimes I may need a key to already be inserted.

Here's a little image of how it looks currently.
Image