Jump to content

Square Trainer - Perder stamina enquanto treina


Administrador

Recommended Posts

  • Administrador

Ta ai um script muito bom galera, créditos e instruções no próprio script.

--[[
    Square Skill Trainer made by Arthur aka artofwork 12/1/14, my original account
    Updated 10/15/2015, to 1.2 based on tfs sources on github by Codex NG 
   
  
    This script will train all of a players skills indefintely including magic level
    It has a small configuration setup where you can set the number of tries per skill
    The time interval in between each skill try added
    A storage value to help prevent abuse
    You can assign any tile you wish to this script that a player can walk on with action id 900
   
    Now removes offline training time for free accounts

    New in this script?

    skill tries for both free account & premium accounts
    mana gain for both free & premium accounts
    mana multipliers to effect magic level for both free and premium accounts based on percentage
    experience gain for both free and prem accounts

    Added optional all skills for free accounts or just the weapons & shield they have equiped
  
    add this too movements
    <!-- Square Trainer -->
    <movevent event="StepIn" actionid="900" script="squaretrainer.lua"/>
    <movevent event="StepOut" actionid="900" script="squaretrainer.lua"/>
  
    save this file in data\movements\script\ as squaretrainer.lua
]]--

local special = false -- true for vip false for prem
-- do not edit
local currentTime = os.time()
local day = 86400 -- 1 full day in seconds
local minimumTime = 0 -- minimum time for vip
local addSkillTimer = 1000 -- do not edit - time at which skill tries are added
local skills = 5 -- 0 to 5 includes 0:fist, 1:club, 2:sword, 3:axe, 4:distance, 5:shield -- do not edit
-------------------------------

local allskills = false -- should free accounts train all their skills

local removeOfflineTime = true -- do you want to remove offline training time?
-- minutes to remove per minute, should be minimum 2 since they gain a minute for every minute they are not killing something
local timeOfOfflineToRemove = 2
-- minimum hours needed to train, set it to 12 if u want to test the tp to temple
local minimumTimeNeedToUseTrainers = 1

local useConfigMlRate = false -- do you want to use the config settings rate of Magic in this script
local useConfigExpRate = false -- do you want to use the config settings rate of Exp in this script
local useConfigSkillRate = true -- do you want to use the config settings rate of Skills in this script

-- do not edit
    local keys = {
        RATE_SKILL = 6,
        RATE_MAGIC = 8,
        RATE_LOOT = 7,
        RATE_EXPERIENCE = 5
    }

local tseconds = 1000
local tminute = 60 * tseconds
local thour = 60 * tminute
local trainingTimeMax = thour * minimumTimeNeedToUseTrainers  -- 43200000 default value (12 hours)
-----------------

-- used by isSpecial, this allows certain account types to skip the offline time removal
local godAccount = 4

-- tile actionid
local aid = 900

local p = {}

local addskills =
{
    prem = 1000, -- xp to add as vip/prem (depends if special is true) account per interval
    -- the rate is a percentage of their max mana, this way it scales with their level 
    manaGainPremRate = .10, -- mana to add as vip/prem (depends if special is true) account per interval
    premSkillTries = 100, -- Number of tries per skill for vip/prem (depends if special is true) account per interval
    premManaMultiplier = 5, -- when player has full mana multiply how much more mana is used to gain magic level
   
    free = 100,
    manaGainFreeRate = .01, -- mana to add as free account per interval
    freeSkillTries = 1, -- Number of tries per skill for free account
    freeManaMultiplier = 1, -- when player has full mana multiply how much more mana is used to gain magic level
   
    balanceShield = 3  -- 3 is good, but if shielding goes up too quick then lower it, use only whole numbers e.g. 1, 2, 3
}

-- do not edit
local weaponTypes = {
    [0] = { 0, 0 }, -- fist
          { 1, 2 }, -- Sword
          { 2, 1 }, -- Club
          { 3, 3 }, -- Axe
          { 4, 5 }, -- Shield
          { 5, 4 }, -- Distance
          { 6, 0 } -- 6 is rod / wands, 0 is for fists..
}

local shieldId = 5

function getSlottedItems(player)
    local left = pushThing(player:getSlotItem(CONST_SLOT_LEFT)).itemid
    local right = pushThing(player:getSlotItem(CONST_SLOT_RIGHT)).itemid
   
    left = ItemType( left ):getWeaponType()
    right = ItemType( right ):getWeaponType()
    return left, right
end
--------------------------------


-- this function is only effected by free accounts
function templeTeleport(p)
    p.player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    p.player:setStorageValue( 18010, 0)
    local temple = p.player:getTown():getTemplePosition()
    p.player:teleportTo(temple)
    temple:sendMagicEffect(CONST_ME_ENERGYAREA)
    p.player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Sorry, "..p.name.." you don't have enough offline time to train.")
end


function RemoveOfflineTrainingTime(p)
    if trainingTimeCheck(p) then
        p.player:removeOfflineTrainingTime(timeOfOfflineToRemove * 60000)
        p.seconds = 60000 -- reset the timer
    end
end

function trainingTimeCheck(p)
    local time_ = p.player:getOfflineTrainingTime()
    if time_ <= (timeOfOfflineToRemove * tminute) then
        templeTeleport(p)
    end
    if time_ >= trainingTimeMax then
        return true
    else
        templeTeleport(p)
    end
end

