• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Teleport To last died tfs 1.5 tibia 8.6

jareczekjsp

Active Member
Joined
Jan 30, 2023
Messages
281
Solutions
1
Reaction score
29
GitHub
Jarek123
Hello,
I’m looking for a system where when a player dies, they can use an item up to 2 times a day or something that teleports them back to the last position where they died. Does anyone know how to do this or could guide me somehow?
 
Solution
I have something like this, see if it works, if necessary let me know what errors, just replace the item ID 12345 and reset the server

data/scripts/teleport_last_death.lua

Code:
local STORAGE = {
  DEATH_X = 90000,
  DEATH_Y = 90001,
  DEATH_Z = 90002,
  TP_DAY  = 90003,
  TP_COUNT = 90004
}

local DAILY_LIMIT = 2

-- Zapis pozycji śmierci
local deathEvent = CreatureEvent("StoreDeathPosition")
function deathEvent.onPrepareDeath(creature, killer)
  local player = creature:getPlayer()
  if not player then
    return true
  end
  local pos = player:getPosition()
  player:setStorageValue(STORAGE.DEATH_X, pos.x)
  player:setStorageValue(STORAGE.DEATH_Y, pos.y)
  player:setStorageValue(STORAGE.DEATH_Z, pos.z)
  return true
end...
Hi, tell me what Lua your server supports, probably 5.2, and does the server automatically load scripts from data/script?
 
I have something like this, see if it works, if necessary let me know what errors, just replace the item ID 12345 and reset the server

data/scripts/teleport_last_death.lua

Code:
local STORAGE = {
  DEATH_X = 90000,
  DEATH_Y = 90001,
  DEATH_Z = 90002,
  TP_DAY  = 90003,
  TP_COUNT = 90004
}

local DAILY_LIMIT = 2

-- Zapis pozycji śmierci
local deathEvent = CreatureEvent("StoreDeathPosition")
function deathEvent.onPrepareDeath(creature, killer)
  local player = creature:getPlayer()
  if not player then
    return true
  end
  local pos = player:getPosition()
  player:setStorageValue(STORAGE.DEATH_X, pos.x)
  player:setStorageValue(STORAGE.DEATH_Y, pos.y)
  player:setStorageValue(STORAGE.DEATH_Z, pos.z)
  return true
end
deathEvent:register()

-- Action przedmiotu: teleport do ostatniej śmierci z limitem 2/dzień
local teleportAction = Action()
function teleportAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
  local lastZ = player:getStorageValue(STORAGE.DEATH_Z)
  if lastZ == -1 then
    player:sendCancelMessage("Brak zapisanej pozycji śmierci.")
    return true
  end

  local today = tonumber(os.date("%j"))
  local usedDay = player:getStorageValue(STORAGE.TP_DAY)
  local usedCount = player:getStorageValue(STORAGE.TP_COUNT)
  if usedDay ~= today then
    usedDay = today
    usedCount = 0
  end

  if usedCount >= DAILY_LIMIT then
    player:sendCancelMessage("Możesz użyć tego przedmiotu tylko dwa razy dziennie.")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
  end

  local pos = Position(
    player:getStorageValue(STORAGE.DEATH_X),
    player:getStorageValue(STORAGE.DEATH_Y),
    lastZ
  )

  if pos.x <= 0 or pos.y <= 0 then
    player:sendCancelMessage("Nieprawidłowa zapisana pozycja.")
    return true
  end

  local fromPos = player:getPosition()
  player:teleportTo(pos)
  pos:sendMagicEffect(CONST_ME_TELEPORT)
  fromPos:sendMagicEffect(CONST_ME_TELEPORT)

  player:setStorageValue(STORAGE.TP_DAY, today)
  player:setStorageValue(STORAGE.TP_COUNT, usedCount + 1)
  return true
end
teleportAction:id(12345) -- <= PODMIEŃ na ID swojego itemu
teleportAction:register()

