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

CreatureEvent Experience for killing higher level players

gunz

GunzOT Owner
Premium User
Joined
Dec 30, 2007
Messages
529
Solutions
5
Reaction score
191
Hello,

I've made a script to support PvP on optional pvp servers. Players that kills higher level will get experience as on pvp enforced server.

Features:
- Real tibia formula for pvp-enforced servers
- doesn't give exp in pvp arenas (pvp tiles)
- divide exp to the whole deathlist (that are lower level of course)

creaturescripts/scripts/pvpenfo.lua
Code:
function onPrepareDeath(cid, deathList)
        local tile = getTileInfo(getPlayerPosition(cid))
        if(tile.hardcore == false) then
                local pl_count = table.getn(deathList)
                local j = 0
                for _, pid in ipairs(deathList) do
                        if (isPlayer(cid) and isPlayer(pid) and getPlayerLevel(cid) > getPlayerLevel(pid)) then
                                local priorita = 1 - (j * 0.1)
                                local exp = 0
                                if (pl_count > 2) then
                                        exp = math.floor((((1 - (getPlayerLevel(pid) * 1.0) / getPlayerLevel(cid)) * 0.05 * getPlayerExperience(cid)) / pl_count) * priorita)
                                else
                                        exp = math.floor((((1 - (getPlayerLevel(pid) * 1.0) / getPlayerLevel(cid)) * 0.05 * getPlayerExperience(cid)) / (pl_count + 2)) * priorita)
                                end
                                doPlayerAddExp(pid, exp)
                                local pos = getPlayerPosition(pid)
                                doPlayerSendTextMessage(pid, MESSAGE_EXPERIENCE, "You gained " .. exp .. " experience for killing higher level than you.", exp, COLOR_WHITE, pos)
                                for _, spec in ipairs(getSpectators(pos, 7, 5, false)) do
                                        if (isPlayer(spec) and spec ~= pid) then
                                                doPlayerSendTextMessage(spec, MESSAGE_EXPERIENCE, getCreatureName(pid) .. " gained " .. exp .. " experience for killing " .. getCreatureName(cid) .. ".", exp, COLOR_WHITE, pos)
                                        end
                                end

                        end
                        j = j + 1
                end
        end
        return true
end

Add this line to creaturescripts.xml
Code:
<event type="preparedeath" name="pvpenfo" event="script" value="pvpenfo.lua"/>

Add this line to creaturescripts/scripts/login.lua
Code:
registerCreatureEvent(cid, "pvpenfo")

Tested and works on 9.1+ server.

Have fun.
 
Last edited:
Does it works for 0.3.6? because my players dont get any exp for killing eachother. Not in pvp, not in pvp-enforced...
 
Error on line 7:

[Error - LuaInterface::loadFile] data/creaturescripts/scripts/pvpenfo.lua:7: ')' expected near 'getPlayerLevel'

I'm using tfs 0.4; I guess this script will work in higher versions...
 
Hello,

I've made a script to support PvP on optional pvp servers. Players that kills higher level will get experience as on pvp enforced server.

Features:
  • Real tibia formula for pvp-enforced servers
  • doesn't give exp in pvp arenas (pvp tiles)
  • divide exp to the whole deathlist (that are lower level of course)

creaturescripts/scripts/pvpenfo.lua
Code:
function onPrepareDeath(cid, deathList)
        local tile = getTileInfo(getPlayerPosition(cid))
        if(tile.hardcore == false) then
                local pl_count = table.getn(deathList)
                local j = 0
                for _, pid in ipairs(deathList) do
                        if (isPlayer(cid) and isPlayer(pid) and getPlayerLevel(cid) > getPlayerLevel(pid)) then
                                local priorita = 1 - (j * 0.1)
                                local exp = 0
                                if (pl_count > 2) then
                                        exp = math.floor((((1 - (getPlayerLevel(pid) * 1.0) / getPlayerLevel(cid)) * 0.05 * getPlayerExperience(cid)) / pl_count) * priorita)
                                else
                                        exp = math.floor((((1 - (getPlayerLevel(pid) * 1.0) / getPlayerLevel(cid)) * 0.05 * getPlayerExperience(cid)) / (pl_count + 2)) * priorita)
                                end
                                doPlayerAddExp(pid, exp)
                                local pos = getPlayerPosition(pid)
                                doPlayerSendTextMessage(pid, MESSAGE_EXPERIENCE, "You gained " .. exp .. " experience for killing higher level than you.", exp, COLOR_WHITE, pos)
                                for _, spec in ipairs(getSpectators(pos, 7, 5, false)) do
                                        if (isPlayer(spec) and spec ~= pid) then
                                                doPlayerSendTextMessage(spec, MESSAGE_EXPERIENCE, getCreatureName(pid) .. " gained " .. exp .. " experience for killing " .. getCreatureName(cid) .. ".", exp, COLOR_WHITE, pos)
                                        end
                                end

                        end
                        j = j + 1
                end
        end
        return true
end

Add this line to creaturescripts.xml
Code:
<event type="preparedeath" name="pvpenfo" event="script" value="pvpenfo.lua"/>

Add this line to creaturescripts/scripts/login.lua
Code:
registerCreatureEvent(cid, "pvpenfo")

Tested and works on 9.1+ server.

Have fun.
How to increase the level of combat?
 
Back
Top