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