local config = {
destination = {x = 1000, y = 1000, z = 7},
chance = 10,
actionId = 3214,
itemId = 9020,
item = {{8300, 10}, {8301, 3}, {8302, 5}}
}
function onUse(cid, item, fromPos, itemEx, toPos)
local teleportItem = getPlayerItemById(cid, true, config.itemId)
if not teleportItem then
doPlayerSendCancel(cid, "You don't have the required item.")
doSendMagicEffect(fromPos, CONST_ME_POFF)
return true
end
if teleportItem.actionid ~= config.actionId then
doPlayerSendCancel(cid, "Invalid item.")
doSendMagicEffect(fromPos, CONST_ME_POFF)
return true
end
local chance = math.random(1, 100)
if chance > config.chance then
-- remove random item
local itemToRemove = config.item[math.random(#config.item)]
doPlayerRemoveItem(cid, itemToRemove[1], math.random(itemToRemove[2]))
doSendAnimatedText(fromPos, "FAIL", COLOR_YELLOW)
doSendMagicEffect(fromPos, CONST_ME_POFF)
return true
end
doTeleportThing(cid, config.destination)
doSendMagicEffect(config.destination, CONST_ME_TELEPORT)
doRemoveItem(teleportItem.uid, 1)
return true
end