• 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 0.X skill stages depending on vocation

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
I found this script:


But there is a big problem on that, the rates not change by vocation
So knights for example always have a high magic level rate

I tried to fix but with no success, is anyone more with more experience could help me to put to work?

SCRIPTS:

data\creaturescripts\scripts\stagesconfig.lua
Code:
-- Skill Stages Mages --
skillConfigM = {skill = getConfigValue('rateSkill'), magiclevel = getConfigValue('rateMagic')}
skillStagesM = {}
skillStagesM[SKILL_FIST] = {{0,0}}
skillStagesM[SKILL_CLUB] = {{0,0.5}}
skillStagesM[SKILL_SWORD] = {{0,0.5}}
skillStagesM[SKILL_AXE] = {{0,0.5}}
skillStagesM[SKILL_DISTANCE] = {{0,0.5}}
skillStagesM[SKILL_SHIELD] = {{0,3},{15,2},{25,1}}
--skillStagesM[SKILL_FISHING] = {{0,5},{60,4},{80,3},{100,2},{110,1}}
skillStagesM[SKILL__MAGLEVEL] = {{0,1.0},{20,2.0},{30,3.0},{40,1.5},{50,1},{60,0.5}}

-- Skill Stages Paladin --
skillConfigR = {skill = getConfigValue('rateSkill'), magiclevel = getConfigValue('rateMagic')}
skillStagesR = {}
skillStagesR[SKILL_FIST] = {{0,0}}
skillStagesR[SKILL_CLUB] = {{0,0.5}}
skillStagesR[SKILL_SWORD] = {{0,0.5}}
skillStagesR[SKILL_AXE] = {{0,0.5}}
skillStagesR[SKILL_DISTANCE] = {{0,3},{4,2},{9,1},{15,0.5}}
skillStagesR[SKILL_SHIELD] = {{0,3},{40,1},{60,0.5}}
--skillStagesR[SKILL_FISHING] = {{0,5},{60,4},{80,3},{100,2},{110,1}}
skillStagesR[SKILL__MAGLEVEL] = {{0,3},{4,2},{9,1},{15,0.5}}

-- Skill Stages Knight --
skillConfigW = {skill = getConfigValue('rateSkill'), magiclevel = getConfigValue('rateMagic')}
skillStagesW = {}
skillStagesW[SKILL_FIST] = {{0,0}}
skillStagesW[SKILL_CLUB] = {{0,3},{40,2},{60,1},{80,0.5}}
skillStagesW[SKILL_SWORD] = {{0,3},{40,2},{60,1},{80,0.5}}
skillStagesW[SKILL_AXE] = {{0,3},{40,2},{60,1},{80,0.5}}
skillStagesW[SKILL_DISTANCE] = {{0,0.5}}
skillStagesW[SKILL_SHIELD] = {{0,3},{40,2},{60,1},{80,0.5}}
--skillStagesW[SKILL_FISHING] = {{0,5},{60,4},{80,3},{100,2},{110,1}}
skillStagesW[SKILL__MAGLEVEL] = {{0,3},{4,2},{6,1},{9,0.5}}

-- Skill Stages Rooker (None) --
skillConfigN = {skill = getConfigValue('rateSkill'), magiclevel = getConfigValue('rateMagic')}
skillStagesN = {}
skillStagesN[SKILL_FIST] = {{0,0}}
skillStagesN[SKILL_CLUB] = {{0,5},{10,4},{15,3},{20,2},{25,1},{30,0.5}}
skillStagesN[SKILL_SWORD] = {{0,5},{10,4},{15,3},{20,2},{25,1},{30,0.5}}
skillStagesN[SKILL_AXE] = {{0,5},{10,4},{15,3},{20,2},{25,1},{30,0.5}}
skillStagesN[SKILL_DISTANCE] = {{0,5},{10,4},{15,3},{20,2},{25,1},{30,0.5}}
skillStagesN[SKILL_SHIELD] = {{0,5},{10,4},{15,3},{20,2},{25,1},{30,0.5}}
--skillStagesW[SKILL_FISHING] = {{0,5},{60,4},{80,3},{100,2},{110,1}}
skillStagesN[SKILL__MAGLEVEL] = {{0,0}}


showInfoOnAdvance = true -- send player message about skill rate change
showInfoOnLogin = true -- send player message about skill rates when he login
 
