• 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!

TFS 1.X+ How to simulate death in tfs 1.3?

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,234
Solutions
8
Reaction score
111
Location
Sweden
As topic says, how do i simulate death on a player? I have an area of pvp zone which I want, when the player dies he gets teleported somewhere. Whats the most good looking and least resource taking way of doing this?

I read something here on otland about "killing" a player when hes on 1 hp, but that seems to be messy.

TFS 1.3
 
Last edited:

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,254
Location
Sweden?
Here is a fast example. This is not tested and i have not been coding Lua for years. So take it as a pointer.
Lua:
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()
 
OP
OP
Mjmackan

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,234
Solutions
8
Reaction score
111
Location
Sweden
Here is a fast example. This is not tested and i have not been coding Lua for years. So take it as a pointer.
Lua:
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()
Oh okay, so an addevent pretty much. Thank you so much but I guess it would act the same as my script. The player cant die at all when registering this in login.
I made this in creaturescripts:
Lua:
function onPrepareDeath(creature, killer)
    if not creature:isPlayer() then return true end
 
    local player = Player(creature)
    
if player:getStorageValue(fragEventPlayer) > 100 then
    -- Reset player after death
    player:teleportTo(fragEventRespawnPoint)
    player:addHealth(player:getMaxHealth())
    player:addMana(player:getMaxMana())
    return false
end
    return false
end
 

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,254
Location
Sweden?
Yeh pretty much, i've cleaned the code. Since you dont need those checks from the start. Due to you are register this event to a player already. So no need to check if it's player.

Lua:
function onPrepareDeath(player, killer)
    if player:getStorageValue(fragEventPlayer) > 100 then
        -- Reset player after death
        player:teleportTo(fragEventRespawnPoint)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        return false
    end
    return true
end

Also return true, when the condition is not met. So they can die as usual
 
OP
OP
Mjmackan

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,234
Solutions
8
Reaction score
111
Location
Sweden
Yeh pretty much, i've cleaned the code. Since you dont need those checks from the start. Due to you are register this event to a player already. So no need to check if it's player.

Lua:
function onPrepareDeath(player, killer)
    if player:getStorageValue(fragEventPlayer) > 100 then
        -- Reset player after death
        player:teleportTo(fragEventRespawnPoint)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        return false
    end
    return true
end

Also return true, when the condition is not met. So they can die as usual
Oh damn, so it was just to return true, thats cool. Thanks again!
Thanks for cleaning it up aswell, I have lot more things to add just didnt get why it wouldnt work with these basic stuff.
Thanks you so much for getting that headache away! <3
 
Top