• 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 with Offline Trainer

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
I'm using the @Lessaire skill stages depending o vocation system (TFS 0.X - skill stages depending on vocation (https://otland.net/threads/skill-stages-depending-on-vocation.269757/)) and i would like to make it work with offline trainers system (Action - Offline Training for 8.60 (https://otland.net/threads/offline-training-for-8-60.200271/))

how should i change the:
Code:
OfflineTraining_rates = {
    [SKILL_CLUB] = 3,
    [SKILL_SWORD] = 3,
    [SKILL_AXE] = 3,
    [SKILL_DISTANCE] = 3,
    [SKILL_SHIELD] = 0.5,
    [SKILL__MAGLEVEL] = 1.5
}

from /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

to work with skill vocation stages?
 
OP
sucibob

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
how to this stuff of skill stages msg in there?
Code:
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
 

Lessaire

Omniscient Hypervisor
Premium User
Joined
Dec 29, 2009
Messages
1,265
Solutions
46
Reaction score
440
Location
Oregon

That was explicitly what I tried asking you for in the other thread 😌


Man there is a lot wrong with this... This will take me a bit, because I'll have to finish refactoring it before I even think about intergration / interop.

Lua:
-- config, in percent of normal training with 2 trainers and player vocation mana regeneration [by food]
OFFLINETRAIN = {
    RATES = {
        [SKILL_CLUB]      = 3,
        [SKILL_SWORD]     = 3,
        [SKILL_AXE]       = 3,
        [SKILL_DISTANCE]  = 3,
        [SKILL_SHIELD]    = 0.5,
        [SKILL__MAGLEVEL] = 1.5
    },
    STORAGES = {
        TIME   = 62666,
        ACITVE = 62667,
        SKILL  = 62669, --???
    }
}

-- function that you should edit to make it add other skill etc.
function OfflineTraining_canStartTraining(cid) -- return bool
    return getCreatureStorage(cid, OFFLINETRAIN.STORAGES.SKILL) > 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, OFFLINETRAIN.STORAGES.SKILL, 0)
end

function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
    local timeInSeconds = trainTime * 60
    local vocInfo = getVocationInfo(getPlayerVocation(cid))
    local selected = getCreatureStorage(cid, OFFLINETRAIN.STORAGES.SKILL)

    if false then ; -- You leave this semicolon alone!
    elseif(selected == SKILL_SWORD)     then doPlayerAddSkillTry(cid, SKILL_SWORD,    ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OFFLINETRAIN.RATES[SKILL_SWORD] / 100, true)
    elseif(selected == SKILL_AXE)       then doPlayerAddSkillTry(cid, SKILL_AXE,      ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OFFLINETRAIN.RATES[SKILL_AXE] / 100, true)
    elseif(selected == SKILL_CLUB)      then doPlayerAddSkillTry(cid, SKILL_CLUB,     ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OFFLINETRAIN.RATES[SKILL_CLUB] / 100, true)
    elseif(selected == SKILL_DISTANCE)  then doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OFFLINETRAIN.RATES[SKILL_DISTANCE] / 100, true)
    elseif(selected == SKILL__MAGLEVEL) then doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * OFFLINETRAIN.RATES[SKILL__MAGLEVEL] / 100, true)
    end

    doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * OFFLINETRAIN.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, OFFLINETRAIN.STORAGES.TIME)
end

function OfflineTraining_setTime(cid, newTime)
    local upper = isPremium(cid) and 720 or 360

    -- set values only between 0 - 720 [12 hours]
    doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.TIME, math.max(0, math.min(newTime, upper)))

    -- 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)
    local time = isPremium(cid) and 720 or 360
    if(OfflineTraining_getTime(cid) == -1) then
        OfflineTraining_setTime(cid, time)
        OfflineTraining_setLogoutTime(cid) -- block problem with first login 'add time'
    end
end

function OfflineTraining_isTraining(cid)
    return (getCreatureStorage(cid, OFFLINETRAIN.STORAGES.ACTIVE) > 0)
end
function OfflineTraining_turnOnTraining(cid)
    doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.ACTIVE, 1)
end
function OfflineTraining_turnOffTraining(cid)
    doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.ACTIVE, 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




-- <globalevent name="offtrain_add_minutes" interval="60000" event="script" value="offtrain_addMinutes.lua"/>

function onThink(interval) -- run it with interval 60 seconds
    for _, cid in pairs(getPlayersOnline()) do
        OfflineTraining_addTime(cid, 1)
    end
    return true
