local underItem = 1642 -- the item you have under the item you want
local distance = x -- the amount of squares away from the lever the items are, needs to be the same for all directions
local items = {
[itemid] = x, -- change the itemid to the actual itemid and then change the x to the amount of tokens needed for this item
[itemid2] = x, -- same again
[itemid3] = x -- same again until you have all items or they only need 1 token to buy them
}
function onUse(cid, item, fromPosition, itemEx, topos)
local itemx = {0, 0, 0, 0}
if item.itemid == 1945 or item.itemid == 1946 then
itemx[1] = getThingfromPos({x=topos.x, y=topos.y-distance, z=topos.z, stackpos=1})
itemx[2] = getThingfromPos({x=topos.x+distance, y=topos.y, z=topos.z, stackpos=1})
itemx[3] = getThingfromPos({x=topos.x, y=topos.y+distance, z=topos.z, stackpos=1})
itemx[4] = getThingfromPos({x=topos.x-distance, y=topos.y, z=topos.z, stackpos=1})
if itemx[1].itemid == underItem then
make = getThingfromPos({x=topos.x, y=topos.y-distance, z=topos.z, stackpos=3})-- might have to change stackpos
elseif itemx[2].itemid == underItem then
make = getThingfromPos({x=topos.x+distance, y=topos.y, z=topos.z, stackpos=3})
elseif itemx[3].itemid == underItem then
make = getThingfromPos({x=topos.x, y=topos.y+distance, z=topos.z, stackpos=3})
elseif itemx[4].itemid == underItem then
make = getThingfromPos({x=topos.x-distance, y=topos.y, z=topos.z, stackpos=3})
end
if getItemNameById(make.itemid) ~= '' then
if items[make.itemid] then
if (doPlayerRemoveItem(cid,5887, items[make.itemid])) then
doPlayerSendTextMessage(cid, 22, "U got a '" .. getItemNameById(make.itemid) .. ", for " .. items[make.itemid] .. " tokens.")
doPlayerAddItem(cid, make.itemid, 1)
else
doPlayerSendTextMessage(cid, 22, "U dont have " .. items[make.itemid] .. " tokens!")
end
else
if (doPlayerRemoveItem(cid,5887,1)) then
doPlayerAddItem(cid, make.itemid, 1)
doPlayerSendTextMessage(cid, 22, "U got a '" .. getItemNameById(make.itemid) .. ", for 1 token.")
else
doPlayerSendTextMessage(cid, 22, "U dont have 1 token!")
end
end
end
if item.itemid == 1945 then
doTransformItem(item.uid, item.itemid + 1)
elseif item.itemid == 1946 then
doTransformItem(item.uid, item.itemid - 1)
end
end
return TRUE
end