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

TalkAction [TFS 1.x] Global (Exp/Skill/Magic) Rate Boost

Erikas Kontenis

Board Moderator
Staff member
Board Moderator
Joined
Jul 3, 2009
Messages
1,859
Reaction score
557
Location
Lithuania
Hello, its been a while since I haven't contributed anything for open tibia community. So, since I am feeling pretty much active these days in open tibia development and having my own server so I am going to contribute a little of things that I do for my own server because open tibia community gives me back a lot too.

data\talkactions\scripts\global_rate_boost.lua
Lua:
local config = {
    ['exp'] = {skillKey = 17585, timeKey = 17589},
    ['skill'] = {skillKey = 17586, timeKey = 17590},
    ['magic'] = {skillKey = 17587, timeKey = 17591}
}

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")
    if split[3] == nil then
        player:sendCancelMessage("Insufficient parameters [(exp,skill,magic),percentage,hours].")
        return false
    end
    
    local skillName = split[1]
    local percentage = tonumber(split[2])
    local hours = tonumber(split[3])
    
    local globalStorage = config[skillName]
    if not globalStorage then
        player:sendCancelMessage("Skill name value must be one of the following: exp, skill, magic.")
        return false
    end

    if percentage <= 0 then
        player:sendCancelMessage("Percentage value must be higher than 0. For example, 50% means 1.5x higher rate.")
        return false
    end
    
    if hours <= 0 then
        player:sendCancelMessage("Hours value must be higher than 0.")
        return false
    end
    
    setGlobalStorageValue(globalStorage.skillKey, percentage)
    setGlobalStorageValue(globalStorage.timeKey, os.time() + hours * 60 * 60)
    broadcastMessage(player:getName() .. " have activated the global " .. percentage .. "% " .. skillName .. " rate boost for next " .. hours .. " " .. (hours == 1 and "hour" or "hours") .. ".", MESSAGE_STATUS_WARNING)
    
    return false
end
XML:
<talkaction words="/globalboost" separator=" " script="global_rate_boost.lua" />

data\events\scripts\player.lua (Custom Lines comment is the place where the changes have been applied)
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

    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())

    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)

        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end
    -- Custom Lines
    if getGlobalStorageValue(17589) > os.time() then
        exp = exp * (1 + getGlobalStorageValue(17585) / 100)
    end
    -- Custom Lines
    return exp
end

Lua:
function Player:onGainSkillTries(skill, tries)
    if APPLY_SKILL_MULTIPLIER == false then
        return tries
    end

    if skill == SKILL_MAGLEVEL then
        tries = tries * configManager.getNumber(configKeys.RATE_MAGIC)
        -- Custom Lines
        if getGlobalStorageValue(17591) > os.time() then
            tries = tries * (1 + getGlobalStorageValue(17587) / 100)
        end
        -- Custom Lines
        return tries
    end
    
    tries = tries * configManager.getNumber(configKeys.RATE_SKILL)
    -- Custom Lines
    if getGlobalStorageValue(17590) > os.time() then
        tries = tries * (1 + getGlobalStorageValue(17586) / 100)
    end
    -- Custom Lines
    return tries
end

pT72xmI.png

Type /globalboost exp,100,5 to active double exp boost for 5 hours.
 
Great job, I'll probably use this one. I'm just curious if this sentence is going to take down the exp for some players to 50%, shouldn't it be exp = exp * 1?


Lua:
exp = exp * 0.5
 
Not trying to stir up an older post but.....I am drawing a blank on how to return the time left for the global rate boost. I am piecing together a script for !exp for all the bonuses on my server.

Lua:
function onSay(player, words, param)
local p = player
local s = function(p, lv)
       local k = Game.getExperienceStage(lv)
       local st = p:getStamina()
         if st > 2400 then
           return k*1.5 .. " (stamina bonus)"
         elseif st < 1 then
           return 0 .. " (out of stamina)"
         elseif st < 841 then
           return k*0.5 .. " (stamina penalty)"
         else
           return k
         end
       end

   if words == "!exp" then
     local lv = p:getLevel()
     local eq = getGlobalStorageValue(17585)
     local global = getGlobalStorageValue(17589)
     p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need " .. ((50 * lv^3) - (150 * lv^2) + (400 * lv)) / 3 - p:getExperience() .. " experience more, for " .. lv+1 .. " level.")
     p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your Rate: x" .. s(p, lv))
        if getGlobalStorageValue(17589) > os.time() then
        local ttime = os.time()
        p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Server Bonus: x" .. eq .. ". Time left: " .. ttime".")
        end
     return false
   end
  p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have to spend " .. math.ceil((p:getVocation():getRequiredManaSpent(p:getBaseMagicLevel() + 1) - p:getManaSpent()) / configManager.getNumber(configKeys.RATE_MAGIC))  .. " mana more, for next magic level.")
