Can I suggest a little addition to your library.
I need to respawn items with the same id, so I modified the grimq a little.
I just don't want to duplicate the grimq code in my framework, so it would be nice to have these features in your library.
Code: Select all
-- loads an item from the table (added optional id argument)
function loadItem(itemTable, level, x, y, facing,id)
local spitem = nil
if (level ~= nil) then
spitem = spawn(itemTable.name, level, x, y, facing,id)
else
spitem = spawn(itemTable.name,nil,nil,nil,nil,id)
end
if itemTable.stackSize > 0 then
spitem:setStackSize(itemTable.stackSize)
end
if itemTable.charges > 0 then
spitem:setCharges(itemTable.charges)
end
if itemTable.scrollText ~= nil then
spitem:setScrollText(itemTable.scrollText)
end
spitem:setFuel(itemTable.fuel)
if (itemTable.subItems ~= nil) then
for _, subTable in pairs(itemTable.subItems) do
local subItem = loadItem(subTable)
spitem:addItem(subItem, false)
end
end
return spitem
end
-- Respawns an item (original id can be used)
-- If level == nil the item will be respawned to object space
function respawnItem(item,level,x,y,facing,id)
-- if id is numeric then create a new unique id for item
-- for some reason numeric id's are not allowed as a spawn-function argument
if (id and string.find(id, "^%d+$")) then
id = nil
end
local copy = saveItem(item)
item:destroy()
return loadItem(copy,level,x,y,facing,id)
end