• 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.2] Bonus XP for using Client 12, instead of 10

d0gw4r

New Member
Joined
Jun 6, 2019
Messages
55
Solutions
1
Reaction score
4
Location
Brazil
Hello there,

Can someone help me with giving a exp bonus for who uses a client instead of another?
I tried to put a code inside this function, but when I login client 12 the exp given is the same as the client 10.

The following image shows how the code is set: (folder: /events/scripts/player.lua)
1571243581911.png


Here is the code itself:

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
    local clientVersion = player:getClient()
        if clientVersion >= 1200 then
            exp = exp * 1.3
        end
        return exp
    end

I don't what I'm doing wrong here. So if someone could help me, I'll be very grateful.

Thanks!
 
Last edited:
Solution
Now it's giving me this error in terminal:

Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onGainExperience
data/events/scripts/player.lua:738: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:738: in function <data/events/scripts/player.lua:732>

Change:
Lua:
local clientVersion = player:getClient().version

To:
Lua:
local clientVersion = self:getClient().version


Edit: the full code snippet that was asked about in this thread:
Lua:
   -- Client 12 Bonus Experience
    local clientVersion = self:getClient().version
    if clientVersion >= 1200 then
        exp = exp * 2
    end
I already have this here:
1571251027690.png

I just don't know where/how I can see the client version.

I tried to set it manually from config.lua, and only my client 12 worked.

Lua:
-- Version Manual
clientVersionMin = 1200
clientVersionMax = 1200

But the exp bonus isn't working yet.
 
I already have this here:
View attachment 39752

I just don't know where/how I can see the client version.

I tried to set it manually from config.lua, and only my client 12 worked.

Lua:
-- Version Manual
clientVersionMin = 1200
clientVersionMax = 1200

But the exp bonus isn't working yet.

What I meant was, in your code you have this:
Lua:
local clientVersion = player:getClient()

Change it to this:
Lua:
local clientVersion = player:getClient().version
 
It stills don't work.


Edit:

Where should I put this?

Code:
print(player:getClient())
 
Last edited:
It stills don't work.

Post your full function Player:eek:nGainExperience(source, exp, rawExp) code here

Edit:

It should not be inside this "if statement"
Lua:
if not source or source:isPlayer() then
 
Last edited:
Post your full function Player:eek:nGainExperience(source, exp, rawExp) code here

Edit:

It should not be inside this "if statement"
Lua:
if not source or source:isPlayer() then



Here:

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
    local clientVersion = player:getClient().version
        if clientVersion >= 1200 then
            exp = exp * 2
        end
        return exp
    end
   
        -- Soul Regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Experience Stage Multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
    baseExp = rawExp * Game.getExperienceStage(self:getLevel())
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = Game.getExperienceStage(self:getLevel())
        else
        displayRate = 1
    end

    -- Prey Bonus
    for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
        if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
            exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
            preyTimeLeft(self, slot) -- slot consumption
            break
        end
    end

    -- Store Bonus
    local Boost = self:getExpBoostStamina()
    useStaminaXp(self) -- Use store boost stamina
    self:setStoreXpBoost(Boost > 0 and 50 or 0)
    if (self:getExpBoostStamina() <= 0 and self:getStoreXpBoost() > 0) then
        self:setStoreXpBoost(0) -- Reset Store boost to 0 if boost stamina has ran out
    end
    if (self:getStoreXpBoost() > 0) then
        exp = exp + (baseExp * (self:getStoreXpBoost()/100)) -- Exp Boost
        displayRate = displayRate * ((self:getStoreXpBoost()+100)/100)
    end

    -- Stamina Bonus
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp + baseExp * 0.5
            displayRate = displayRate + Game.getExperienceStage(self:getLevel()) * 0.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
            self:setStaminaXpBoost(50)
            displayRate = displayRate * 0.5
        else
            self:setStaminaXpBoost(100)
        end
        for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
            if self:getPreyState(slot) == 2 then
             preyTimeLeft(self, slot) -- slot consumption
            end
        end
    end

    self:setBaseXpGain(displayRate * 100)
    return exp
end
 
@d0gw4r