function getPlayerSkillRatesText(cid)
 local skillInfo = getPlayerRates(cid)
 if isMage(cid) then
     return "YOUR RATES: [ Magic Level: " .. skillInfo[SKILL__MAGLEVEL] * skillConfigM.magiclevel .. "x || Fist: " .. skillInfo[SKILL_FIST] * skillConfigM.skill .. "x | Club: " .. skillInfo[SKILL_CLUB] * skillConfigM.skill .. "x |  Sword: " .. skillInfo[SKILL_SWORD] * skillConfigM.skill .. "x | Axe: " .. skillInfo[SKILL_AXE] * skillConfigM.skill .. "x |  Distance: " .. skillInfo[SKILL_DISTANCE] * skillConfigM.skill .. " | Shielding: " .. skillInfo[SKILL_SHIELD] * skillConfigM.skill .. "x | Fishing: " .. skillInfo[SKILL_FISHING] * skillConfigM.skill .. "x ]"
 elseif isRanger(cid) then
     return "YOUR RATES: [ Magic Level: " .. skillInfo[SKILL__MAGLEVEL] * skillConfigR.magiclevel .. "x || Fist: " .. skillInfo[SKILL_FIST] * skillConfigR.skill .. "x | Club: " .. skillInfo[SKILL_CLUB] * skillConfigR.skill .. "x |  Sword: " .. skillInfo[SKILL_SWORD] * skillConfigR.skill .. "x | Axe: " .. skillInfo[SKILL_AXE] * skillConfigR.skill .. "x |  Distance: " .. skillInfo[SKILL_DISTANCE] * skillConfigR.skill .. " | Shielding: " .. skillInfo[SKILL_SHIELD] * skillConfigR.skill .. "x | Fishing: " .. skillInfo[SKILL_FISHING] * skillConfigR.skill .. "x ]"
 elseif isWarrior(cid) then
     return "YOUR RATES: [ Magic Level: " .. skillInfo[SKILL__MAGLEVEL] * skillConfigW.magiclevel .. "x || Fist: " .. skillInfo[SKILL_FIST] * skillConfigW.skill .. "x | Club: " .. skillInfo[SKILL_CLUB] * skillConfigW.skill .. "x |  Sword: " .. skillInfo[SKILL_SWORD] * skillConfigW.skill .. "x | Axe: " .. skillInfo[SKILL_AXE] * skillConfigW.skill .. "x |  Distance: " .. skillInfo[SKILL_DISTANCE] * skillConfigW.skill .. " | Shielding: " .. skillInfo[SKILL_SHIELD] * skillConfigW.skill .. "x | Fishing: " .. skillInfo[SKILL_FISHING] * skillConfigW.skill .. "x ]"
 elseif isRooker(cid) then
     return "YOUR RATES: [ Magic Level: " .. skillInfo[SKILL__MAGLEVEL] * skillConfigN.magiclevel .. "x || Fist: " .. skillInfo[SKILL_FIST] * skillConfigN.skill .. "x | Club: " .. skillInfo[SKILL_CLUB] * skillConfigN.skill .. "x |  Sword: " .. skillInfo[SKILL_SWORD] * skillConfigN.skill .. "x | Axe: " .. skillInfo[SKILL_AXE] * skillConfigN.skill .. "x |  Distance: " .. skillInfo[SKILL_DISTANCE] * skillConfigN.skill .. " | Shielding: " .. skillInfo[SKILL_SHIELD] * skillConfigN.skill .. "x | Fishing: " .. skillInfo[SKILL_FISHING] * skillConfigN.skill .. "x ]"
 end
end

data\creaturescripts\scripts\skillstageslogin.lua
Code:
dofile(getDataDir() .. "creaturescripts/scripts/stagesconfig.lua")

