Page 1 of 1

Is it Possible To Have a Key Stack?

Posted: Wed Jul 03, 2013 11:15 pm
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

Re: Is it Possible To Have a Key Stack?

Posted: Wed Jul 03, 2013 11:29 pm
by Komag
You can easily defineObject new keys with new names. A stackable keyring setup is probably doable, but it would be advanced.

Re: Is it Possible To Have a Key Stack?

Posted: Sat Jul 06, 2013 12:13 am
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

Re: Is it Possible To Have a Key Stack?

Posted: Sat Jul 06, 2013 3:04 pm
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

Re: Is it Possible To Have a Key Stack?

Posted: Sat Jul 13, 2013 12:08 am
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