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

RevScripts Offline Training for 1.x RevScript (for Tibia version 9.5 or bellow)

E

Evil Puncker

Guest
long story short: don't want to release but didn't want to leave it lost, someone might have an use for it:

a feel things to consider:
  • the magic level formula needs to be fixed
  • a few functions are really redundant and should be removed
  • add setting to minimum time offline to start training
  • make maximum time configurable as well
  • make a table with item ids and skills they should train
  • make a table with all these storage to set them only once
  • a sample map is attached

disclaimer to mods/admins: its not a release! just an unfinished thing for someone whiling to add/fix the above mentioned and release it

Lua:
-- config, in percent of normal training with 2 trainers and player vocation mana regeneration [by food]
OfflineTraining_rates = {
    [SKILL_CLUB] = 100,
    [SKILL_SWORD] = 100,
    [SKILL_AXE] = 100,
    [SKILL_DISTANCE] = 100,
    [SKILL_SHIELD] = 100,
    [SKILL_MAGLEVEL] = 100
}
-- function that you should edit to make it add other skill etc.
function OfflineTraining_canStartTraining(cid) -- return bool
    return Player(cid):getStorageValue(62665) > 0
end

function OfflineTraining_onEndTraining(cid)
    Player(cid):setStorageValue(62665, 0)
end

function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
    local timeInSeconds = trainTime * 60
    local player = Player(cid)
    local voc = player:getVocation()

    if player:getStorageValue(62665) == SKILL_SWORD then
        player:addSkillTries(SKILL_SWORD, ((timeInSeconds * 1000) / voc:getAttackSpeed()) * OfflineTraining_rates[SKILL_SWORD] / 100, true)
    elseif player:getStorageValue(62665) == SKILL_AXE then
        player:addSkillTries(SKILL_AXE, ((timeInSeconds * 1000) / voc:getAttackSpeed()) * OfflineTraining_rates[SKILL_AXE] / 100, true)
    elseif player:getStorageValue(62665) == SKILL_MAGLEVEL then
        player:addManaSpent((timeInSeconds / voc:getRequiredManaSpent(player:getBaseMagicLevel() + 1)) * OfflineTraining_rates[SKILL_MAGLEVEL] / 100, true)
    elseif player:getStorageValue(62665) == SKILL_CLUB then
        player:addSkillTries(SKILL_CLUB, ((timeInSeconds * 1000) / voc:getAttackSpeed()) * OfflineTraining_rates[SKILL_CLUB] / 100, true)
    elseif player:getStorageValue(62665) == SKILL_DISTANCE then
        player:addSkillTries(SKILL_DISTANCE, ((timeInSeconds * 1000) / voc:getAttackSpeed()) * OfflineTraining_rates[SKILL_DISTANCE] / 100, true)
    end
    player:addSkillTries(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 Player(cid):getStorageValue(62666)
end

function OfflineTraining_setTime(cid, newTime)
    -- set values only between 0 - 720 [12 hours]
    Player(cid):setStorageValue(62666, math.max(0, math.min(newTime, 720)))
    -- 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
        OfflineTraining_setTime(cid, 720)
        OfflineTraining_setLogoutTime(cid) -- block problem with first login 'add time'
    end
end

function OfflineTraining_isTraining(cid)
    return Player(cid):getStorageValue(62667) > 0
end

function OfflineTraining_turnOnTraining(cid)
    Player(cid):setStorageValue(62667, 1)
end

function OfflineTraining_turnOffTraining(cid)
    Player(cid):setStorageValue(62667, 0)
end

function OfflineTraining_getOfflineTime(cid)
    return math.floor((os.time() - Player(cid):getStorageValue(62668)) / 60)
end

function OfflineTraining_setLogoutTime(cid)
    return Player(cid):setStorageValue(62668, os.time())
end

local offlineTrainer = Action()

function offlineTrainer.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1444 then -- sword
        player:setStorageValue(62665, SKILL_SWORD)
    elseif item.itemid == 10349 then -- axe
        player:setStorageValue(62665, SKILL_AXE)
    elseif item.itemid == 8834 then -- mlvl
        player:setStorageValue(62665, SKILL_MAGLEVEL)
    elseif item.itemid == 8626 then -- club
        player:setStorageValue(62665, SKILL_CLUB)
    elseif item.itemid == 10353 then -- distance
        player:setStorageValue(62665, SKILL_DISTANCE)
    end
    if item.actionid == 1000 then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:remove()
    end
    return true
end

offlineTrainer:id(8834, 10353, 8626, 1444, 10349)
offlineTrainer:register()

local offlineTrainerLogin = CreatureEvent("offlineTrainerLogin")

function offlineTrainerLogin.onLogin(player)
    local cid = player:getId()
    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
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "During your abscence you trained for. ".. OfflineTraining_getOfflineTime(cid) .." minutes.")
    return true
end

offlineTrainerLogin:register()

local offlineTrainerLogout = CreatureEvent("offlineTrainerLogout")

function offlineTrainerLogout.onLogout(player)
    local cid = player:getId()
    if OfflineTraining_canStartTraining(cid) then
        OfflineTraining_turnOnTraining(cid)
    end
    OfflineTraining_setLogoutTime(cid)
    return true
end

offlineTrainerLogout:register()
 

Attachments

Back
Top