function onLogin(cid)
    local voc = getPlayerVocation(cid)
    -- Mage --
    if isMage(cid) then
        for skill, skillStageM in pairs(skillStagesM) do
            if(skill >= 0 and skill <= 6) then
                nowSkill = getPlayerSkillLevel(cid, skill)
            else
                nowSkill = getPlayerMagLevel(cid, true)
            end
        end
        for i, skillRateInfoM in pairs(skillStageM) do
            if(nowSkill >= skillRateInfoM[1]) then
                skillRateM = skillRateInfoM[2]
            else
                break
            end
        end
        doPlayerSetRate(cid, skill, skillRateM)
    -- Paladin --
    elseif isRanger(cid) then
        for skill, skillStageP in pairs(skillStagesR) do
            if(skill >= 0 and skill <= 6) then
                nowSkill = getPlayerSkillLevel(cid, skill)
            else
                nowSkill = getPlayerMagLevel(cid, true)
            end
        end
        for i, skillRateInfoP in pairs(skillStageP) do
            if(nowSkill >= skillRateInfoP[1]) then
                skillRateP = skillRateInfoP[2]
            else
                break
            end
        end
        doPlayerSetRate(cid, skill, skillRateP)
    -- Knight --
    elseif isKnight(cid) then
        for skill, skillStageK in pairs(skillStagesW) do
            if(skill >= 0 and skill <= 6) then
                nowSkill = getPlayerSkillLevel(cid, skill)
            else
                nowSkill = getPlayerMagLevel(cid, true)
            end
        end
        for i, skillRateInfoK in pairs(skillStageK) do
            if(nowSkill >= skillRateInfoK[1]) then
                skillRateK = skillRateInfoK[2]
            else
                break
            end
        end
        doPlayerSetRate(cid, skill, skillRateK)
    elseif isRooker(cid) then
        for skill, skillStageN in pairs(skillStageN) do
            if(skill >= 0 and skill <= 6) then
                nowSkill = getPlayerSkillLevel(cid, skill)
            else
                nowSkill = getPlayerMagLevel(cid, true)
            end
        end
        for i, skillRateInfoW in pairs(skillStageN) do
            if(nowSkill >= skillRateInfoW[1]) then
                skillRateW = skillRateInfoW[2]
            else
                break
            end
        end
        doPlayerSetRate(cid, skill, skillRateW)
    end


    if(showInfoOnLogin) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerSkillRatesText(cid))
    end
    registerCreatureEvent(cid, "SkillStagesAdvance")
    return TRUE
end

data\creaturescripts\scripts\skillstagesadvance.lua
Code:
dofile(getDataDir() .. "creaturescripts/scripts/stagesconfig.lua")

function onAdvance(cid, skill, oldLevel, newLevel)
    -- Mage --
    if isMage(cid) then
        if(skillStagesM[skill] ~= nil) then
        local skillRateM = 1
        local oldRatesM = getPlayerRates(cid)
        for i, skillRateInfoM in pairs(skillStagesM[skill]) do
            if(newLevel >= skillRateInfoM[1]) then
                skillRateM = skillRateInfoM[2]
            else
                break
            end
        end
        doPlayerSetRate(cid, skill, skillRateM)
        if(showInfoOnAdvance and skillRateM ~= oldRatesM[skill]) then
            if(skill >= 0 and skill <= 6) then
                configRateM = skillConfigM.skill
            else
                configRateM = skillConfigM.magiclevel
            end
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getPlayerNewSkillRatesText(cid))
        end
    -- Paladin --
    elseif isRanger(cid) then
        if(skillStagesR[skill] ~= nil) then
            local skillRateP = 1
            local oldRatesP = getPlayerRates(cid)
            for i, skillRateInfoP in pairs(skillStagesR[skill]) do
                if(newLevel >= skillRateInfoP[1]) then
                    skillRateP = skillRateInfoP[2]
                else
                    break
                end
            end
        end
        doPlayerSetRate(cid, skill, skillRateP)
        if(showInfoOnAdvance and skillRateP ~= oldRatesP[skill]) then
        if(skill >= 0 and skill <= 6) then
            configRateP = skillConfigR.skill
        else
            configRateP = skillConfigR.magiclevel
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getPlayerNewSkillRatesText(cid))
    -- Knight --
    elseif isWarrior(cid) then
        if(skillStagesW[skill] ~= nil) then
            local skillRateW = 1
            local oldRatesK = getPlayerRates(cid)
            for i, skillRateInfoW in pairs(skillStagesW[skill]) do
                if(newLevel >= skillRateInfoW[1]) then
                skillRateW = skillRateInfoW[2]
            else
                break
            end
        end
        doPlayerSetRate(cid, skill, skillRateW)
        if(showInfoOnAdvance and skillRateW ~= oldRatesK[skill]) then
            if(skill >= 0 and skill <= 6) then
                configRateK = skillConfigW.skill
            else
                configRateK = skillConfigW.magiclevel
            end
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getPlayerNewSkillRatesText(cid))
        end
    end
    -- ROOKERS --
    elseif isRooker(cid) then
        if(skillStagesN[skill] ~= nil) then
            local skillRateW = 1
            local oldRatesK = getPlayerRates(cid)
            for i, skillRateInfoW in pairs(skillStagesN[skill]) do
                if(newLevel >= skillRateInfoW[1]) then
                skillRateW = skillRateInfoW[2]
            else
                break
            end
        end
        doPlayerSetRate(cid, skill, skillRateW)
        if(showInfoOnAdvance and skillRateW ~= oldRatesK[skill]) then
            if(skill >= 0 and skill <= 6) then
                configRateK = skillConfigN.skill
            else
                configRateK = skillConfigN.magiclevel
            end
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getPlayerNewSkillRatesText(cid))
        end
    end
    return true