return false
end

Returning an error
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/exp.lua:onSay
data/talkactions/scripts/exp.lua:25: attempt to call local 'ttime' (a number value)
stack traceback:
        [C]: in function 'ttime'
        data/talkactions/scripts/exp.lua:25: in function <data/talkactions/scripts/exp.lua:1>
 
Returning an error
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/exp.lua:onSay
data/talkactions/scripts/exp.lua:25: attempt to call local 'ttime' (a number value)
stack traceback:
        [C]: in function 'ttime'
        data/talkactions/scripts/exp.lua:25: in function <data/talkactions/scripts/exp.lua:1>
change
Lua:
p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Server Bonus: x" .. eq .. ". Time left: " .. ttime".")
to
Lua:
p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Server Bonus: x" .. eq .. ". Time left: " .. ttime .. ".")
 
change
Lua:
p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Server Bonus: x" .. eq .. ". Time left: " .. ttime".")
to
Lua:
p:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Server Bonus: x" .. eq .. ". Time left: " .. ttime .. ".")
Wow cant believe i forgot the .. after ttime. Your a G Xikini.
How can i fix this? The time isnt right? I think "code wise" it is working, but its not producing in hours or minutes Screenshot (http://prntscr.com/w0vdp7)
 
Wow cant believe i forgot the .. after ttime. Your a G Xikini.
How can i fix this? The time isnt right? I think "code wise" it is working, but its not producing in hours or minutes Screenshot (http://prntscr.com/w0vdp7)
 
Did the first script in post work for anyone? Am having issue, installed correctly and check all codes, i can use the command and it broadcasts as function intends but there is no bonus EXP, i tried with" X have activated the global 100% exp rate boost for next 5 hours.", did it with 105, 300 - 1000 , changed the hours also but my testchar dont get any extra EXP, no error in console eaither
 
How can I do so that when resetting the globalstorage it does not reset, and how to show the skill and the remaing time in the boost?

Help?

Bump?
 
hmm no have error, not add duble exp, kill rat add exp + 5, god send comands "/globalboost exp,100,5" im kill rat add exp 5 ;/
Post automatically merged:

have one error:

[Warning - Events::load] Can not load script: player.lua
data/events/scripts/player.lua:157: '<eof>' expected near 'end' my player.lua
Lua:
function Player:onLook(thing, position, distance)
    local description = ""
    if hasEventCallback(EVENT_CALLBACK_ONLOOK) then
        description = EventCallback(EVENT_CALLBACK_ONLOOK, self, thing, position, distance, description)
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInBattleList(creature, distance)
    local description = ""
    if hasEventCallback(EVENT_CALLBACK_ONLOOKINBATTLELIST) then
        description = EventCallback(EVENT_CALLBACK_ONLOOKINBATTLELIST, self, creature, distance, description)
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInTrade(partner, item, distance)
    local description = "You see " .. item:getDescription(distance)
    if hasEventCallback(EVENT_CALLBACK_ONLOOKINTRADE) then
        description = EventCallback(EVENT_CALLBACK_ONLOOKINTRADE, self, partner, item, distance, description)
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInShop(itemType, count, description)
    local description = "You see " .. description
    if hasEventCallback(EVENT_CALLBACK_ONLOOKINSHOP) then
        description = EventCallback(EVENT_CALLBACK_ONLOOKINSHOP, self, itemType, count, description)
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if hasEventCallback(EVENT_CALLBACK_ONMOVEITEM) then
        return EventCallback(EVENT_CALLBACK_ONMOVEITEM, self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    end
    return true
end

function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if hasEventCallback(EVENT_CALLBACK_ONITEMMOVED) then
        EventCallback(EVENT_CALLBACK_ONITEMMOVED, self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    end
end

function Player:onMoveCreature(creature, fromPosition, toPosition)
    if hasEventCallback(EVENT_CALLBACK_ONMOVECREATURE) then
        return EventCallback(EVENT_CALLBACK_ONMOVECREATURE, self, creature, fromPosition, toPosition)
    end
    return true
end

function Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation)
    if hasEventCallback(EVENT_CALLBACK_ONREPORTRULEVIOLATION) then
        EventCallback(EVENT_CALLBACK_ONREPORTRULEVIOLATION, self, targetName, reportType, reportReason, comment, translation)
    end
end

function Player:onReportBug(message, position, category)
    if hasEventCallback(EVENT_CALLBACK_ONREPORTBUG) then
        return EventCallback(EVENT_CALLBACK_ONREPORTBUG, self, message, position, category)
    end
    return true
end

function Player:onTurn(direction)
    if hasEventCallback(EVENT_CALLBACK_ONTURN) then
        return EventCallback(EVENT_CALLBACK_ONTURN, self, direction)
    end
    return true
end

function Player:onTradeRequest(target, item)
    if hasEventCallback(EVENT_CALLBACK_ONTRADEREQUEST) then
        return EventCallback(EVENT_CALLBACK_ONTRADEREQUEST, self, target, item)
    end
    return true
end

function Player:onTradeAccept(target, item, targetItem)
    if hasEventCallback(EVENT_CALLBACK_ONTRADEACCEPT) then
        return EventCallback(EVENT_CALLBACK_ONTRADEACCEPT, self, target, item, targetItem)
    end
    return true
end

function Player:onTradeCompleted(target, item, targetItem, isSuccess)
    if hasEventCallback(EVENT_CALLBACK_ONTRADECOMPLETED) then
        EventCallback(EVENT_CALLBACK_ONTRADECOMPLETED, self, target, item, targetItem, isSuccess)
    end
end

local soulCondition = Condition(CONDITION_SOUL, CONDITIONID_DEFAULT)
soulCondition:setTicks(4 * 60 * 1000)
soulCondition:setParameter(CONDITION_PARAM_SOULGAIN, 1)

local function useStamina(player)
    local staminaMinutes = player:getStamina()
    if staminaMinutes == 0 then
        return
    end

    local playerId = player:getId()
    local currentTime = os.time()
    local timePassed = currentTime - nextUseStaminaTime[playerId]
    if timePassed <= 0 then
        return
    end

    if timePassed > 60 then
        if staminaMinutes > 2 then
            staminaMinutes = staminaMinutes - 2
        else
            staminaMinutes = 0
        end
        nextUseStaminaTime[playerId] = currentTime + 120
    else
        staminaMinutes = staminaMinutes - 1
        nextUseStaminaTime[playerId] = currentTime + 60
    end
    player:setStamina(staminaMinutes)
end

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

    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())

    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)

        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end
    if getGlobalStorageValue(17589) > os.time() then
        exp = exp * (1 + getGlobalStorageValue(17585) / 100)
    end
    return exp
end

    return hasEventCallback(EVENT_CALLBACK_ONGAINEXPERIENCE) and EventCallback(EVENT_CALLBACK_ONGAINEXPERIENCE, self, source, exp, rawExp) or exp
end

function Player:onLoseExperience(exp)
    return hasEventCallback(EVENT_CALLBACK_ONLOSEEXPERIENCE) and EventCallback(EVENT_CALLBACK_ONLOSEEXPERIENCE, self, exp) or exp
end

function Player:onGainSkillTries(skill, tries)
    if APPLY_SKILL_MULTIPLIER == false then
        return hasEventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES) and EventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES, self, skill, tries) or tries
    end

    if skill == SKILL_MAGLEVEL then
        tries = tries * configManager.getNumber(configKeys.RATE_MAGIC)
        return hasEventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES) and EventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES, self, skill, tries) or tries
    end
    tries = tries * configManager.getNumber(configKeys.RATE_SKILL)
    return hasEventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES) and EventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES, self, skill, tries) or tries
end
Post automatically merged:

fixed word thanks <3
 
Last edited:
Hey,

Exacly what i was looking for, is it possible to add more functions like faster resp, double loot etc?
 
Back
Top