Try this, All I did was move it outside of that if statement,
Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
    
    -- Client 12 Bonus Experience
    local clientVersion = player:getClient().version
        if clientVersion >= 1200 then
            exp = exp * 2
        end
        return exp
    end
  
        -- Soul Regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Experience Stage Multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
    baseExp = rawExp * Game.getExperienceStage(self:getLevel())
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = Game.getExperienceStage(self:getLevel())
        else
        displayRate = 1
    end

    -- Prey Bonus
    for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
        if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
            exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
            preyTimeLeft(self, slot) -- slot consumption
            break
        end
    end

    -- Store Bonus
    local Boost = self:getExpBoostStamina()
    useStaminaXp(self) -- Use store boost stamina
    self:setStoreXpBoost(Boost > 0 and 50 or 0)
    if (self:getExpBoostStamina() <= 0 and self:getStoreXpBoost() > 0) then
        self:setStoreXpBoost(0) -- Reset Store boost to 0 if boost stamina has ran out
    end
    if (self:getStoreXpBoost() > 0) then
        exp = exp + (baseExp * (self:getStoreXpBoost()/100)) -- Exp Boost
        displayRate = displayRate * ((self:getStoreXpBoost()+100)/100)
    end

    -- Stamina Bonus
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp + baseExp * 0.5
            displayRate = displayRate + Game.getExperienceStage(self:getLevel()) * 0.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
            self:setStaminaXpBoost(50)
            displayRate = displayRate * 0.5
        else
            self:setStaminaXpBoost(100)
        end
        for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
            if self:getPreyState(slot) == 2 then
             preyTimeLeft(self, slot) -- slot consumption
            end
        end
    end

    self:setBaseXpGain(displayRate * 100)
    return exp
end
 
@d0gw4r

Try this, All I did was move it outside of that if statement,
Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
  
    -- Client 12 Bonus Experience
    local clientVersion = player:getClient().version
        if clientVersion >= 1200 then
            exp = exp * 2
        end
        return exp
    end

        -- Soul Regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Experience Stage Multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
    baseExp = rawExp * Game.getExperienceStage(self:getLevel())
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = Game.getExperienceStage(self:getLevel())
        else
        displayRate = 1
    end

    -- Prey Bonus
    for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
        if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
            exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
            preyTimeLeft(self, slot) -- slot consumption
            break
        end
    end

    -- Store Bonus
    local Boost = self:getExpBoostStamina()
    useStaminaXp(self) -- Use store boost stamina
    self:setStoreXpBoost(Boost > 0 and 50 or 0)
    if (self:getExpBoostStamina() <= 0 and self:getStoreXpBoost() > 0) then
        self:setStoreXpBoost(0) -- Reset Store boost to 0 if boost stamina has ran out
    end
    if (self:getStoreXpBoost() > 0) then
        exp = exp + (baseExp * (self:getStoreXpBoost()/100)) -- Exp Boost
        displayRate = displayRate * ((self:getStoreXpBoost()+100)/100)
    end

    -- Stamina Bonus
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp + baseExp * 0.5
            displayRate = displayRate + Game.getExperienceStage(self:getLevel()) * 0.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
            self:setStaminaXpBoost(50)
            displayRate = displayRate * 0.5
        else
            self:setStaminaXpBoost(100)
        end
        for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
            if self:getPreyState(slot) == 2 then
             preyTimeLeft(self, slot) -- slot consumption
            end
        end
    end

    self:setBaseXpGain(displayRate * 100)
    return exp
end

Now it's giving exp rate x1, instead of staged.

Edit:

I guess it wasn't suppose to happen... '-'
It seems that end closed the function.

1571253915894.png
 
Now it's giving exp rate x1, instead of staged.

Edit:

I guess it wasn't suppose to happen... '-'
It seems that end closed the function.

View attachment 39753

Oops

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
    
    -- Client 12 Bonus Experience
    local clientVersion = player:getClient().version
    if clientVersion >= 1200 then
        exp = exp * 2
    end
  
        -- Soul Regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Experience Stage Multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
    baseExp = rawExp * Game.getExperienceStage(self:getLevel())
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = Game.getExperienceStage(self:getLevel())
        else
        displayRate = 1
    end

    -- Prey Bonus
    for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
        if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
            exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
            preyTimeLeft(self, slot) -- slot consumption
            break
        end
    end

    -- Store Bonus
    local Boost = self:getExpBoostStamina()
    useStaminaXp(self) -- Use store boost stamina
    self:setStoreXpBoost(Boost > 0 and 50 or 0)
    if (self:getExpBoostStamina() <= 0 and self:getStoreXpBoost() > 0) then
        self:setStoreXpBoost(0) -- Reset Store boost to 0 if boost stamina has ran out
    end
    if (self:getStoreXpBoost() > 0) then
        exp = exp + (baseExp * (self:getStoreXpBoost()/100)) -- Exp Boost
        displayRate = displayRate * ((self:getStoreXpBoost()+100)/100)
    end

    -- Stamina Bonus
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp + baseExp * 0.5
            displayRate = displayRate + Game.getExperienceStage(self:getLevel()) * 0.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
            self:setStaminaXpBoost(50)
            displayRate = displayRate * 0.5
        else
            self:setStaminaXpBoost(100)
        end
        for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
            if self:getPreyState(slot) == 2 then
             preyTimeLeft(self, slot) -- slot consumption
            end
        end
    end

    self:setBaseXpGain(displayRate * 100)
    return exp
