function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local firstItem = Tile(Position(32393, 32191, 7)):getTopDownItem()
local secondItem = Tile(Position(32394, 32191, 7)):getTopDownItem()
if firstItem and secondItem then
if firstItem.itemid == 2148 and secondItem.itemid == 2152 then
Game.createItem(2160, 1, Position(32396, 32191, 7))
firstItem:remove()
secondItem:remove()
end
end
if item.itemid == 1946 then
item:transform(1945)
return false
end
item:transform(1946)
return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local itemCounter = 0
local stackItems = Tile(Position(32393, 32191, 7)):getItems() -- Tile with items to combine
if item.itemid == 1946 then
item:transform(1945)
return false
end
for i = 1, #stackItems do
local item = stackItems[i]
local itemId = item:getId()
if isInArray({2148, 2152}, itemId) then
itemCounter = itemCounter + 1
item:remove()
end
end
if itemCounter == 2 then
Game.createItem(2160, 1, Position(32394, 32191, 7)) -- Tile where item will be created
end
item:transform(1946)
return true
end
<action actionid="25500" script="others/testing.lua" />
2 items in different positions. 327, 902, 7 and 328, 902, 7 and then it should spawn in 329, 904, 72 items in different positions? or you drop both items to same position?
Close but it should be two of these \/ i think because they are not stacked they close to each otherTry:
LUA:function onUse(player, item, fromPosition, target, toPosition, isHotkey) local itemCounter = 0 local stackItems = Tile(Position(32393, 32191, 7)):getItems() -- Tile with items to combine if item.itemid == 1946 then item:transform(1945) return false end for i = 1, #stackItems do local item = stackItems[i] local itemId = item:getId() if isInArray({2148, 2152}, itemId) then itemCounter = itemCounter + 1 item:remove() end end if itemCounter == 2 then Game.createItem(2160, 1, Position(32394, 32191, 7)) -- Tile where item will be created end item:transform(1946) return true end
XML:<action actionid="25500" script="others/testing.lua" />
local config = {
[1] = {uid = 3045, position = Position(327, 902, 7), itemId = 2033},
[2] = {position = Position(328, 902, 7)}
}
local function revertLever(position)
local leverItem = Tile(position):getItemById(1946)
if leverItem then
leverItem:transform(1945)
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid ~= 1945 then
return true
end
if item.uid == config[1].uid then
local ItemToUse = Tile(config[1].position):getItemById(2160)
local ItemToUseTwo = Tile(config[2].position):getItemById(2160)
if ItemToUse and ItemToUseTwo then
ItemToUse:remove(1)
ItemToUseTwo:remove(1)
config[1].position:sendMagicEffect(CONST_ME_TELEPORT)
config[2].position:sendMagicEffect(CONST_ME_TELEPORT)
Game.createItem(2160, 1, Position(329, 903, 7))
item:transform(1946)
addEvent(revertLever, 4 * 1000, toPosition)
elseif not ItemToUse and ItemToUseTwo then
player:sendCancelMessage('You need to offer both items.')
else
player:sendCancelMessage('You have already used this lever!')
end
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local firstItem = Tile(Position(32393, 32191, 7)):getTopDownItem()
local secondItem = Tile(Position(32394, 32191, 7)):getTopDownItem()
if firstItem and secondItem then
if firstItem.itemid == 2148 and secondItem.itemid == 2152 then
Game.createItem(2160, 1, Position(32396, 32191, 7))
firstItem:remove()
secondItem:remove()
end
end
if item.itemid == 1946 then
item:transform(1945)
return false
end
item:transform(1946)
return true
end
The code has a flaw, even if the conditions are not met, it still removes individual items.Also fixed my one - remember to change Positions and itemids
LUA:local config = { [1] = {pos = Position(32393, 32191, 7), itemid = 2148}, [2] = {pos = Position(32394, 32191, 7), itemid = 2152} } function onUse(player, item, fromPosition, target, toPosition, isHotkey) local counter = 0 for i = 1, #config do local tile = Tile(config[i].pos):getTopDownItem() if tile and tile.itemid == config[i].itemid then counter = counter + 1 tile:remove() if counter == 2 then Game.createItem(2160, 1, Position(32396, 32191, 7)) end end end if item.itemid == 1946 then item:transform(1945) return false end item:transform(1946) return true end
