Is it Possible To Have a Key Stack?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
fazzasx
Posts: 104
Joined: Mon May 27, 2013 12:35 am

Is it Possible To Have a Key Stack?

Post by fazzasx »

Hi Everyone :)

I wanted to ask if is possible to create or use a stack of keys like we have for coins?

Reason for asking this is because I would like to have a regular set of gold keys that open doors like common keys etc?

I would also like to know if we can rename the keys?

Let me know

Thanks
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Is it Possible To Have a Key Stack?

Post by Komag »

You can easily defineObject new keys with new names. A stackable keyring setup is probably doable, but it would be advanced.
Finished Dungeons - complete mods to play
User avatar
fazzasx
Posts: 104
Joined: Mon May 27, 2013 12:35 am

Re: Is it Possible To Have a Key Stack?

Post by fazzasx »

Komag wrote:You can easily defineObject new keys with new names. A stackable keyring setup is probably doable, but it would be advanced.

Thanks Komag I will try this
User avatar
remma
Posts: 36
Joined: Mon Apr 15, 2013 11:03 pm
Location: Newcastle upon Tyne, England

Re: Is it Possible To Have a Key Stack?

Post by remma »

in the item definition you would add in stackable=true,
so you'd end up with something like

Code: Select all

	defineObject{
		name = "bw_commonkey",
		class = "Item",
		uiName = "Common Key",
		model = "mod_assets/bw_pack/models/items/bw_common_key.fbx",
		gfxAtlas = "mod_assets/bw_pack/textures/gui/bw_icoatlas.tga",
		glitterEffect = "glitter_silver",
		stackable = true,
		gfxIndex = 0,
		key = true,
		weight = 0.2,
		end,
	}
Which is great, the issue you will likely run in to however is that keyholes consume an entire stack when activated so if you have 5 keys on the pointer then unlocking that door will use all 5 keys.

to resolve this you need to hook in to an event, since the lock exposes no events I've hooked mine to the onOpen event of the actual door and it works quite well.

in my definition for the door I have:

Code: Select all

	onOpen = function(self)		 
	         if (getMouseItem()) then
		 keystack = getMouseItem():getStackSize()
		 keystack = keystack -1
		 if (keystack>0)then
		 key_spawner.spawnkeys(keystack)
		 end
		 end
I did initially try setting the mouse item from within this but it wouldn't work - I'm guessing that this code runs prior to the mouse pointer being cleared so in the dungeon itself I have script called 'key_spawner'

Code: Select all

function spawnkeys(keystack)
  stacksize = keystack
  key_timer:activate()
end

function givekeys()
  setMouseItem(spawn("bw_commonkey"):setStackSize(stacksize))
  key_timer:deactivate()
end
and a timer called key_timer with the time set to 0.01 and it works great for my dungeon

the one issue you may run into is that this will try to run whenever you open the door, since mine are replaced on open this isn't an issue for me but you may want a sanity check in the onopen hook

edit *blonde moment
User avatar
fazzasx
Posts: 104
Joined: Mon May 27, 2013 12:35 am

Re: Is it Possible To Have a Key Stack?

Post by fazzasx »

remma wrote:in the item definition you would add in stackable=true,
so you'd end up with something like

Code: Select all

	defineObject{
		name = "bw_commonkey",
		class = "Item",
		uiName = "Common Key",
		model = "mod_assets/bw_pack/models/items/bw_common_key.fbx",
		gfxAtlas = "mod_assets/bw_pack/textures/gui/bw_icoatlas.tga",
		glitterEffect = "glitter_silver",
		stackable = true,
		gfxIndex = 0,
		key = true,
		weight = 0.2,
		end,
	}
Which is great, the issue you will likely run in to however is that keyholes consume an entire stack when activated so if you have 5 keys on the pointer then unlocking that door will use all 5 keys.

to resolve this you need to hook in to an event, since the lock exposes no events I've hooked mine to the onOpen event of the actual door and it works quite well.

in my definition for the door I have:

Code: Select all

	onOpen = function(self)		 
	         if (getMouseItem()) then
		 keystack = getMouseItem():getStackSize()
		 keystack = keystack -1
		 if (keystack>0)then
		 key_spawner.spawnkeys(keystack)
		 end
		 end
I did initially try setting the mouse item from within this but it wouldn't work - I'm guessing that this code runs prior to the mouse pointer being cleared so in the dungeon itself I have script called 'key_spawner'

Code: Select all

function spawnkeys(keystack)
  stacksize = keystack
  key_timer:activate()
end

function givekeys()
  setMouseItem(spawn("bw_commonkey"):setStackSize(stacksize))
  key_timer:deactivate()
end
and a timer called key_timer with the time set to 0.01 and it works great for my dungeon

the one issue you may run into is that this will try to run whenever you open the door, since mine are replaced on open this isn't an issue for me but you may want a sanity check in the onopen hook

edit *blonde moment



Thanks Remma,

I will try this and see how it goes. Looks like you have really experimented with this which is good.

Thanks
Zastaph
Post Reply