end

ERRORS:

when i try to login with a rooker (vocation 0):
Code:
[18:48:23.749] Mical has logged in.

[18:48:23.749] [Error - CreatureScript Interface] 
[18:48:23.749] data/creaturescripts/scripts/skillstageslogin.lua:onLogin
[18:48:23.749] Description: 
[18:48:23.749] data/creaturescripts/scripts/skillstageslogin.lua:57: bad argument #1 to 'pairs' (table expected, got nil)
[18:48:23.749] stack traceback:
[18:48:23.749]     [C]: in function 'pairs'
[18:48:23.749]     data/creaturescripts/scripts/skillstageslogin.lua:57: in function <data/creaturescripts/scripts/skillstageslogin.lua:3>
[18:48:23.815] Mical has logged out.
 
Solution
For anyone coming into to this thread later and wants to use this functionality in their 0.X server
I've turned this into a mod available here:


You should not use the code below as-is because the config is very strange.

--- CAUTION: STRANGE CODE BELOW ---


I have refactored this for you. Updated: Should be complete now.

Your terrible code duplication and variable name fails aside, your biggest issue was you destroyed onLogin function by moving the doPlayerSetRate outside the outer loop. It could no longer do it's job because of this.

Lua:
function...
[15:30:35.232] data/creaturescripts/scripts/skillstageslogin.lua:51: attempt to concatenate field 'infoOnLogin' (a boolean value)
a boolean value

That means config is getting through. Drop the debug lines and everything should be working.

what are u mean?
remove that prints?

like this:
Code:
dofile(getDataDir() .. "creaturescripts/scripts/stagesconfig.lua")

function onLogin(cid)
    local function doRatings(class)
        local classStages = CUSTOM_RATE_STAGES[class]
        --[[
            first for loop cycles through skills
            ie: SKILL_FIST - SKILL__MAGLEVEL

            second loop cycles through the line
            ie: {{ 0, 5 },{ 10, 4 },{ 15, 3 },{ 20, 2 },{ 25, 1 },{ 30, 0.5 }}
        ]]
        for skill, stages in pairs(classStages) do
            --[[
                first loop this
                skill:  "SKILL_FIST"
                stages: {{ 0, 0.0 }}
            ]]
            local skillLevel = 0
            if(skill >= 0 and skill <= 6) then
                skillLevel = getPlayerSkillLevel(cid, skill)
            else
                -- if out of range, presume magic
                skillLevel = getPlayerMagLevel(cid, true)
            end

            -- {{0,1},{3,2},{7,4}} -> on 3rd round -> i=3; skillRateInfo = {7,4}
            local skillRate = 1
            for i, skillStage in pairs(stages) do
                if(skillLevel >= skillStage[1]) then
                    skillRate = skillStage[2]
                else
                    break
                end
            end
            assert(skillRate > 0.25, "Using skill stage rate multiplier less than 0.25")
            doPlayerSetRate(cid, skill, skillRate)
        end
    end

    local function getClass(cid)
        if isMage(cid)    then return 'MAGE'    end
        if isRanger(cid)  then return 'PALADIN' end
        if isWarrior(cid) then return 'KNIGHT'  end
        if isRooker(cid)  then return 'ROOK'    end
    end

    doRatings(getClass(cid))

    if(config.infoOnLogin) then
        doPlayerSendTextMessage(cid, config.loginColor, getPlayerSkillRatesText(cid))
    end
    registerCreatureEvent(cid, "SkillStagesAdvance")
    return true
end

its showing errors:
Code:
[15:59:29.094] [Error - CreatureScript Interface] 
[15:59:29.094] data/creaturescripts/scripts/skillstageslogin.lua:onLogin
[15:59:29.094] Description: 
[15:59:29.094] data/creaturescripts/scripts/skillstageslogin.lua:51: attempt to call global 'getPlayerSkillRatesText' (a nil value)
[15:59:29.094] stack traceback:
[15:59:29.094]     data/creaturescripts/scripts/skillstageslogin.lua:51: in function <data/creaturescripts/scripts/skillstageslogin.lua:3>
 
That function was in my post. Did you not add it? 🤷‍♂️ It should be in bottom of config file


