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

Square Trainer for 1.2?

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
I didn't write this script all I did was update it to the latest sources on github, I'll post it here in sections as it is really big :)
Credits & Instructions
Code:
--[[
    Square Skill Trainer made by Arthur aka artofwork 12/1/14
    Updated 8/29/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
    Added a time check based on how much soul they have left

    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
    experience gain for both free and prem accounts

    Added tile trainer exhaust, 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
   
    add this to login.lua inside of onLogin(cid)
    player:setStorageValue(18010, 0) -- when they login it will reset / set the storage values
    player:setStorageValue(18009, 0)

]]--

Code:
local currentTime = os.time()
local day = 86400 -- 1 full day in seconds
local minimumTime = 0 -- minimum time for vip
local exhaust = 3 -- exhaust in seconds from using trainer
local special = true -- true for vip false for prem
local removeSoul = false -- remove soul from free account
local soul = 1 -- soul to take per minute
local removeSoul = false -- do you want to remove soul from the free accounts forcing them to go out and hunt or let them afk train like prem
local amount = 0 -- amount of soul to take from player per minute
local bonus = special and "VIP" or "premium"
local addSkillTimer = 1000 -- 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 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 = false -- do you want to use the config settings rate of Skills in this script

local addskills =
{
    prem = 1000, -- xp to add as vip/prem (depends if special is true) account per interval
    manaGainPrem = 1200, -- 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,
    manaGainFree = 600, -- mana to add as free account per interval
    freeSkillTries = 10, -- 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
}



local weaponTypes = {
    { 1, 2 }, -- Sword
    { 2, 1 }, -- Club
    { 3, 3 }, -- Axe
    { 4, 5 }, -- Shield
    { 5, 4 } -- Distance
}

function soulCheck(p)
    local msg = ""
    local hour = math.floor(p.soul / 60)
    local minutes = p.soul % 60
    if isSpecial(p.player) then
        msg = ", As a "..bonus.." player you will start training right away! :D "
    else
        if removeSoul then
            if(p.soul > 120) then
                msg = ", you have enough soul points to train for "..hour.." hours and "..minutes.." minutes"
            elseif(p.soul == 120) then
                msg = ", you have enough soul points to train for "..hour.." hours."
            elseif(p.soul > 60 and p.soul < 120) then
                msg = ", you have enough soul points to train for "..hour.." hour and "..minutes.." minutes"
            elseif(p.soul == 60) then
                msg = ", you have enough soul points to train for "..hour.." hour."
            else
                msg = ", you have enough soul points to train for "..minutes.." minutes"
        
            end
        else
             msg = ", If you were a "..bonus.." player you wouldn't have to wait to train."
        end
    end
    p.player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, p.name..msg)
end

-- this function is only effected by free accounts
function templeTeleport(p)
    local player = p.player
    local temple = player:getTown():getTemplePosition()
     if player:isPlayer() then
        player:setStorageValue( 18010, 0)
        Position(p.pos):sendMagicEffect(CONST_ME_TELEPORT)
        player:teleportTo(temple)
        Position(temple):sendMagicEffect(CONST_ME_ENERGYAREA)
     else
        player:sendCancelMessage(p.name..", You dont have the access to do this.")
     end
end

-- this function is only effected by free accounts
function takeSoulPoints(p)
    local player = p.player
    if(player:getSoul() > amount) then
        player:addSoul(-p.soul)
        p.seconds = 60000 -- reset the timer
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Sorry "..(p.name)..", You not have enough soul points to train.")
        addEvent(templeTeleport, 1, p)
    end
end
 
Code:
function isSpecial(player)
    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(configKeys.RATE) or 1
end

