• 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] Custom Experience Rate

hodleo

Formerly cbrm -Crypto enthusiast, Retired scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,598
Solutions
3
Reaction score
955
Location
Caribbean Sea
If you add @Evil Hero's player events, then you can manipulate the exp gained or lost by a player.
Here I show you how to add experience bonus rate for players.

/events/scripts/player.lua
Normally you just have these lines when you end adding the new events:
Code:
function Player:onGainExperience(target, exp, rawExp)
    return exp
end

function Player:onLoseExperience(exp)
    return exp
end

For the first one, you can modify the experience gained with some conditions like this
Code:
function Player:onGainExperience(target, exp, rawExp)
    if self:getStorageValue(STORAGE) >= 1 then
        local EXTRA_EXP_RATE = 0.5 --+50% exp rate
        local stamina = 1
        if getConfigInfo('staminaSystem') == 'yes' then
            stamina = (self:getPremiumDays() > 0 and self:getStamina() > 2400) and 1.5 or 0.5
        end
        return rawExp*getConfigInfo('rateExp')*stamina*(1+EXTRA_EXP_RATE)
    end
    return exp
end
>self:getStorageValue(storage) >= 1
>EXTRA_EXP_RATE

With some little effort, you can also make it reduce the lost experience.
 
If you add @Evil Hero's player events, then you can manipulate the exp gained or lost by a player.
Here I show you how to add experience bonus rate for players.

/events/scripts/player.lua
Normally you just have these lines when you end adding the new events:
Code:
function Player:onGainExperience(target, exp)
    return exp
end

function Player:onLoseExperience(exp)
    return exp
end

For the first one, you can modify the experience gained with some conditions like this, where I've isolated the original experience given by the creature:
Code:
function Player:onGainExperience(target, exp)
    if self:getStorageValue(storage) >= 1 then
        local multiplier, orig = 1
        if getConfigInfo('staminaSystem') == 'yes' then
            multiplier = (self:getPremiumDays() > 0 and self:getStamina() > 2400) and 1.5 or 0.5
        end
        orig = exp/(getConfigInfo('rateExp')*multiplier)
        return orig*(getConfigInfo('rateExp')+multiplier+EXTRA_EXP_PERCENT)
    end
    return exp
end
>self:getStorageValue(storage) >= 1
>EXTRA_EXP_PERCENT

With some little effort, you can also make it reduce the lost experience.
The exp is already multiplied, you don't need to check for config rates and stamina, as they're already evaluated :p
 
but you can't set a custom exp rate if you don't isolate the original exp or divide the given exp
hmm maybe orig. exp could be a new param in your function
 
but you can't set a custom exp rate if you don't isolate the original exp or divide the given exp
hmm maybe orig. exp could be a new param in your function
that certainly is true, I'll modify the function so it returns exp without multipliers and with multipliers how about that?
like
Code:
Player:onGainExperience(target, exp, rawExp)
 
yepp better, as an optional param. that returns numeric value without rateExp or stamina multipliers
 
Back
Top