end

-- Offline Training --
--<action itemid="1444"  event="script" value="other/offlinetraining.lua"/>
--<action itemid="8626"  event="script" value="other/offlinetraining.lua"/>
--<action itemid="8834"  event="script" value="other/offlinetraining.lua"/>
--<action itemid="10349" event="script" value="other/offlinetraining.lua"/>
--<action itemid="10353" event="script" value="other/offlinetraining.lua"/>

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(item.itemid == 1444) then -- sword
        doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.SKILL, SKILL_SWORD)
    elseif(item.itemid == 10349) then -- axe
        doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.SKILL, SKILL_AXE)
    elseif(item.itemid == 8834) then -- mlvl
        doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.SKILL, SKILL__MAGLEVEL)
    elseif(item.itemid == 8626) then -- club
        doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.SKILL, SKILL_CLUB)
    elseif(item.itemid == 10353) then -- distannce
        doCreatureSetStorage(cid, OFFLINETRAIN.STORAGES.SKILL, SKILL_DISTANCE)
    end
    if item.actionid == 1000 then
        doRemoveCreature(cid)
    end
    return true
end
-----------------------------------------------------------------------

--<event type="login" name="offtrain_PlayerLogin" event="script" value="offtrain_login.lua"/>
--<event type="logout" name="offtrain_PlayerLogout" event="script" value="offtrain_logout.lua"/>

-- 0.4 - offline training - login.lua
function onLogin(cid)
    OfflineTraining_initialize(cid)
    if(OfflineTraining_isTraining(cid)) then
        OfflineTraining_turnOffTraining(cid)
        -- we add skill/mlvl, we select lower value: time that player was offline OR offline training time [bar in game - 9.6]
        OfflineTraining_addTrainedSkills(cid, math.min(OfflineTraining_getTime(cid), OfflineTraining_getOfflineTime(cid)))
        -- we remove offline training time [bar in game - 9.6],
        -- if player was offline longer then his 'offline training time' it will add him time [like on RL tibia]
        -- got '3  hours offline training time', stay logged off for 8 hours, you get skills for 3 hours and on login you got '5 hours offline training time'
        OfflineTraining_setTime(cid, math.abs(OfflineTraining_getTime(cid) - OfflineTraining_getOfflineTime(cid)))
        OfflineTraining_onEndTraining(cid)
    else
        -- offline training time also regenerate when you are offline, but NOT train
        OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + OfflineTraining_getOfflineTime(cid))
    end
    return true
end

-- 0.4 - offline training - logout.lua
function onLogout(cid)
    if(OfflineTraining_canStartTraining(cid)) then
        OfflineTraining_turnOnTraining(cid)
        OfflineTraining_onStartTraining(cid)
    end
    OfflineTraining_setLogoutTime(cid)
    return true
end
 
OP
sucibob

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
That was explicitly what I tried asking you for in the other thread 😌

what are u mean? the full code link?

Man there is a lot wrong with this... This will take me a bit, because I'll have to finish refactoring it before I even think about intergration / interop.

Oh man, thank you so much, if there is anything i can help tell me
 
OP
sucibob

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
i still waiting for someone help us to do

