local teleport_location = {x = 1000, y = 1000, z = 7}
local positionStorage = {x = 45001, y = 45002, z = 45003} -- change storages to un-used values
local cooldownStorage = 45004
function onUse(cid, item, fromPosition, itemEx, toPosition)
-- cooldown
local cur_time = os.time()
local cooldown = getPlayerStorageValue(cid, cooldownStorage)
if cooldown > cur_time then
doSendMagicEffect(fromPosition, CONST_ME_POFF)
doPlayerSendCancel(cid, "Item on cooldown. " .. os.date('!%H:%M:%S', (cooldown - cur_time)))
return true
end
setPlayerStorageValue(cid, cooldownStorage, cur_time + 5)
-- in-fight
if getCreatureCondition(cid, CONDITION_INFIGHT) then
doSendMagicEffect(fromPosition, CONST_ME_POFF)
doPlayerSendCancel(cid, "Can't use this object while in combat.")
return true
end
-- item must be in player inventory
if fromPosition.x == 65535 then
doSendMagicEffect(fromPosition, CONST_ME_POFF)
doPlayerSendCancel(cid, "This object must be in your inventory to be used.")
return true
end
-- teleport to destination
if getPlayerStorageValue(cid, positionStorage.x) < 0 then
local currentPosition = getCreaturePosition(cid)
setPlayerStorageValue(cid, positionStorage.x, currentPosition.x)
setPlayerStorageValue(cid, positionStorage.y, currentPosition.y)
setPlayerStorageValue(cid, positionStorage.z, currentPosition.z)
doTeleportThing(cid, teleport_location)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've been teleported to blah blah. Use the item again to teleport back to your previous location.")
return true
end
-- teleport back
local backPosition = {x = getPlayerStorageValue(cid, positionStorage.x), y = getPlayerStorageValue(cid, positionStorage.y), z = getPlayerStorageValue(cid, positionStorage.z)}
doTeleportThing(cid, backPosition)
setPlayerStorageValue(cid, positionStorage.x, -1)
setPlayerStorageValue(cid, positionStorage.y, -1)
setPlayerStorageValue(cid, positionStorage.z, -1)
setPlayerStorageValue(cid, cooldownStorage, cur_time + 900)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've been teleported to your previous location.")
return true
end