• 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.0 Bonus Experience

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,318
Solutions
35
Reaction score
435
Hello Otlanders,

Could someone help me make a script that would give players with a certain storage value 20% Bonus experience for killing all types of monsters?
 
Last edited:
Just make a simple onKill creature event and fetch exp gained from the monster and add exp to the player equal to expFromMonster * 0.2 ?

I don't have a TFS 1.0 disto and is too lazy to download it, but this is a really basic script.
 
Yes sounds simple enough but the problem i was running into is what is the proper function to use in order to get the monsters Experience?

I couldn't find the correct function, I tried monsterType:getExperience() but it was returning a nil value.

Here are the functions for TFS 1.0: http://otland.net/threads/tfs-1-0-lua-functions.197202/
Clearly for me it was not so easy, but ofcourse I will keep trying to solve it.
 
Code:
function onKill(cid, target, lastHit)
    local attackMonster = MonsterType(target)
    if not attackMonster then
        return true
    end

    for id, damage in pairs(attackMonster:getDamageMap()) do
        local player = Player(cid)
        if player then
            if getPlayerVipTime(player) > 100 then
                local experience = attackMonster:getExperience()
                local expFormula = (experience * 0.20)
                player:addExperience(math.floor(expFormula), true)
            end
        end
    end
end

This was my attempt but it's not working. @Milice
 
what about this?
Code:
function onKill(cid, target, lastHit)
  local attackMonster = MonsterType(getCreatureName(target))
  if not attackMonster then
    return true
  end

  local player = Player(getCreatureName(cid))

   if player then

     if getPlayerVipTime(player) > 100 then
       player:addExperience(math.floor(attackMonster:getExperience() * 0.2), true)
     end
  end
   return true
end
 
Last edited:
Thanks a lot, the bonus experience is working now!!!

However, the problem right now is that only the player who get's the last hit earns experience. So if 5 players are killing a boss then only that guy that takes the last hit earns the experience.
 
You need to use getDamageMap so all attackers receive experience :p

Code:
function onKill(cid, target, lastHit)
    local monster = Monster(target)
    if not monster then
        return true
    end
  
    for id, damage in pairs(monster:getDamageMap()) do
        local player = Player(id)
        if player then
            local experience = monster:getType():getExperience()
            local expFormula = (experience * 0.20)
            player:addExperience(math.floor(expFormula), true)
        end
    end
end
 
Last edited:
I'm struggling a little because I see a function for creature:getDamageMap() and I see a function for monsterType:getExperience(), now how do I connect those 2 things? or am I completely going the wrong way?

With this script I still get the bonus experience but once again only one player is gaining experience. :(

Code:
function onKill(cid, target, lastHit)

  local attackMonster = MonsterType(getCreatureName(target))
  if not attackMonster then
    return true
  end

local creature = Creature(target)
local damageMap = creature:getDamageMap()

    for id, damage in pairs(damageMap) do
        local player = Player(id)
        if player then
            if getPlayerVipTime(player) > 100 then
            player:addExperience(math.floor(attackMonster:getExperience() * 0.2), true)
            end
        end
    end
   
  return true
end
 
You need to use getDamageMap so all attackers receive experience :p

Code:
function onKill(cid, target, lastHit)
    local attackMonster = Monster(target)
    if not attackMonster then
        return true
    end
  
    for id, damage in pairs(attackMonster:getDamageMap()) do
        local player = Player(id)
        if player then
            local experience = MonsterType(attackMonster:getName()):getExperience()
            local expFormula = (experience * 0.20)
            player:addExperience(math.floor(expFormula), true)
        end
    end
end

Hey @Ninja thanks for the help! With this script the same problem is occuring. The Bonus EXP is working but all the exp still goes to the player who takes the last hit.
 
Hey @Ninja thanks for the help! With this script the same problem is occuring. The Bonus EXP is working but all the exp still goes to the player who takes the last hit.
Are you testing with a GM character?

I just tested with 3 normal characters and all of them received bonus exp plus normal exp.
 
I have a question,

Is it possible that the bonus experience the player receives can be based upon the amount of damage he does?

Like right now even if he does only 100 dmg on a dragon he will get 140 exp (20% of 700) + whatever exp he earned for 100 dmg.

Is it possible to make it so the bonus 20% will be based upon the actual experience the player earns as opposed to 20% of the monsters total experience?
 
Code:
function onKill(cid, target, lastHit)
local monster = Monster(target)
if not monster then
return true
end

for id, damage in pairs(monster:getDamageMap()) do
local player = Player(id)
if player then
local experience = damage.total / monster:getType():getHealth() * monster:getType():getExperience() 
local expFormula = (experience * 0.20)
player:addExperience(math.floor(expFormula), true)
end
end
end
 
Back
Top