local teleporterCreatePosition = {x = 1000, y = 1000, z = 7}
local teleporterDestination = {x = 1000, y = 1000, z = 7}
local removeTimer = 5 -- seconds until remove
local teleporterId = 1387
local leverId = {1945, 1946}
local requiredItems = {
{1111, 1, "Item 1"}, -- {itemid, amount, item_name}
{2222, 2, "Item 2"},
{3333, 3, "Item 3"}
}
local function removeItemOnPosition(itemid, position)
local item = getTileItemById(position, itemid).uid
if item > 0 then
doRemoveItem(item)
return true
end
return false
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
-- check if teleport has already been spawned
local teleport = getTileItemById(teleporterCreatePosition, teleporterId).uid
if teleport > 0 then
return true
end
local itemsRequiredText = ""
local hasItems = true
for i = 1, #requiredItems do
if getPlayerItemCount(cid, requiredItems[i][1]) < requiredItems[i][2] then
hasItems = false
end
if text ~= "" then
text = text .. ", "
end
text = text .. requiredItems[i][2] .. " " .. requiredItems[i][3]
end
if not hasItems then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Missing required items to create teleporter. (" .. itemsRequiredText .. ")")
return true
end
for i = 1, #requiredItems do
doPlayerRemoveItem(cid, requiredItems[i][1], requiredItems[i][2])
end
-- create teleport and remove after x time
doCreateTeleport(teleporterId, teleporterDestination, teleporterCreatePosition)
addEvent(removeItemOnPosition, removeTimer * 1000, teleporterId, teleporterPosition)
-- lever flopping
doTransformItem(item.uid, item.itemid == leverId[1] and leverId[2] or leverId[1])
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Teleporter has been created, and will disappear in " .. removeTimer .. " seconds.")
return true
end