Lua:
function getPlayerSkillRatesText(cid)
    local skillInfo = getPlayerRates(cid)
    local packed = {
        skillInfo[SKILL__MAGLEVEL] * SERVER_RATE_ML,
        skillInfo[SKILL_FIST]      * SERVER_RATE_SR,
        skillInfo[SKILL_CLUB]      * SERVER_RATE_SR,
        skillInfo[SKILL_SWORD]     * SERVER_RATE_SR,
        skillInfo[SKILL_AXE]       * SERVER_RATE_SR,
        skillInfo[SKILL_DISTANCE]  * SERVER_RATE_SR,
        skillInfo[SKILL_SHIELD]    * SERVER_RATE_SR,
        skillInfo[SKILL_FISHING]   * SERVER_RATE_SR
    }
    local message = string.format("YOUR RATES: [ Magic Level: %sx || Fist: %sx | Club: %sx |  Sword: %sx | Axe: %sx |  Distance: %s | Shielding: %sx | Fishing: %sx ]", unpack(packed))

    return message
end
 
That function was in my post. Did you not add it? 🤷‍♂️ It should be in bottom of config file


Lua:
function getPlayerSkillRatesText(cid)
    local skillInfo = getPlayerRates(cid)
    local packed = {
        skillInfo[SKILL__MAGLEVEL] * SERVER_RATE_ML,
        skillInfo[SKILL_FIST]      * SERVER_RATE_SR,
        skillInfo[SKILL_CLUB]      * SERVER_RATE_SR,
        skillInfo[SKILL_SWORD]     * SERVER_RATE_SR,
        skillInfo[SKILL_AXE]       * SERVER_RATE_SR,
        skillInfo[SKILL_DISTANCE]  * SERVER_RATE_SR,
        skillInfo[SKILL_SHIELD]    * SERVER_RATE_SR,
        skillInfo[SKILL_FISHING]   * SERVER_RATE_SR
    }
    local message = string.format("YOUR RATES: [ Magic Level: %sx || Fist: %sx | Club: %sx |  Sword: %sx | Axe: %sx |  Distance: %s | Shielding: %sx | Fishing: %sx ]", unpack(packed))

    return message
end

😍
Oh thank you!! Sorry, my bad, i'm too dumb :(



Could u help me with 2 last things?
I want to do this your script works together with two others systems

1- on player enter training monks rates changes to rates / 2 (to make skill rates on training monks more slowers)

i already tried this with no sucess
i've change the codes to:
skillstagesadvanced.lua
Code:
dofile(getDataDir() .. "creaturescripts/scripts/stagesconfig.lua")

function onAdvance(cid, skill, oldLevel, newLevel)
    local function doAdvance(class)
        local classStages = CUSTOM_RATE_STAGES[class]
        local skillRate = 1
        local oldRates = getPlayerRates(cid)

        -- gotta check cuz some are empty in the defaults like fishing
        if(classStages[skill] ~= nil) then
            for i, skillStage in pairs(classStages[skill]) do
                if(newLevel >= skillStage[1]) then
                    skillRate = skillStage[2]
                else
                    break
                end
            end
            doPlayerSetRate(cid, skill, skillRate)
            if(config.infoOnAdvance and skillRate ~= oldRates[skill]) then
                local configRate = 1
                if(skill >= 0 and skill <= 6) then
                    configRate = SERVER_RATE_SR
                else
                    configRate = SERVER_RATE_ML
                end

                if(config.infoOnLogin) then
                    local message = string.format("%s rate changed from %sx to %sx. %s",
                        SKILL_NAMES[skill], oldRates[skill] * configRate, skillRate * configRate, getPlayerSkillRatesText(cid))

                    doPlayerSendTextMessage(cid, config.msgColor, message)
                    getPlayerSkillRatesText(cid)
                end
            end
        end
    end

    doAdvance(getClass(cid))
    return true
end

skillstageslogin.lua
Code:
dofile(getDataDir() .. "creaturescripts/scripts/stagesconfig.lua")

function onLogin(cid)
    local function doRatings(class)
        local classStages = CUSTOM_RATE_STAGES[class]
        --[[
            first for loop cycles through skills
            ie: SKILL_FIST - SKILL__MAGLEVEL

            second loop cycles through the line
            ie: {{ 0, 5 },{ 10, 4 },{ 15, 3 },{ 20, 2 },{ 25, 1 },{ 30, 0.5 }}
        ]]
        for skill, stages in pairs(classStages) do
            --[[
                first loop this
                skill:  "SKILL_FIST"
                stages: {{ 0, 0.0 }}
            ]]
            local skillLevel = 0
            if(skill >= 0 and skill <= 6) then
                skillLevel = getPlayerSkillLevel(cid, skill)
            else
                -- if out of range, presume magic
                skillLevel = getPlayerMagLevel(cid, true)
            end

            -- {{0,1},{3,2},{7,4}} -> on 3rd round -> i=3; skillRateInfo = {7,4}
            local skillRate = 1
            for i, skillStage in pairs(stages) do
                if(skillLevel >= skillStage[1]) then
                    skillRate = skillStage[2]
                else
                    break
                end
            end
            doPlayerSetRate(cid, skill, skillRate)
        end
    end

    doRatings(getClass(cid))

    if(config.infoOnLogin) then
        doPlayerSendTextMessage(cid, config.msgColor, getPlayerSkillRatesText(cid))
    end
    registerCreatureEvent(cid, "SkillStagesAdvance")
    return true
