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

Lua Exp ring or necklace TF 1.3

klarkarak

Member
Joined
Nov 19, 2011
Messages
26
Reaction score
8
Location
Mexico
Im looking an script for a ring or necklace that gives me experience when you have it equipped, plz
 
Solution
Try this :)


Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        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
    local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
    exp = exp * expStage
    baseExp = rawExp * expStage
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = expStage...
you can use something like this if you want:

data/scripts/necklaceExp.lua

Lua:
local ev = EventCallback

function ev.onGainExperience(player, source, exp, rawExp)
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
    if necklace and necklace:getId() == 2661 then
        exp = exp * 1.25
    end
    return exp
end

this way, when you have the necklace equipped, than you receive 25% more experience
 
you can use something like this if you want:

data/scripts/necklaceExp.lua

Lua:
local ev = EventCallback

function ev.onGainExperience(player, source, exp, rawExp)
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
    if necklace and necklace:getId() == 2661 then
        exp = exp * 1.25
    end
    return exp
end

this way, when you have the necklace equipped, than you receive 25% more experience
Thaks for the script, but i have this error. could you help me plz
 

Attachments

Thaks for the script, but i have this error. could you help me plz
You should have mentioned that you are using the OTServ Br engine, that engine does not have the EventCallback system
the code is only compatible with official TFS 1.3
 
Last edited:
Share your Player:onGainExperience code from:

/data/events/scripts/player.lua

And perhaps I can help you convert Sarah's suggestion to your code base :)
 
Share your Player:onGainExperience code from:

/data/events/scripts/player.lua

And perhaps I can help you convert Sarah's suggestion to your code base :)
function Player:eek:nGainExperience(source, exp, rawExp)
if not source or source:isPlayer() then
return exp
end

there is, thanks for helping me :)
 
Okay, let's try this:

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

    -- identify the necklace slot.
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)

    -- if the necklace is our "extra XP item"
    if necklace and necklace:getId() == 2661 then
        -- Then give the player extra exp.
        exp = exp * 1.25
    end

    return exp
end

However, your onGainExperience has no functionality for adding extra exp for stages or stamina. Are you sure that you copied the whole function?
This is how the function looks in OTServBR latest version:

In case you missed the remaining functionality, i'll add this code-snippet for you to try as well:

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        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
    local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
    exp = exp * expStage
    baseExp = rawExp * expStage
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = expStage
    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))
            break
        end
        if (self:getPreyTimeLeft(slot) / 60) > 0 then
            preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check
        end
    end

    -- Store Bonus
    useStaminaXp(self) -- Use store boost stamina

    local Boost = self:getExpBoostStamina()
    local stillHasBoost = Boost > 0
    local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0

    self:setStoreXpBoost(storeXpBoostAmount)

    if (storeXpBoostAmount > 0) then
        exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost
    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 * 1.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5 --TODO destroy loot of people with 840- stamina
            self:setStaminaXpBoost(50)
        else
            self:setStaminaXpBoost(100)
        end
    end
          
    -- Boosted creature
    if source:getName():lower() == (Game.getBoostedCreature()):lower() then
        exp = exp * 2
    end

    -- Necklace Extra EXP boost
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)

    -- if the necklace is our "extra XP item"
    if necklace and necklace:getId() == 2661 then

        -- Then give the player extra EXP.
        exp = exp * 1.25 -- 25% extra EXP.
    end

    -- Event scheduler
    if SCHEDULE_EXP_RATE ~= 100 then
        exp = (exp * SCHEDULE_EXP_RATE)/100
    end
    self:setBaseXpGain(displayRate * 100)
    return exp
end

Don't forget to go into data/events/events.xml and change
<event class="Player" method="onGainExperience" enabled="0" />
to:
<event class="Player" method="onGainExperience" enabled="1" />
Which enables the LUA function for your server :)

edit:
Credits for the extra experience functionality goes to

Sarah Wesker

 
Last edited:
Okay, let's try this:

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

    -- identify the necklace slot.
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)

    -- if the necklace is our "extra XP item"
    if necklace and necklace:getId() == 2661 then
        -- Then give the player extra exp.
        exp = exp * 1.25
    end

    return exp
end

However, your onGainExperience has no functionality for adding extra exp for stages or stamina. Are you sure that you copied the whole function?
This is how the function looks in OTServBR latest version:

