• 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.3 PVP Arena Script problem.

CesarZ

Well-Known Member
Joined
Sep 20, 2012
Messages
268
Solutions
4
Reaction score
63
Alright the log is clean no errors appeared but its seems like is not executing the function because the players are dying.
I took the script from a old TFS 1.0 and I'm trying to change it to TFS 1.3.
I'm not running this in script folder I'm running it on XML file.


Lua:
function onLogin(cid)
    local player = Player(cid)
    player:registerEvent("Arena_Death")
return true
    end
  
    local arena = {
        from = {x=822, y=1056, z=9}, -- left top corner of  arena
        to = {x=857, y=1072, z=9}, -- right bottom corner of  arena
        temple = { x = 787, y = 1012, z = 7 } -- change it to temple pos
   }



local conditions = {CONDITION_POISON,
CONDITION_FIRE,
CONDITION_ENERGY,
CONDITION_PARALYZE,
CONDITION_DRUNK,
CONDITION_DROWN,
CONDITION_FREEZING,
CONDITION_DAZZLED,
CONDITION_INFIGHT,
CONDITION_EXHAUST_HEAL,
CONDITION_SPELLCOOLDOWN,
CONDITION_SPELLGROUPCOOLDOWN,
CONDITION_EXHAUST_COMBAT,
CONDITION_EXHAUSTED,
CONDITION_EXHAUST,
CONDITION_EXHAUST_WEAPON,
CONDITION_BLEEDING,
CONDITION_CURSED
}

    function onPrepareDeath(cid, killer)
        local player = creature(cid)
        if isInRange(getPlayerPosition(cid), arena.from,arena.to) then
            if isPlayer(cid) then
                player:addHealth(player:getMaxHealth())
                player:addMana(player:getMaxMana())
                player:teleportTo(arena.temple, true)
                player:removeCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)
                doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You Have Exit the PVP-ARENA.")
                for _, condition in ipairs(conditions) do
                    if(player:getCondition(condition)) then
                        player:removeCondition(condition)
                    end
                end
                    if isInArray({SKULL_WHITE}, player:getSkull()) then
                    player:setSkull(SKULL_NONE)
                    player:setSkullTime(0)
                    end
              
                return false
            end
        end
       return true
    end
  
    function isInRange(pos, fromPos, toPos)
       return pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z
    end
i saw the function registered in the cpp files
Code:
onPrepareDeath

i have it registered on XML as

Code:
<event type="preparedeath" name="Arena_Death" script="Arena_Death.lua"/>
<event type="login" name="Arena_Login" script="Arena_Death.lua"/>

let me know whats wrong thanks!.
 
put this on your data/scripts folder and test:

Lua:
local conditions = {
    CONDITION_POISON, CONDITION_FIRE,
    CONDITION_ENERGY, CONDITION_PARALYZE,
    CONDITION_DRUNK, CONDITION_DROWN,
    CONDITION_FREEZING, CONDITION_DAZZLED,
    CONDITION_BLEEDING, CONDITION_CURSED
}

local creatureevent = CreatureEvent("Arena_Death")

function creatureevent.onPrepareDeath(creature, killer)
    if creature:isPlayer() and creature:getPosition():isInRange(Position(822, 1056, 9), Position(857, 1072, 9))
        creature:addHealth(creature:getMaxHealth())
        creature:addMana(creature:getMaxMana())
        creature:teleportTo(arena.temple)
        creature:teleportTo(player:getTown():getTemplePosition())
        creature:removeCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)
        creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You Have Exit the PVP-ARENA.")
        for _, condition in ipairs(conditions) do
            if creature:getCondition(condition) then
                creature:removeCondition(condition)
            end
        end
        if table.contains({SKULL_WHITE}, creature:getSkull()) then
            creature:setSkull(SKULL_NONE)
            creature:setSkullTime(0)
        end
    end
    return true
end

creatureevent:register()

local creatureevent2 = CreatureEvent("example")

function creatureevent2.onLogin(player)
    player:registerEvent("Arena_Death")
    return true
end

creatureevent2:register()
 
put this on your data/scripts folder and test:

Lua:
local conditions = {
    CONDITION_POISON, CONDITION_FIRE,
    CONDITION_ENERGY, CONDITION_PARALYZE,
    CONDITION_DRUNK, CONDITION_DROWN,
    CONDITION_FREEZING, CONDITION_DAZZLED,
    CONDITION_BLEEDING, CONDITION_CURSED
}

local creatureevent = CreatureEvent("Arena_Death")

function creatureevent.onPrepareDeath(creature, killer)
    if creature:isPlayer() and creature:getPosition():isInRange(Position(822, 1056, 9), Position(857, 1072, 9)) then
        creature:addHealth(creature:getMaxHealth())
        creature:addMana(creature:getMaxMana())
        creature:teleportTo(787, 1012, 7)
        creature:teleportTo(player:getTown():getTemplePosition())
        creature:removeCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)
        creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You Have Exit the PVP-ARENA.")
        for _, condition in ipairs(conditions) do
            if creature:getCondition(condition) then
                creature:removeCondition(condition)
            end
        end
        if table.contains({SKULL_WHITE}, creature:getSkull()) then
            creature:setSkull(SKULL_NONE)
            creature:setSkullTime(0)
        end
    end
    return true
end

creatureevent:register()

local creatureevent2 = CreatureEvent("example")

function creatureevent2.onLogin(player)
    player:registerEvent("Arena_Death")
    return true
end

creatureevent2:register()
It didn't work :/
 
It is possible that you are using a custom engine and do not have all the correct changes from official TFS.
the onPreparedDeath event was created with the main purpose of preventing the death of a creature

I do not have the correct follow-up of the PR that must be implemented, but if I find them I will leave the link here
 
I would change scan area to tables, like this

Lua:
participants = { }

function Player.isParticipatingArena(self)

if not self then
return nil
end

for _, v in pairs(participants)
     if v == self:getId() then
       return true
     end
end

return false
end

Lua:
function Player.removeFromArenaTable(self)

if not self then
return nil
end

for i, v in ipairs(participants) do
    if v == self:getId() then
         return table.remove(participants, i)
    end
end

return false
end

Lua:
if player:join then -- just the func when player enter to arena.
      table.insert(participants, player:getId())
end

Lua:
-- on death event
if player:isParticipatingArena() then
    print("this player was on arena.")
     --- do smth
  player:removeFromArenaTable()
  end

but solution for your problem its post above from @Codinablack
if its still not work or sometimes not work, the scan area func that is completly uncessary and slow have problem.
 
Last edited:
Back
Top