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

Exp From Players

Mera Mero

Guess Who?
Joined
Dec 27, 2014
Messages
417
Reaction score
86
Ey OTLanders,

I've searched around for exp script or a solution for gaining exp by killing people and i couldn't find anything that may help me. I was looking for something that make players take exp from high/low levels and i can handle the amount of it like the level that the player will lose, it should be divided on the killers.

For EX.
Player level 100 died by 2 level 50 and he lost like 1 level so this level should be divided for both of them

tfs 0.4
 
worldType = "Hardcore"
rateExperienceFromPlayers = 3
config lua
I am using this one in config.lua
Code:
    minLevelThresholdForKilledPlayer = 0.9
    maxLevelThresholdForKilledPlayer = 40

Code:
    rateExperienceFromPlayers = 0.05
So which one should i use and how can i balance it to make it fair for all players when they kill each other.
 
Lua:
function onKill(cid, target, lastHit)
    local attackPlayer = Player(target)
    if not attackPlayer then
        return true
    end

    for id, damage in pairs(attackPlayer:getDamageMap()) do
        local player = Player(id)
        if player then
          if attackPlayer:getTile():hasFlag(TILESTATE_PVPZONE) == false then
                local experience = attackPlayer:getExperience()
                local expFormula = ((experience / 800) * 1)
                player:addExperience(math.floor(expFormula), true)
            end
        end
    end
end
 
I am using this one in config.lua
Code:
    minLevelThresholdForKilledPlayer = 0.9
    maxLevelThresholdForKilledPlayer = 40

Code:
    rateExperienceFromPlayers = 0.05
So which one should i use and how can i balance it to make it fair for all players when they kill each other.
rateExperienceFromPlayers = 4 (thats enough to level from just 2 players to top of server without killing mobs 1.5-2 is enough)
 
Lua:
function onKill(cid, target, lastHit)
    local attackPlayer = Player(target)
    if not attackPlayer then
        return true
    end

    for id, damage in pairs(attackPlayer:getDamageMap()) do
        local player = Player(id)
        if player then
          if attackPlayer:getTile():hasFlag(TILESTATE_PVPZONE) == false then
                local experience = attackPlayer:getExperience()
                local expFormula = ((experience / 800) * 1)
                player:addExperience(math.floor(expFormula), true)
            end
        end
    end
end
29glsid.jpg

Somehow the player do not die normally and stands with 0 hp
 
Lua:
function onKill(cid, target, lastHit)

  if(isPlayer(cid) and isPlayer(target)) then
    if getPlayerIp(cid) ~= getPlayerIp(target) then
      doPlayerAddExperience(cid, (getPlayerExperience(target))) -- you will likely want to introduce a formula here
      else
      doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You will not receive anything for killing players of the same IP.")
    end
  end

return true
end

You will need to use damagemap in this script to get it to divide between the players like you want it - there is a working example of damagemap above, you will need to adjust it slightly to work with the 0.4 functions though.

EDIT: I don't think 0.4 ever actually had a damagemap lua function added unfortunately - People using TFS 0.4 should consider migrating to TFS 1.x.
If your heart is set on using 0.4 for whatever reason, you will need to add a damagemap lua function to the source.
@Diath wrote a piece of code that will put you on the right path:
Lua - onPrepareDeath(cid, deathlist) problem (https://otland.net/threads/onpreparedeath-cid-deathlist-problem.132092/post-1279374)
 
Last edited:
Back
Top