end

skillstagesconfig.lua
Code:
config = {
    infoOnAdvance = true, -- send player message about skill rate change
    infoOnLogin   = true, -- send player message about skill rates when he login
    msgColor    = MESSAGE_STATUS_CONSOLE_ORANGE
}

SERVER_RATE_SR = getConfigValue('rateSkill')
SERVER_RATE_ML = getConfigValue('rateMagic')

CUSTOM_RATE_STAGES = {
    -- Skill Stages Mage --
    MAGE = {
        [SKILL_FIST]      = {{ 0, 0.0 }},
        [SKILL_CLUB]      = {{ 0, 0.5 }},
        [SKILL_SWORD]     = {{ 0, 0.5 }},
        [SKILL_AXE]       = {{ 0, 0.5 }},
        [SKILL_DISTANCE]  = {{ 0, 0.5 }},
        [SKILL_SHIELD]    = {{ 0, 3.0 },{ 15, 2.0 },{ 25, 1.0 }},
        [SKILL__MAGLEVEL] = {{ 0, 3.0 },{ 20, 2.0 },{ 30, 1.5 },{ 40, 1}, { 50, 0.5 }},
    },
    -- Skill Stages Paladin --
    RANGER = {
        [SKILL_FIST]      = {{ 0, 0.0 }},
        [SKILL_CLUB]      = {{ 0, 0.5 }},
        [SKILL_SWORD]     = {{ 0, 0.5 }},
        [SKILL_AXE]       = {{ 0, 0.5 }},
        [SKILL_DISTANCE]  = {{ 0, 3.0 },{ 30, 2.0 },{ 40, 1.0 },{ 70, 0.5 }},
        [SKILL_SHIELD]    = {{ 0, 3.0 },{ 40, 1.0 },{ 60, 0.5 }},
        [SKILL__MAGLEVEL] = {{ 0, 3.0 },{  4, 2.0 },{  9, 1.0 },{ 15, 0.5 }},
    },
    -- Skill Stages Knight --
    WARRIOR = {
        [SKILL_FIST]      = {{ 0, 0.0 }},
        [SKILL_CLUB]      = {{ 0, 300.0 },{ 30, 200.0 },{ 40, 100.0 },{ 70, 0.5 }},
        [SKILL_SWORD]     = {{ 0, 3.0 },{ 30, 2.0 },{ 40, 1.0 },{ 70, 0.5 }},
        [SKILL_AXE]       = {{ 0, 3.0 },{ 30, 2.0 },{ 40, 1.0 },{ 70, 0.5 }},
        [SKILL_DISTANCE]  = {{ 0, 0.5 }},
        [SKILL_SHIELD]    = {{ 0, 3.0 },{ 40, 1.0 },{ 60, 0.5 }},
        [SKILL__MAGLEVEL] = {{ 0, 3.0 },{  4, 2.0 },{  6, 1.0 },{  9, 0.5 }},
    },
    -- Skill Stages Rooker (None) --
    ROOK = {
        [SKILL_FIST]      = {{ 0, 0 }},
        [SKILL_CLUB]      = {{ 0, 5.0 },{ 15, 3.0 },{ 20, 2.0 },{ 25, 1.0 },{ 30, 0.5 }},
        [SKILL_SWORD]     = {{ 0, 5.0 },{ 15, 3.0 },{ 20, 2.0 },{ 25, 1.0 },{ 30, 0.5 }},
        [SKILL_AXE]       = {{ 0, 5.0 },{ 15, 3.0 },{ 20, 2.0 },{ 25, 1.0 },{ 30, 0.5 }},
        [SKILL_DISTANCE]  = {{ 0, 5.0 },{ 15, 3.0 },{ 20, 2.0 },{ 25, 1.0 },{ 30, 0.5 }},
        [SKILL_SHIELD]    = {{ 0, 5.0 },{ 15, 3.0 },{ 20, 2.0 },{ 25, 1.0 },{ 30, 0.5 }},
        [SKILL__MAGLEVEL] = {{ 0, 0 }},
    },
    --SKILL_FISHING = {{0,5},{60,4},{80,3},{100,2},{110,1}}
}

