Code: Select all
altar_1.surface:addConnector('onAcceptItem', self.go.id, "itemSwap")
function itemSwap(surface, item)
local checkItem = "rock"
local itemReplacement = "figure_skeleton"
if item.go.item:getStackSize() == 1 and
item.go.name == checkItem then
item.go:destroyDelayed()
surface:addItem(spawn(itemReplacement).item)
--optional effect
surface.go:createComponent('Particle'):setParticleSystem('beacon_crystal')
surface.go.particle:setDestroySelf(true)
surface.go.particle:fadeOut(1)
surface.go:playSound('teleport')
return false
end
end
IIRC you wanted a script that turns multiple items into a single new item, like crafting potions.
Code: Select all
function transformItems(button)
local input_item_names = { rock = false, branch = false }
local output_item_name = "cudgel"
local surface
local alcove = findEntity("dungeon_alcove_1")
if alcove and alcove.surface then
surface = alcove.surface
else
print("Entity doesn't exist or has no surface component: dungeon_alcove_1")
return
end
-- If any of the input items is on the surface, mark it as present in input_item_names
for _, item in surface:contents() do
if input_item_names[item.go.name] ~= nil then
input_item_names[item.go.name] = true
end
end
-- If at least one input item is missing from the surface, exit the function
for _, present in pairs(input_item_names) do
if present == false then
return
end
end
-- Destroy the input items
for _, item in surface:contents() do
if input_item_names[item.go.name] == true then
-- Mark the item as destroyed in input_item_names
-- So only one instance of the input item gets destroyed
input_item_names[item.go.name] = false
item.go:destroyDelayed()
end
end
-- Add the output item to the surface
surface:addItem(spawn(output_item_name).item)
playSound("secret")
hudPrint("The alcove has created a new " .. output_item_name .. ".")
end