the skill_stages_by_vocation
from: TFS 0.X - skill stages depending on vocation (https://otland.net/threads/skill-stages-depending-on-vocation.269757/)

with trainer_offline:
from: Action - Offline Training for 8.60 (https://otland.net/threads/offline-training-for-8-60.200271/)

because the config.lua have to be:
Code:
    rateExperience = 1.0
    rateSkill = 1.0
    rateMagic = 1.0
    rateLoot = 1.0
so the skill_stages_by_vocation works well
but it kills the offline trainer, because the offline trainer is also based on config.lua

is anybody with more experience could help us?
 
OP
sucibob

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
i still waiting for someone help us to do

the skill_stages_by_vocation
from: TFS 0.X - skill stages depending on vocation (https://otland.net/threads/skill-stages-depending-on-vocation.269757/)

with trainer_offline:
from: Action - Offline Training for 8.60 (https://otland.net/threads/offline-training-for-8-60.200271/)

because the config.lua have to be:
Code:
    rateExperience = 1.0
    rateSkill = 1.0
    rateMagic = 1.0
    rateLoot = 1.0
so the skill_stages_by_vocation works well
but it kills the offline trainer, because the offline trainer is also based on config.lua

is anybody with more experience could help us?

I tried this:
Code:
        print("getClass(cid): " .. getClass(cid))
        local classStages = CUSTOM_RATE_STAGES[getClass(cid)]
        print("<a>")
        print("A: " .. classStages)

Code:
[8:32:52.798] Test Mage has logged in.
getClass(cid): MAGE
<a>

[8:32:52.799] [Error - CreatureScript Interface]
[8:32:52.799] data/creaturescripts/scripts/offtrain_login.lua:onLogin
[8:32:52.799] Description:
[8:32:52.799] data/creaturescripts/scripts/offtrain_login.lua:12: attempt to concatenate local 'classStages' (a table value)
[8:32:52.799] stack traceback:
[8:32:52.799]     data/creaturescripts/scripts/offtrain_login.lua:12: in function <data/creaturescripts/scripts/offtrain_login.lua:2>
[8:32:52.908] Test Mage has logged out.
Line 12 is print("A: " .. classStages)


-----------------------------------------------------------------------------------------------------------------

I was thinking about do:

data/creaturescripts/scripts/offtrain_login.lua
Code:
-- 0.4 - offline training - login.lua
function onLogin(cid)
    OfflineTraining_initialize(cid)
    if(OfflineTraining_isTraining(cid)) then
        OfflineTraining_turnOffTraining(cid)
      
      
        -- we add skill/mlvl, we select lower value: time that player was offline OR offline training time [bar in game - 9.6]
        print("getClass(cid): " .. getClass(cid))
        local classStages = CUSTOM_RATE_STAGES[getClass(cid)]
        print("<a>")
        print("A: " .. classStages)
        print("</a>")
        OfflineTraining_addTrainedSkills(cid, math.min(OfflineTraining_getTime(cid), OfflineTraining_getOfflineTime(cid)), classStages)
      
      
        -- we remove offline training time [bar in game - 9.6],
        -- if player was offline longer then his 'offline training time' it will add him time [like on RL tibia]
        -- got '3 hours offline training time', stay logged off for 8 hours, you get skills for 3 hours and on login you got '5 hours offline training time'
        OfflineTraining_setTime(cid, math.abs(OfflineTraining_getTime(cid) - OfflineTraining_getOfflineTime(cid)))
        OfflineTraining_onEndTraining(cid)
        local left = ((OfflineTraining_getTime(cid) / 60) * 60 * 60)
        left = {hour = math.floor(left/3600), minutes = math.ceil((left % 3600)/60)}
        doPlayerPopupFYI(cid, 'Voce ainda tem '.. left.hour ..'h and '..left.minutes..'min de Treinamento.')
    else
        -- offline training time also regenerate when you are offline, but NOT train
        local lefts = ((OfflineTraining_getTime(cid) / 60) * 60 * 60)
        OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + OfflineTraining_getOfflineTime(cid))
        lefts = {hour = math.floor(lefts/3600), minutes = math.ceil((lefts % 3600)/60)}
        doPlayerSendTextMessage(cid, 27, "Stamina trainer offline ".. lefts.hour .."h and "..lefts.minutes.."min.")
    end
    return true
end

lib/offline-training.lua
Code:
...

function OfflineTraining_addTrainedSkills(cid, trainTime, classStages) -- time in minutes!
    print("<b>")
    print("B: " .. classStages)
    print("</b>")

    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] * classStages[SKILL_SWORD]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL_AXE) then
        doPlayerAddSkillTry(cid, SKILL_AXE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * (OfflineTraining_rates[SKILL_AXE] * classStages[SKILL_AXE]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL__MAGLEVEL) then
        doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * (OfflineTraining_rates[SKILL__MAGLEVEL] * classStages[SKILL__MAGLEVEL]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL_CLUB) then
        doPlayerAddSkillTry(cid, SKILL_CLUB, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * (OfflineTraining_rates[SKILL_CLUB] * classStages[SKILL_CLUB]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL_DISTANCE) then
        doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * (OfflineTraining_rates[SKILL_DISTANCE] * classStages[SKILL_DISTANCE]) / 100, true)
    end
    doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * (OfflineTraining_rates[SKILL_SHIELD] * classStages[SKILL_SHIELD]) / 100, true)
end

...




-----------------------------------------------------------------------------------------------------------------

Is anybody can help?
 
OP
sucibob

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
I tried this:
Code:
        print("getClass(cid): " .. getClass(cid))
        local classStages = CUSTOM_RATE_STAGES[getClass(cid)]
        print("<a>")
        print("A: " .. classStages)

Code:
[8:32:52.798] Test Mage has logged in.
getClass(cid): MAGE
<a>

[8:32:52.799] [Error - CreatureScript Interface]
[8:32:52.799] data/creaturescripts/scripts/offtrain_login.lua:onLogin
[8:32:52.799] Description:
[8:32:52.799] data/creaturescripts/scripts/offtrain_login.lua:12: attempt to concatenate local 'classStages' (a table value)
[8:32:52.799] stack traceback:
[8:32:52.799]     data/creaturescripts/scripts/offtrain_login.lua:12: in function <data/creaturescripts/scripts/offtrain_login.lua:2>
[8:32:52.908] Test Mage has logged out.
Line 12 is print("A: " .. classStages)


-----------------------------------------------------------------------------------------------------------------

I was thinking about do:

data/creaturescripts/scripts/offtrain_login.lua
Code:
-- 0.4 - offline training - login.lua
function onLogin(cid)
    OfflineTraining_initialize(cid)
    if(OfflineTraining_isTraining(cid)) then
        OfflineTraining_turnOffTraining(cid)
     
     
        -- we add skill/mlvl, we select lower value: time that player was offline OR offline training time [bar in game - 9.6]
        print("getClass(cid): " .. getClass(cid))
        local classStages = CUSTOM_RATE_STAGES[getClass(cid)]
        print("<a>")
        print("A: " .. classStages)
        print("</a>")
        OfflineTraining_addTrainedSkills(cid, math.min(OfflineTraining_getTime(cid), OfflineTraining_getOfflineTime(cid)), classStages)
     
     
        -- we remove offline training time [bar in game - 9.6],
        -- if player was offline longer then his 'offline training time' it will add him time [like on RL tibia]
        -- got '3 hours offline training time', stay logged off for 8 hours, you get skills for 3 hours and on login you got '5 hours offline training time'
        OfflineTraining_setTime(cid, math.abs(OfflineTraining_getTime(cid) - OfflineTraining_getOfflineTime(cid)))
        OfflineTraining_onEndTraining(cid)
        local left = ((OfflineTraining_getTime(cid) / 60) * 60 * 60)
        left = {hour = math.floor(left/3600), minutes = math.ceil((left % 3600)/60)}
        doPlayerPopupFYI(cid, 'Voce ainda tem '.. left.hour ..'h and '..left.minutes..'min de Treinamento.')
    else
        -- offline training time also regenerate when you are offline, but NOT train
        local lefts = ((OfflineTraining_getTime(cid) / 60) * 60 * 60)
        OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + OfflineTraining_getOfflineTime(cid))
        lefts = {hour = math.floor(lefts/3600), minutes = math.ceil((lefts % 3600)/60)}
        doPlayerSendTextMessage(cid, 27, "Stamina trainer offline ".. lefts.hour .."h and "..lefts.minutes.."min.")
    end
    return true