In case you missed the remaining functionality, i'll add this code-snippet for you to try as well:

Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        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
    local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
    exp = exp * expStage
    baseExp = rawExp * expStage
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = expStage
    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))
            break
        end
        if (self:getPreyTimeLeft(slot) / 60) > 0 then
            preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check
        end
    end

    -- Store Bonus
    useStaminaXp(self) -- Use store boost stamina

    local Boost = self:getExpBoostStamina()
    local stillHasBoost = Boost > 0
    local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0

    self:setStoreXpBoost(storeXpBoostAmount)

    if (storeXpBoostAmount > 0) then
        exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost
    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 * 1.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5 --TODO destroy loot of people with 840- stamina
            self:setStaminaXpBoost(50)
        else
            self:setStaminaXpBoost(100)
        end
    end
        
    -- Boosted creature
    if source:getName():lower() == (Game.getBoostedCreature()):lower() then
        exp = exp * 2
    end

    -- Necklace Extra EXP boost
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)

    -- if the necklace is our "extra XP item"
    if necklace and necklace:getId() == 2661 then

        -- Then give the player extra EXP.
        exp = exp * 1.25 -- 25% extra EXP.
    end

    -- Event scheduler
    if SCHEDULE_EXP_RATE ~= 100 then
        exp = (exp * SCHEDULE_EXP_RATE)/100
    end
    self:setBaseXpGain(displayRate * 100)
    return exp
end

Don't forget to go into data/events/events.xml and change
<event class="Player" method="onGainExperience" enabled="0" />
to:
<event class="Player" method="onGainExperience" enabled="1" />
Which enables the LUA function for your server :)

edit:
Credits for the extra experience functionality goes to

Sarah Wesker

I put the first script in \data\scripts\amulet.lua

in the second you are right i dont put the complete Player:eek:nGainExperience code
but when I paste the code that you put, in the console appears this error
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:player@onGainExperience
data/events/scripts/player.lua:748: attempt to index global 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/events/scripts/player.lua:748: in function <data/events/scripts/player.lua:680>

this is what i have in line 748
local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)


and i have activated <event class="Player" method="onGainExperience" enabled="1" />

the item doesnt give more exp, and the exp stage doesnt work
 
Last edited:
Try this :)


Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        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
    local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
    exp = exp * expStage
    baseExp = rawExp * expStage
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = expStage
    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))
            break
        end
        if (self:getPreyTimeLeft(slot) / 60) > 0 then
            preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check
        end
    end

    -- Store Bonus
    useStaminaXp(self) -- Use store boost stamina

    local Boost = self:getExpBoostStamina()
    local stillHasBoost = Boost > 0
    local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0

    self:setStoreXpBoost(storeXpBoostAmount)

    if (storeXpBoostAmount > 0) then
        exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost
    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 * 1.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5 --TODO destroy loot of people with 840- stamina
            self:setStaminaXpBoost(50)
        else
            self:setStaminaXpBoost(100)
        end
    end
          
    -- Boosted creature
    if source:getName():lower() == (Game.getBoostedCreature()):lower() then
        exp = exp * 2
    end

    -- Necklace Extra EXP boost
    local necklace = self:getSlotItem(CONST_SLOT_NECKLACE)

    -- if the necklace is our "extra XP item"
    if necklace and necklace:getId() == 2661 then

        -- Then give the player extra EXP.
        exp = exp * 1.25 -- 25% extra EXP.
    end

    -- Event scheduler
    if SCHEDULE_EXP_RATE ~= 100 then
        exp = (exp * SCHEDULE_EXP_RATE)/100
    end
    self:setBaseXpGain(displayRate * 100)
    return exp
end
 
Solution
Try this :)


Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        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
    local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
    exp = exp * expStage
    baseExp = rawExp * expStage
    if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
        displayRate = expStage
    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))
            break
        end
        if (self:getPreyTimeLeft(slot) / 60) > 0 then
            preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check
        end
    end

    -- Store Bonus
    useStaminaXp(self) -- Use store boost stamina

    local Boost = self:getExpBoostStamina()
    local stillHasBoost = Boost > 0
    local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0

    self:setStoreXpBoost(storeXpBoostAmount)

    if (storeXpBoostAmount > 0) then
        exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost
    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 * 1.5
            self:setStaminaXpBoost(150)
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5 --TODO destroy loot of people with 840- stamina
            self:setStaminaXpBoost(50)
        else
            self:setStaminaXpBoost(100)
        end
    end
         
    -- Boosted creature
    if source:getName():lower() == (Game.getBoostedCreature()):lower() then
        exp = exp * 2
    end

    -- Necklace Extra EXP boost
    local necklace = self:getSlotItem(CONST_SLOT_NECKLACE)

    -- if the necklace is our "extra XP item"
    if necklace and necklace:getId() == 2661 then

        -- Then give the player extra EXP.
        exp = exp * 1.25 -- 25% extra EXP.
    end

    -- Event scheduler
    if SCHEDULE_EXP_RATE ~= 100 then
        exp = (exp * SCHEDULE_EXP_RATE)/100
    end
    self:setBaseXpGain(displayRate * 100)
    return exp
end
Thanks it works!!!

thanks for being patient
 
you can use something like this if you want:

data/scripts/necklaceExp.lua

Lua:
local ev = EventCallback

function ev.onGainExperience(player, source, exp, rawExp)
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
    if necklace and necklace:getId() == 2661 then
        exp = exp * 1.25
    end
    return exp
end

this way, when you have the necklace equipped, than you receive 25% more experience
Trying to use that but don't really works and i have no error :/ tfs 1.5 8.0 by nekiro
 
Back
Top