Re: Ask a simple question, get a simple answer
Posted: Tue Nov 22, 2016 12:06 am
thanks!
Official Legend of Grimrock Forums
http://grimrock.net/forum/
Code: Select all
-----------
--- Key ---
-----------
defineObject{
name = "lvl1thom_door_key_1",
baseObject = "base_item",
tags = { "my_quest_keys" },
components = {
{
class = "Model",
model = "assets/models/items/key_iron.fbx",
},
{
class = "Item",
uiName = "Thomadars Key",
gfxIndex = 22,
weight = 0.2,
traits = { "key" },
},
{
class = "Particle",
particleSystem = "glitter_gold",
},
},
}
------------------
--- Key Lock ---
------------------
defineObject{
name = "thom_base_lock_1",
components = {
{
class = "Model",
model = "assets/models/env/wall_lock_round.fbx",
offset = vec(0, 1.375, 0),
staticShadow = true,
},
{
class = "Clickable",
offset = vec(0, 1.38, -0.16),
size = vec(0.1, 0.1, 0.15),
debugDraw = true,
},
{
class = "Socket",
offset = vec(0, 0, 0), --(-0.42, 1.18, 0),--
--offset = vec(0, 0, 0),
rotation = vec(0, 0, -3),
onAcceptItem = function(self, item)
if item.go.name ~= "lvl1thom_door_key_1" then
hudPrint("You will need Thomadar's key to open the door.")
return false
else
playSound("key_lock")
return true
end
end,
},
},
placement = "wall",
editorIcon = 92,
tags = { "my_quest_keys" },
}
LockComponent doesn't actually destroy the item, it just removes the mouse item. The item still exists afterwards, but since it is not on a map you can only reach it by having a preexisting reference to it. For example, this is a lock that immediately puts the key item back into the mouse item slot:zimberzimber wrote:Lock component accepts only the item it is defined to accepts without any additional checkers, and automatically destroys it upon accepting it.
Code: Select all
-- The mirror "lock" should not consume the item used to open it; in Dungeon
-- Master, using the Mirror of Dawn on it doesn't destroy the mirror. We do
-- this by simply setting the mouse item back to the key after it is used. The
-- ItemComponent reference here is removed before the end of the frame so it
-- cannot cause a serialization error.
defineObject{
name = "dm_lock_mirror_slot",
baseObject = "lock",
components = {
{
class = "Model",
model = "mod_assets/dmcsb_pack/models/env/dm_mirror_slot.fbx",
offset = vec(0, 1.74, 0),
staticShadow = true,
},
{
class = "Clickable",
offset = vec(0, 1.74, 0),
size = vec(0.5, 0.4, 0.4),
onClick = function(self)
if self.go.lock:isEnabled() and getMouseItem() and getMouseItem().go.name == self.go.lock:getOpenedBy() then
GameMode.dm_tempLockItem = getMouseItem()
end
end,
},
{
class = "Lock",
sound = "key_lock",
openedBy = "dm_mirror_of_dawn",
onActivate = function(self)
setMouseItem(GameMode.dm_tempLockItem)
GameMode.dm_tempLockItem = nil
end,
},
},
tags = {"dm","dm_user"},
}
Code: Select all
self.go:createComponent("Surface")
self.go.surface:setSize(vec(1.5, 1.5))
function destroyItem(item)
if not item then return end
if not item.go.map then self.go.surface:addItem(item) end
item.go:destroy()
end
Code: Select all
for v,i in enchanterAltar.surface:contents() do
if i and i.go.item then
for c = 1,4 do
local champion = party.party:getChampion(c)
if champion then
for invSlot = 13, 32 do
if champion:getItem(invSlot) == nil then
champion:insertItem(invSlot, i)
mi.data.gfxIndex = 0.5
mi.data.size = {0, 0}
enchanterAltar:removeComponent("surface")
enchanterAltar:createComponent("Surface")
enchanterAltar.surface:setSize(vec(1,1))
return
end
end
end
end
hudPrint("Inventory is full")
playSound("dispel_launch")
return
end
end