end

lib/offline-training.lua
Code:
...

function OfflineTraining_addTrainedSkills(cid, trainTime, classStages) -- time in minutes!
    print("<b>")
    print("B: " .. classStages)
    print("</b>")

    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] * classStages[SKILL_SWORD]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL_AXE) then
        doPlayerAddSkillTry(cid, SKILL_AXE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * (OfflineTraining_rates[SKILL_AXE] * classStages[SKILL_AXE]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL__MAGLEVEL) then
        doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * (OfflineTraining_rates[SKILL__MAGLEVEL] * classStages[SKILL__MAGLEVEL]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL_CLUB) then
        doPlayerAddSkillTry(cid, SKILL_CLUB, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * (OfflineTraining_rates[SKILL_CLUB] * classStages[SKILL_CLUB]) / 100, true)
    elseif(getCreatureStorage(cid, 62669) == SKILL_DISTANCE) then
        doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * (OfflineTraining_rates[SKILL_DISTANCE] * classStages[SKILL_DISTANCE]) / 100, true)
    end
    doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * (OfflineTraining_rates[SKILL_SHIELD] * classStages[SKILL_SHIELD]) / 100, true)
end

...




-----------------------------------------------------------------------------------------------------------------

Is anybody can help?

why it is not printing anything?
why it is breaking in print("A: " .. classStages)?
 
OP
sucibob

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
why it is not printing anything?
why it is breaking in print("A: " .. classStages)?

Is anybody can help me?
I'm trapped on this...
If i manage to do this feature i'll share here, there are other people on this topic who want this and maybe even more, help me to help us :)
 
Top