function isSpecial(player)
    -- this is so i could test the shit right away
    if player:getAccountType() >= godAccount then
        return true
    end
    if special then
        return (math.floor((player:getStorageValue(13540) - currentTime) / (day)) > minimumTime)
    else
        return player:isPremium()
    end
end

function train(p)
    local player = p.player
    if player:isPlayer() and player:getStorageValue(18010) == 1 then
        if isSpecial(player) then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training session will now begin.")
            addEvent(trainMe, 1, p)
        else -- if free account, they have to wait 30 seconds to begin training
            if p.secondsTime > 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training session will begin in "..(p.secondsTime).." seconds.")
            end
            if p.secondsTime <= 0 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training session will now begin.")
                addEvent(trainMe, 1, p)
            else
                p.secondsTime = p.secondsTime - 10
                addEvent(train, 10000, p)
            end
        end
    end
    return true
end

function returnRate(useRate, RATE)
    return useRate and configManager.getNumber(RATE) - 3300 or 1
end

function trainMe(p)
    local player = p.player
    local weaponLeft, weaponRight = getSlottedItems(player)

    if player:isPlayer() and player:getStorageValue(18010) == 1 then
        if isSpecial(player) then
            player:addExperience(addskills["prem"] * returnRate(useConfigExpRate, RATE_EXPERIENCE) )
            -- add mana to player based on premium mana rate settings
            player:addManaSpent(addskills["manaGainPremRate"] * player:getMaxMana() )
        else
            player:addExperience(addskills["free"] * returnRate(useConfigExpRate, RATE_EXPERIENCE) )
            -- add mana to player based on free mana rate settings
            player:addManaSpent(addskills["manaGainFreeRate"] * player:getMaxMana() )
        end
        for i = 0, skills do
            if isSpecial(player) then
                if i == shieldId then -- shielding, will help balance shield gain
                    player:addSkillTries(i, (addskills["premSkillTries"] * addskills["balanceShield"]) * returnRate(useConfigSkillRate, RATE_SKILL) )
                else
                    player:addSkillTries(i, addskills["premSkillTries"] * returnRate(useConfigSkillRate, RATE_SKILL) ) -- all other skills
                end
            else
                if allskills then
                    if i == shieldId then -- shielding, will help balance shield gain
                        player:addSkillTries(i, (addskills["freeSkillTries"] * addskills["balanceShield"]) * returnRate(useConfigSkillRate, RATE_SKILL) )
                    else
                        player:addSkillTries(i, addskills["freeSkillTries"] * returnRate(useConfigSkillRate, RATE_SKILL) ) -- all other skills
                    end
                else -- this effects only free accounts
                    for i = 0, #weaponTypes do
                        if weaponTypes[i][2] == shieldId and weaponTypes[i][1] == weaponRight then
                            player:addSkillTries(weaponTypes[i][2], (addskills["freeSkillTries"] * addskills["balanceShield"]) * returnRate(useConfigSkillRate, RATE_SKILL) )
                        end
                      
                        if weaponTypes[i][2] ~= shieldId and weaponTypes[i][1] == weaponLeft then
                            player:addSkillTries(weaponTypes[i][2], addskills["freeSkillTries"] * returnRate(useConfigSkillRate, RATE_SKILL) )
                        end
                    end
                end
            end
            -- will increase magic level based on max mana times multiplier
            local maxMana = player:getMaxMana()
            if player:getMana() == maxMana then
                if isSpecial(player) then
                    -- premium account multiplier used to increase level
                    player:addManaSpent(maxMana * (addskills["premManaMultiplier"] * returnRate(useConfigMlRate, RATE_MAGIC)) )
                else
                    -- free account multiplier used to increase level
                    player:addManaSpent(maxMana * (addskills["freeManaMultiplier"] * returnRate(useConfigMlRate, RATE_MAGIC)) )
                end
                player:addMana(-maxMana)
            end
 
        end
        if not isSpecial(player) then
            p.seconds = p.seconds - addSkillTimer
            if(p.seconds <= 1000) then -- we want to be fair so we make sure the player gets a whole minute
                if removeOfflineTime then
                    addEvent(RemoveOfflineTrainingTime, 1, p)
                end
            end
        end
        addEvent(trainMe, addSkillTimer, p)
    end
    return true
end

function onStepIn(player, item, position, fromPosition)
    if not player:isPlayer() then
        return false
    end
  
    p = -- this is table is essential so we can pass it to the other functions
    {
        player = player:getPlayer(),
        item = item,
        pos = player:getPosition(),
        soul = player:getSoul(),
        seconds = 60000,
        secondsTime = 30,
        name = player:getName()
    }
    if player:isPlayer() then
        if player:getStorageValue(18010) < 1 then
            if p.item.actionid == aid then
                player:setStorageValue(18010, 1)
                -- if the player is a free acc they will lose offline training time as they train
                if removeOfflineTime then
                    RemoveOfflineTrainingTime(p)
                end
                addEvent(train, 1, p)
            end
        else
            player:teleportTo(fromPos, true)
        end
    end
    return true
end

function onStepOut(player, item, position, fromPosition)
    p.secondsTime = 30
    stopEvent(train) -- may not work as expected
    stopEvent(trainMe) -- may not work as expected
    player:setStorageValue(18010, 0)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training session has now ended.")
  
    return true
end
Link to comment
Share on other sites

  • 11 months later...
×
×
  • Create New...