function getPlayerSkillRatesText(cid)
    local skillInfo = getPlayerRates(cid)
    local divideBy = 1
    if getCreatureStorage(cid, 17000 ) >= 1 then
        divideBy = 2
    end
    local packed = {
        (skillInfo[SKILL__MAGLEVEL] * SERVER_RATE_ML) / divideBy,
        (skillInfo[SKILL_FIST]      * SERVER_RATE_SR) / divideBy,
        (skillInfo[SKILL_CLUB]      * SERVER_RATE_SR) / divideBy,
        (skillInfo[SKILL_SWORD]     * SERVER_RATE_SR) / divideBy,
        (skillInfo[SKILL_AXE]       * SERVER_RATE_SR) / divideBy,
        (skillInfo[SKILL_DISTANCE]  * SERVER_RATE_SR) / divideBy,
        (skillInfo[SKILL_SHIELD]    * SERVER_RATE_SR) / divideBy,
        (skillInfo[SKILL_FISHING]   * SERVER_RATE_SR) / divideBy
    }
    local message = string.format("YOUR RATES: [ Magic Level: %sx || Fist: %sx | Club: %sx |  Sword: %sx | Axe: %sx |  Distance: %s | Shielding: %sx | Fishing: %sx ]", unpack(packed))

    return message
end


so in the training monks movemment i did:
Code:
dofile(getDataDir() .. "creaturescripts/scripts/stagesconfig.lua")

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    setPlayerStorageValue(cid, 17000, 1)

    local function doRatings(class)
        local classStages = CUSTOM_RATE_STAGES[class]
        for skill, stages in pairs(classStages) do
            local skillLevel = 0
            if(skill >= 0 and skill <= 6) then
                skillLevel = getPlayerSkillLevel(cid, skill)
            else
                skillLevel = getPlayerMagLevel(cid, true)
            end
            local skillRate = 1
            for i, skillStage in pairs(stages) do
                if(skillLevel >= skillStage[1]) then
                    skillRate = skillStage[2]
                else
                    break
                end
            end
            doPlayerSetRate(cid, skill, skillRate/2)
        end
    end
    doRatings(getClass(cid))

    if(config.infoOnLogin) then
        doPlayerSendTextMessage(cid, config.msgColor, getPlayerSkillRatesText(cid))
    end

    return true
end

function onStepOut(cid, item, position, fromPosition)
    setPlayerStorageValue(cid, 17000, 0)
    if(config.infoOnLogin) then
        doPlayerSendTextMessage(cid, config.msgColor, getPlayerSkillRatesText(cid))
    end
    return true
end

But there are 2 problems

problem A) skills are not chaging right
problem B) skills get back to the normal (like player was out of training monks) when player advance skill

did u know how to fix or a better way to do this?

tests logs:
Code:
when i login, shows right:
03:30 YOUR RATES: [ Magic Level: 3x || Fist: 0x | Club: 300x |  Sword: 1x | Axe: 1x |  Distance: 0.5 | Shielding: 3x | Fishing: 1x ]

when i enter training monks rooms, it shows:
03:32 YOUR RATES: [ Magic Level: 0.75x || Fist: 0x | Club: 75x |  Sword: 0.25x | Axe: 0.25x |  Distance: 0.125 | Shielding: 0.75x | Fishing: 0.5x ]

clubs = Club: 75x
should be = Club: 150x

and when i leaves training rooms, instead of come back to 300x
it returns
03:33 YOUR RATES: [ Magic Level: 1.5x || Fist: 0x | Club: 150x |  Sword: 0.5x | Axe: 0.5x |  Distance: 0.25 | Shielding: 1.5x | Fishing: 1x ]



the fucking strange thing is
if i login with:
03:34 YOUR RATES: [ Magic Level: 3x || Fist: 0x | Club: 300x |  Sword: 1x | Axe: 1x |  Distance: 0.5 | Shielding: 3x | Fishing: 1x ]

i enter on traninig monks rooms it shows:
03:34 YOUR RATES: [ Magic Level: 0.75x || Fist: 0x | Club: 75x |  Sword: 0.25x | Axe: 0.25x |  Distance: 0.125 | Shielding: 0.75x | Fishing: 0.5x ]

But when i attack a training monk, it shows:
03:35 club fighting rate changed from 150x to 300x. YOUR RATES: [ Magic Level: 0.75x || Fist: 0x | Club: 150x |  Sword: 0.25x | Axe: 0.25x |  Distance: 0.125 | Shielding: 0.75x | Fishing: 0.5x ]