function trainMe(p)
    local player = p.player
    local weaponLeft = player:getSlotItem(CONST_SLOT_LEFT)
    local weaponRight = player:getSlotItem(CONST_SLOT_RIGHT)
    if weaponLeft.itemid ~= 0 then
        weaponLeft = Game.getSkillType(weaponLeft.uid) -- not sure about this function
    end
    if weaponRight.itemid ~= 0 then
        weaponRight = Game.getSkillType(weaponRight.uid) -- not sure about this function
    end
    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 gain settings
            player:addManaSpent(addskills["manaGainPrem"] )
        else
            player:addExperience(addskills["free"] * returnRate(useConfigExpRate, RATE_EXPERIENCE) )
            -- add mana to player based on free mana gain settings
            player:addManaSpent(addskills["manaGainFree"] )
        end
        for i = 0, skills do
            if isSpecial(player) then
                if i == 5 then -- shielding, will help balance shield gain
                    player:addSkillTries(5, (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 == 5 then -- shielding, will help balance shield gain
                        player:addSkillTries(5, (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 _, t in pairs(weaponTypes) do
                        if t[1] == weaponLeft or t[1] == weaponRight then 
                            if t[2] == 5 then -- shielding, will help balance shield gain
                                player:addSkillTries(5, (addskills["freeSkillTries"] * addskills["balanceShield"]) * returnRate(useConfigSkillRate, RATE_SKILL) )
                            else
                                player:addSkillTries(t[2], addskills["freeSkillTries"] * returnRate(useConfigSkillRate, RATE_SKILL) )
                            end
                        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 removeSoul then -- if removeSoul is true it will remove soul from the player
                    addEvent(takeSoulPoints, 1, p)
                end
            end
        end
            addEvent(trainMe, addSkillTimer, p)
    end
    return true
end

function TrainerExhaust(player)
    player:setStorageValue(18009, 0)
end

function onStepIn(creature, item, pos, fromPos)
    if not creature:isPlayer() then
        return false
    end
    local player = creature:getPlayer()
    local p = -- this is table is essential so we can pass it to the other functions
    {
        player = player,
        item = item,
        pos = player:getPosition(),
        soul = player:getSoul(),
        seconds = 60000,
        secondsTime = 30,
        name = player:getName()
    }
    if player:isPlayer() then
        if player:getStorageValue(18010) == 0 and player:getStorageValue(18009) == 0 then
            if(p.item.actionid == 900 and (p.soul > amount)) == true then
                player:setStorageValue(18010, 1)
                if removeSoul then
                    soulCheck(p)
                end
                addEvent(train, 1, p)
            end
        else
            player:teleportTo(fromPos, true)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Sorry "..p.name..", You must wait "..exhaust.." seconds to use the trainer again.")
            addEvent(TrainerExhaust, exhaust * 1000, player)
        end
    else
        player:teleportTo(fromPos, true)
    end
    return true
end

function onStepOut(creature, item, pos)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end
    player:setStorageValue(18009, 1)
    player:setStorageValue(18010, 0)
    player:addMana(player:getMaxMana())
    addEvent(TrainerExhaust, exhaust * 1000, player)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training session has now ended.")
    return true
end
 
Last edited:
This is the addvip script that came with the source
Code:
--[[
    I did not write this script and I don't know who did but this works in conjunction with the square trainer, this is why I am including it
    All i did was edit line 15 because if I didn't an error of performing math on a boolean would be returned
]]

function onSay(player, words, param)

    -- configs
    local access = 0
    local days = 15
    -- end configs


    local daysvalue = days * 3600 * 24
    local timenow = os.time()

    if player:getStorageValue(13540) == -1 or player:getStorageValue(13540) == 0 then
        timeleft = timenow + daysvalue
    else
        timeleft = player:getStorageValue(13540) + daysvalue
    end

    if param ~= "" then
        if player:getGroup():getId() >= access then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "was added ".. days .." days VIP in its character.")
            player:setStorageValue(13540, timeleft)
            quantity = math.floor((player:getStorageValue(13540) - timenow) / (3600 * 24))
            player:sendTextMessage(MESSAGE_INFO_DESCR, "you have ".. quantity .." VIP remaining days.")
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Only players with greater access to "..access.." VIPs can add.")
        end
    end
end
 
Last edited:
I actually tested this code for 1.2 & it doesn't work - although I did re-write it, unfortunately I need to get permission to release the code. :(
 
Back
Top