-- Rejestracja eventu na logowaniu (dla wszystkich graczy)
local loginEvent = CreatureEvent("RegisterStoreDeathPosition")
function loginEvent.onLogin(player)
  player:registerEvent("StoreDeathPosition")
  return true
end
loginEvent:register()
 
Last edited:
Solution
Work but I have question ,I have castle war or bosses for cooldown is possible player can not use this item special places? castle or bossess? i dont know meybe no logout places?
Post automatically merged:

and this item only can use in pz zone
 
Work but I have question ,I have castle war or bosses for cooldown is possible player can not use this item special places? castle or bossess? i dont know meybe no logout places?
Post automatically merged:

and this item only can use in pz zone

New request -> new thread
Yes it's possible
 
Here you have a modified script, add your item in id12345, or change it to the English version when it comes to commands when something cannot be done

LUA:
local STORAGE = {
  DEATH_X  = 90000,
  DEATH_Y  = 90001,
  DEATH_Z  = 90002,
  TP_DAY   = 90003,
  TP_COUNT = 90004
}

local DAILY_LIMIT = 2

-- Zapis pozycji śmierci
local deathEvent = CreatureEvent("StoreDeathPosition")
function deathEvent.onPrepareDeath(creature, killer)
  local player = creature:getPlayer()
  if not player then
    return true
  end

  local pos = player:getPosition()
  player:setStorageValue(STORAGE.DEATH_X, pos.x)
  player:setStorageValue(STORAGE.DEATH_Y, pos.y)
  player:setStorageValue(STORAGE.DEATH_Z, pos.z)
  return true
end
deathEvent:register()

-- Action przedmiotu: teleport do ostatniej śmierci
local teleportAction = Action()
function teleportAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
  -- Musi być w PZ
  local playerTile = player:getTile()
  if not playerTile or not playerTile:hasFlag(TILESTATE_PROTECTIONZONE) then
    player:sendCancelMessage("Przedmiot działa tylko w strefie PZ.")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
  end

  -- Sprawdź zapis śmierci
  local lastZ = player:getStorageValue(STORAGE.DEATH_Z)
  if lastZ == -1 then
    player:sendCancelMessage("Brak zapisanej pozycji śmierci.")
    return true
  end

  -- Limit 2 razy dziennie (reset o północy)
  local today = tonumber(os.date("%j"))
  local usedDay = player:getStorageValue(STORAGE.TP_DAY)
  local usedCount = player:getStorageValue(STORAGE.TP_COUNT)
  if usedDay ~= today then
    usedDay = today
    usedCount = 0
  end
  if usedCount >= DAILY_LIMIT then
    player:sendCancelMessage("Możesz użyć tego przedmiotu tylko dwa razy dziennie.")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
  end

  -- Pozycja docelowa
  local pos = Position(
    player:getStorageValue(STORAGE.DEATH_X),
    player:getStorageValue(STORAGE.DEATH_Y),
    lastZ
  )
  if pos.x <= 0 or pos.y <= 0 then
    player:sendCancelMessage("Nieprawidłowa zapisana pozycja.")
    return true
  end

  -- Blokada strefy no-logout
  local destTile = Tile(pos)
  if not destTile or destTile:hasFlag(TILESTATE_NOLOGOUT) then
    player:sendCancelMessage("Nie możesz teleportować do strefy no-logout.")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
  end

  -- Teleport
  local fromPos = player:getPosition()
  player:teleportTo(pos)
  pos:sendMagicEffect(CONST_ME_TELEPORT)
  fromPos:sendMagicEffect(CONST_ME_TELEPORT)

  -- Zapis użycia
  player:setStorageValue(STORAGE.TP_DAY, today)
  player:setStorageValue(STORAGE.TP_COUNT, usedCount + 1)
  return true
end

teleportAction:id(12345) -- <= PODMIEŃ na ID swojego itemu
teleportAction:register()

-- Rejestracja eventu przy logowaniu
local loginEvent = CreatureEvent("RegisterStoreDeathPosition")
function loginEvent.onLogin(player)
  player:registerEvent("StoreDeathPosition")
  return true
end
loginEvent:register()
 
Back
Top