2- offline trainers (Action - Offline Training for 8.60 (https://otland.net/threads/offline-training-for-8-60.200271/))

How do i need to edit the /lib/offline-training.lua
to work with deppeding vocation rates instead of that static skill rates?
Code:
OfflineTraining_rates = {
    [SKILL_CLUB] = 3,
    [SKILL_SWORD] = 3,
    [SKILL_AXE] = 3,
    [SKILL_DISTANCE] = 3,
    [SKILL_SHIELD] = 0.5,
    [SKILL__MAGLEVEL] = 1.5
}

/lib/offline-training.lua
Code:
-- config, in percent of normal training with 2 trainers and player vocation mana regeneration [by food]
OfflineTraining_rates = {
    [SKILL_CLUB] = 3,
    [SKILL_SWORD] = 3,
    [SKILL_AXE] = 3,
    [SKILL_DISTANCE] = 3,
    [SKILL_SHIELD] = 0.5,
    [SKILL__MAGLEVEL] = 1.5
}
-- function that you should edit to make it add other skill etc.
function OfflineTraining_canStartTraining(cid) -- return bool
return getCreatureStorage(cid, 62669) > 0
end
function OfflineTraining_onStartTraining(cid)
-- maybe someone will need
-- to save your time, this: doPlayerPopupFYI(cid, "You started offline training.")
-- NOT WORK  [IMG]http://www.tibiaking.com/forum/public/style_emoticons/default/sad.png[/IMG]
end
function OfflineTraining_onEndTraining(cid)
doCreatureSetStorage(cid, 62669, 0)
end
function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
local timeInSeconds = trainTime * 60
local vocInfo = getVocationInfo(getPlayerVocation(cid))
if(getCreatureStorage(cid, 62669) == SKILL_SWORD) then
doPlayerAddSkillTry(cid, SKILL_SWORD, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_SWORD] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_AXE) then
doPlayerAddSkillTry(cid, SKILL_AXE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_AXE] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL__MAGLEVEL) then
doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * OfflineTraining_rates[SKILL__MAGLEVEL] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_CLUB) then
doPlayerAddSkillTry(cid, SKILL_CLUB, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_CLUB] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_DISTANCE) then
doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_DISTANCE] / 100, true)
end
doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * OfflineTraining_rates[SKILL_SHIELD] / 100, true)
end

-- 4 functions to show right values on 'bar' in Tibia 9.6
function OfflineTraining_getTime(cid)
return getCreatureStorage(cid, 62666)
end
function OfflineTraining_setTime(cid, newTime)
-- set values only between 0 - 720 [12 hours]
if isPremium(cid) then
doCreatureSetStorage(cid, 62666, math.max(0, math.min(newTime, 720)))
else
doCreatureSetStorage(cid, 62666, math.max(0, math.min(newTime, 360)))
end
-- now code to force server to send 'PlayerStats' (including Offline Time)
-- we must change any stat: hp,mana,stamina,cap,soul,exp,level
doPlayerAddSoul(cid, 1)
doPlayerAddSoul(cid, -1)
end
function OfflineTraining_addTime(cid, addTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + addTime)
end
function OfflineTraining_removeTime(cid, removeTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) - removeTime)
end

-- functions for library to add skills/mlvl
function OfflineTraining_initialize(cid)
if(OfflineTraining_getTime(cid) == -1) then
if isPremium(cid) then
OfflineTraining_setTime(cid, 720)
else
OfflineTraining_setTime(cid, 360)
end
OfflineTraining_setLogoutTime(cid) -- block problem with first login 'add time'
end
end
function OfflineTraining_isTraining(cid)
return (getCreatureStorage(cid, 62667) > 0)
end
function OfflineTraining_turnOnTraining(cid)
doCreatureSetStorage(cid, 62667, 1)
end
function OfflineTraining_turnOffTraining(cid)
doCreatureSetStorage(cid, 62667, 0)
end
function OfflineTraining_getOfflineTime(cid)
return math.floor((os.time() - getCreatureStorage(cid, 62668)) / 60)
end
function OfflineTraining_setLogoutTime(cid)
return doCreatureSetStorage(cid, 62668, os.time())
end

---

And thank you to your help so far, really thanks, your script is amazing and should be used in a lot of servers (i hope other people can see that to use, it make the game experience so better)
 
Has a problem with up magic level mages!
Each exura, up on any magic level skill, 9% from magic level bar!
ML 1 exura = 6% bar skill
ML 70 exura = 6% bar skill up.
Any solutions?
 
Back
Top