I would like to create an Replicator:
2 alcoves, 1 lever and one lua entity
when the lever is pulled, i can check items in alcoves
when both alcoves contain just one item, and one of them is for example rock (or anything else), a want to replace this rock with the item in the other alcove.
My 2(3) questions:
- is there a way to remove item (or just teleport it from the alcove somewhere else)
- is there a waz to clone item (or spawn a copy or whatever you can name it)?
- found it on the forum
Code: Select all
replicator_alcove_1:addItem(spawn(original_item.name))
- if so, where can i find info about such functions?
Thanks!
EDIT:
Looks like i found a workaround, here is code for my replicator:
Code: Select all
replicator_used = false -- can use only once
function replicate()
if(replicator_used==false) then
checkAlcoveForItems()
end
end
function checkAlcoveForItems()
local itemCount1 = replicator_alcove_1:getItemCount()
local itemCount2 = replicator_alcove_2:getItemCount()
if( (itemCount1==1) and (itemCount2==1)) then
for i in replicator_alcove_1:containedItems() do
if i.name == "replicator_token" then -- it's just a clone of rock with different name :)
itemFound()
end
end
end
end
-- run this script _once for each item_ with a matching name
function itemFound()
--play sound, write text
for a in replicator_alcove_2:containedItems() do
replicator_alcove_2:addItem(spawn(a.name)) --replicate item in alcove_2
replicator_used = true --cannot use it again
dungeon_wall_text_1:setWallText("Not enough energy!") --change replicator description
dungeon_secret_door_1:close() --close secret door before alcove eith token - player cannot pick it up again
end
end
One qestion thou - can i modify function itemFound() so it does not use a for loop?