local config = {
destination = Position(x, y, z),
timer = 5,
}
local function teleportBack(id, position)
local player = Player(id)
if player then
local corpseItem = Tile(position):getItemById(player:getSex() == PLAYERSEX_FEMALE and 3065 or 3058)
if corpseItem then
corpseItem:remove()
end
player:teleportTo(config.destination)
position:sendMagicEffect(CONST_ME_YALAHARIGHOST)
end
end
local creatureevent = CreatureEvent("onFakeDeath")
function creatureevent.onPrepareDeath(player, killer)
-- Fake corpse
local killerName
if killer then
if killer:isPlayer() then
killerName = killer:getName()
else
local master = killer:getMaster()
if master and master ~= killer and master:isPlayer() then
killerName = master:getName()
end
end
else
killerName = "field item"
end
local corpse = Game.createItem(player:getSex() == PLAYERSEX_FEMALE and 3065 or 3058, 1, player:getPosition())
corpse:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, ("You recognize %s. %s was killed by %s."):format(player:getName(), player:getSex() == PLAYERSEX_FEMALE and "She" or "He", killerName)
corpse:decay()
-- Return player timer
addEvent(teleportBack, config.timer * 1000, player.uid, player:getPosition())
-- Teleport
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have died and been brought to a temporary place.")
player:teleportTo(config.destination)
destination:sendMagicEffect(CONST_ME_TELEPORT)
return false
end
creatureevent:register()