end
 
Oops

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end

    -- Client 12 Bonus Experience
    local clientVersion = player:getClient().version
    if clientVersion >= 1200 then
        exp = exp * 2
    end

        -- Soul Regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Experience Stage Multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
    baseExp = rawExp * Game.getExperienceStage(self:getLevel())
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = Game.getExperienceStage(self:getLevel())
        else
        displayRate = 1
    end

    -- Prey Bonus
    for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
        if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
            exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
            preyTimeLeft(self, slot) -- slot consumption
            break
        end
    end

    -- Store Bonus
    local Boost = self:getExpBoostStamina()
    useStaminaXp(self) -- Use store boost stamina
    self:setStoreXpBoost(Boost > 0 and 50 or 0)
    if (self:getExpBoostStamina() <= 0 and self:getStoreXpBoost() > 0) then
        self:setStoreXpBoost(0) -- Reset Store boost to 0 if boost stamina has ran out
    end
    if (self:getStoreXpBoost() > 0) then
        exp = exp + (baseExp * (self:getStoreXpBoost()/100)) -- Exp Boost
        displayRate = displayRate * ((self:getStoreXpBoost()+100)/100)
    end

    -- Stamina Bonus
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp + baseExp * 0.5
            displayRate = displayRate + Game.getExperienceStage(self:getLevel()) * 0.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
            self:setStaminaXpBoost(50)
            displayRate = displayRate * 0.5
        else
            self:setStaminaXpBoost(100)
        end
        for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
            if self:getPreyState(slot) == 2 then
             preyTimeLeft(self, slot) -- slot consumption
            end
        end
    end

    self:setBaseXpGain(displayRate * 100)
    return exp
end


Now it's giving me this error in terminal:

Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onGainExperience
data/events/scripts/player.lua:738: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:738: in function <data/events/scripts/player.lua:732>

Edit:
And the exp rate stills 1x... :(
 
Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
    
    -- Client 12 Bonus Experience
    local clientVersion = self:getClient().version
    if clientVersion >= 1200 then
        exp = exp * 2
    end
 
        -- Soul Regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Experience Stage Multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
    baseExp = rawExp * Game.getExperienceStage(self:getLevel())
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = Game.getExperienceStage(self:getLevel())
        else
        displayRate = 1
    end

    -- Prey Bonus
    for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
        if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
            exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
            preyTimeLeft(self, slot) -- slot consumption
            break
        end
    end

    -- Store Bonus
    local Boost = self:getExpBoostStamina()
    useStaminaXp(self) -- Use store boost stamina
    self:setStoreXpBoost(Boost > 0 and 50 or 0)
    if (self:getExpBoostStamina() <= 0 and self:getStoreXpBoost() > 0) then
        self:setStoreXpBoost(0) -- Reset Store boost to 0 if boost stamina has ran out
    end
    if (self:getStoreXpBoost() > 0) then
        exp = exp + (baseExp * (self:getStoreXpBoost()/100)) -- Exp Boost
        displayRate = displayRate * ((self:getStoreXpBoost()+100)/100)
    end

    -- Stamina Bonus
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp + baseExp * 0.5
            displayRate = displayRate + Game.getExperienceStage(self:getLevel()) * 0.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
            self:setStaminaXpBoost(50)
            displayRate = displayRate * 0.5
        else
            self:setStaminaXpBoost(100)
        end
        for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
            if self:getPreyState(slot) == 2 then
             preyTimeLeft(self, slot) -- slot consumption
            end
        end
    end

    self:setBaseXpGain(displayRate * 100)
    return exp
end
 
Now it's giving me this error in terminal:

Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onGainExperience
data/events/scripts/player.lua:738: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:738: in function <data/events/scripts/player.lua:732>

Change:
Lua:
local clientVersion = player:getClient().version

To:
Lua:
local clientVersion = self:getClient().version


Edit: the full code snippet that was asked about in this thread:
Lua:
   -- Client 12 Bonus Experience
    local clientVersion = self:getClient().version
    if clientVersion >= 1200 then
        exp = exp * 2
    end
 
Last edited:
Solution
Back
Top