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

talkaction mana train tfs 0.4

miguelshta

Member
Joined
Mar 21, 2009
Messages
351
Solutions
1
Reaction score
13
Location
Toronto, Canada
hello i wanted for a script to train mana in my ot to make it work u need an spell an mana to say it example:
!train exura vita,400 >> it will use exura vita when has 400 of mana thanks for all !! <3
 
Eating works, but dunno why errors occur. It happens when you write a spell words, not name.
getPlayerLearnInstantSpell function does not work properly.

Lua:
local players = {}
local eat = {}
local foods = {
    {8, "Crunch.", 2362},
    {15, "Munch.", 2666},
    {12, "Munch.", 2667},
    {10, "Mmmm.", 2668},
    {17, "Munch.", 2669},
    {4, "Gulp.", 2670},
    {30, "Chomp.", 2671},
    {60, "Chomp.", 2672},
    {5, "Yum.", 2673},
    {6, "Yum.", 2674},
    {13, "Yum.", 2675},
    {8, "Yum.", 2676},
    {1, "Yum.", 2677},
    {18, "Slurp.", 2678},
    {1, "Yum.", 2679},
    {2, "Yum.", 2680},
    {9, "Yum.", 2681},
    {20, "Yum.", 2682},
    {17, "Munch.", 2683},
    {8, "Crunch.", 2684},
    {6, "Munch.", 2685},
    {9, "Crunch.", 2686},
    {2, "Crunch.", 2687},
    {9, "Munch.", 2688},
    {10, "Crunch.", 2689},
    {3, "Crunch.", 2690},
    {8, "Crunch.", 2691},
    {6, "Munch.", 2792},
    {9, "Munch.", 2793},
    {6, "Gulp.", 2695},
    {9, "Smack.", 2696},
    {9, "Munch.", 2787},
    {4, "Munch.", 2788},
    {22, "Munch.", 2789},
    {30, "Munch.", 2790},
    {30, "Munch.", 2791},
    {6, "Munch.", 2792},
    {3, "Munch.", 2794},
    {36, "Munch.", 2795},
    {5, "Munch.", 2796},
    {9, "Munch.", 2793},
    {4, "Yum.", 5097},
    {8, "Gulp.", 6125},
    {10, "Mmmm.", 6278},
    {15, "Mmmm.", 6279},
    {12, "Mmmm.", 6393},
    {15, "Mmmm.", 6394},
    {20, "Mmmm.", 6501},
    {6, "Gulp.", 6541},
    {6, "Gulp.", 6542},
    {6, "Gulp.", 6543},
    {6, "Gulp.", 6544},
    {6, "Gulp.", 6545},
    {1, "Mmmm.", 6569},
    {4, "Mmmm.", 6574},
    {15, "Munch.", 7158},
    {13, "Munch.", 7159},
    {7, "Yum.", 7372},
    {7, "Yum.", 7373},
    {7, "Yum.", 7374},
    {7, "Yum.", 7375},
    {7, "Yum.", 7376},
    {7, "Yum.", 7377},
    {4, "Crunch.", 7909},
    {7, "Gulp.", 8838},
    {5, "Yum.", 8839},
    {2, "Yum.", 8840},
    {3, "Urgh.", 8841},
    {3, "Munch.", 8842},
    {3, "Crunch.", 8843},
    {3, "Gulp.", 8844},
    {2, "Munch.", 8845},
    {11, "Yum.", 8447}
}

function autoEat(cid)
    local food = nil
    for _, v in ipairs(foods) do
        if getPlayerItemCount(cid, v[3]) > 0 then
            food = v
            break
        end
    end

    if food ~= nil then
        if((getPlayerFood(cid) + food[1]) >= 400) then
            doPlayerSendCancel(cid, "You are full.")
            eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
            return
        end
        doPlayerFeed(cid, food[1] * 4)
        doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
        doPlayerRemoveItem(cid, food[3], 1)
    end
    eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
    return true
end

local function trainMana(cid, startTime)
    if not isPlayer(cid) then
        players[cid] = nil
        return
    end
    if not players[cid] or players[cid][3] ~= startTime then
        return
    end
    if getCreatureMana(cid) >= players[cid][2] then
        doPlayerCastSpell(cid, players[cid][1])
    end
    addEvent(trainMana, 1000, cid, startTime)
end

local function showSpellList(cid)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.level ~= 0) then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. "%"
            end

            table.insert(t, spell)
        end
    end

    table.sort(t, function(a, b) return a.level < b.level end)
    local text, prevLevel = "", -1
    for i, spell in ipairs(t) do
        local line = ""
        if(prevLevel ~= spell.level) then
            if(i ~= 1) then
                line = "\n"
            end

            line = line .. "Spells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
        end

        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .."\n"
    end

    doShowTextDialog(cid, 2175, text)
end

function onSay(cid, words, param, channel)
    if players[cid] then
        if players[cid][3] == os.time() then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            return true
        end
        players[cid] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        return true
    end
 
    if param == "" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells")
        return true
    elseif param == "list" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
        showSpellList(cid)
        return true
    end

    local t = string.explode(param, ",")
    if t[1] == nil or t[2] == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
        return true
    end
    t[1] = t[1]:lower()
 
    --if not getPlayerLearnedInstantSpell(cid, t[1]) then
   --     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell name (" .. t[1] .. ") either does not exist, or you do not own this spell.")
    --    return true
    --end
 
    local manaThreshold = tonumber(t[2])
        if manaThreshold == nil then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is not a known number. Mana threshold has been set to your maximum mana.")
            manaThreshold = getCreatureMaxMana(cid)
        end
 
        manaThreshold = math.floor(manaThreshold) -- to get rid of any decimals player might have thrown in
        if manaThreshold < 0 or manaThreshold < getInstantSpellInfo(cid, t[1]).mana then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is lower then the spell cost of the spell (" .. t[1] .. "). Mana threshold has been set to your maximum mana.")
            manaThreshold = getCreatureMaxMana(cid)
        elseif manaThreshold > getCreatureMaxMana(cid) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
            manaThreshold = getCreatureMaxMana(cid)
        end
 
    players[cid] = {getInstantSpellInfo(cid, t[1]).words, manaThreshold, os.time()}  
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. t[1] .. "), Mana Threshold: " .. manaThreshold .. "")
    trainMana(cid, os.time())
    autoEat(cid)
    return true
end

Without anty-idle(dunno what it should do)
 
Eating works, but dunno why errors occur. It happens when you write a spell words, not name.
getPlayerLearnInstantSpell function does not work properly.

Lua:
local players = {}
local eat = {}
local foods = {
    {8, "Crunch.", 2362},
    {15, "Munch.", 2666},
    {12, "Munch.", 2667},
    {10, "Mmmm.", 2668},
    {17, "Munch.", 2669},
    {4, "Gulp.", 2670},
    {30, "Chomp.", 2671},
    {60, "Chomp.", 2672},
    {5, "Yum.", 2673},
    {6, "Yum.", 2674},
    {13, "Yum.", 2675},
    {8, "Yum.", 2676},
    {1, "Yum.", 2677},
    {18, "Slurp.", 2678},
    {1, "Yum.", 2679},
    {2, "Yum.", 2680},
    {9, "Yum.", 2681},
    {20, "Yum.", 2682},
    {17, "Munch.", 2683},
    {8, "Crunch.", 2684},
    {6, "Munch.", 2685},
    {9, "Crunch.", 2686},
    {2, "Crunch.", 2687},
    {9, "Munch.", 2688},
    {10, "Crunch.", 2689},
    {3, "Crunch.", 2690},
    {8, "Crunch.", 2691},
    {6, "Munch.", 2792},
    {9, "Munch.", 2793},
    {6, "Gulp.", 2695},
    {9, "Smack.", 2696},
    {9, "Munch.", 2787},
    {4, "Munch.", 2788},
    {22, "Munch.", 2789},
    {30, "Munch.", 2790},
    {30, "Munch.", 2791},
    {6, "Munch.", 2792},
    {3, "Munch.", 2794},
    {36, "Munch.", 2795},
    {5, "Munch.", 2796},
    {9, "Munch.", 2793},
    {4, "Yum.", 5097},
    {8, "Gulp.", 6125},
    {10, "Mmmm.", 6278},
    {15, "Mmmm.", 6279},
    {12, "Mmmm.", 6393},
    {15, "Mmmm.", 6394},
    {20, "Mmmm.", 6501},
    {6, "Gulp.", 6541},
    {6, "Gulp.", 6542},
    {6, "Gulp.", 6543},
    {6, "Gulp.", 6544},
    {6, "Gulp.", 6545},
    {1, "Mmmm.", 6569},
    {4, "Mmmm.", 6574},
    {15, "Munch.", 7158},
    {13, "Munch.", 7159},
    {7, "Yum.", 7372},
    {7, "Yum.", 7373},
    {7, "Yum.", 7374},
    {7, "Yum.", 7375},
    {7, "Yum.", 7376},
    {7, "Yum.", 7377},
    {4, "Crunch.", 7909},
    {7, "Gulp.", 8838},
    {5, "Yum.", 8839},
    {2, "Yum.", 8840},
    {3, "Urgh.", 8841},
    {3, "Munch.", 8842},
    {3, "Crunch.", 8843},
    {3, "Gulp.", 8844},
    {2, "Munch.", 8845},
    {11, "Yum.", 8447}
}

function autoEat(cid)
    local food = nil
    for _, v in ipairs(foods) do
        if getPlayerItemCount(cid, v[3]) > 0 then
            food = v
            break
        end
    end

    if food ~= nil then
        if((getPlayerFood(cid) + food[1]) >= 400) then
            doPlayerSendCancel(cid, "You are full.")
            eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
            return
        end
        doPlayerFeed(cid, food[1] * 4)
        doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
        doPlayerRemoveItem(cid, food[3], 1)
    end
    eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
    return true
end

local function trainMana(cid, startTime)
    if not isPlayer(cid) then
        players[cid] = nil
        return
    end
    if not players[cid] or players[cid][3] ~= startTime then
        return
    end
    if getCreatureMana(cid) >= players[cid][2] then
        doPlayerCastSpell(cid, players[cid][1])
    end
    addEvent(trainMana, 1000, cid, startTime)
end

local function showSpellList(cid)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.level ~= 0) then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. "%"
            end

            table.insert(t, spell)
        end
    end

    table.sort(t, function(a, b) return a.level < b.level end)
    local text, prevLevel = "", -1
    for i, spell in ipairs(t) do
        local line = ""
        if(prevLevel ~= spell.level) then
            if(i ~= 1) then
                line = "\n"
            end

            line = line .. "Spells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
        end

        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .."\n"
    end

    doShowTextDialog(cid, 2175, text)
end

function onSay(cid, words, param, channel)
    if players[cid] then
        if players[cid][3] == os.time() then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            return true
        end
        players[cid] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        return true
    end
 
    if param == "" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells")
        return true
    elseif param == "list" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
        showSpellList(cid)
        return true
    end

    local t = string.explode(param, ",")
    if t[1] == nil or t[2] == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
        return true
    end
    t[1] = t[1]:lower()
 
    --if not getPlayerLearnedInstantSpell(cid, t[1]) then
   --     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell name (" .. t[1] .. ") either does not exist, or you do not own this spell.")
    --    return true
    --end
 
    local manaThreshold = tonumber(t[2])
        if manaThreshold == nil then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is not a known number. Mana threshold has been set to your maximum mana.")
            manaThreshold = getCreatureMaxMana(cid)
        end
 
        manaThreshold = math.floor(manaThreshold) -- to get rid of any decimals player might have thrown in
        if manaThreshold < 0 or manaThreshold < getInstantSpellInfo(cid, t[1]).mana then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is lower then the spell cost of the spell (" .. t[1] .. "). Mana threshold has been set to your maximum mana.")
            manaThreshold = getCreatureMaxMana(cid)
        elseif manaThreshold > getCreatureMaxMana(cid) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
            manaThreshold = getCreatureMaxMana(cid)
        end
 
    players[cid] = {getInstantSpellInfo(cid, t[1]).words, manaThreshold, os.time()} 
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. t[1] .. "), Mana Threshold: " .. manaThreshold .. "")
    trainMana(cid, os.time())
    autoEat(cid)
    return true
end

Without anty-idle(dunno what it should do)
Apparently the food problem has been solved, but when I type an invalid spell it gives an error on the console and doesn't return anything to the user, I'd like it to return an alert (if possible)

Console error when i type "/train blablabla, 300"
1638309153982.png
Post automatically merged:

Another thing I noticed was that, even after turning off the train, he still eats by itself.
 
Last edited:
Yep, today I don't know why that getPlayerLearnedInstantSpell function doesn't work. Maybe tomorrow I figure it out.
Eating problem too.
 
Say when it occurs?
And for eating problem add this between 154 and 155 line:
Lua:
eat[getPlayerGUID(cid)] = nil
Apparently this error happened after I logged out a character that had the train active.
Post automatically merged:

Say when it occurs?
And for eating problem add this between 154 and 155 line:
Lua:
eat[getPlayerGUID(cid)] = nil
Added but player still trying to eat:

Lua:
function onSay(cid, words, param, channel)
    if players[cid] then
        if players[cid][3] == os.time() then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            return true
        end
        players[cid] = nil
        eat[getPlayerGUID(cid)] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        return true
    end
 
Last edited:
I have wasted a lot of my time, coz its more complicated as it seems. Tried to fix the problem when someone write a spell "words", not "name".
Now I fixed "eating problem":
replace:
Lua:
eat[getPlayerGUID(cid)] = nil
with:
Code:
stopEvent(eat[getPlayerGUID(cid)])

Other problems:
  • if you write the spell "words", not "name", there will occur an error
  • getPlayerLearnedInstantSpell does not work as it should
  • we should reset "players" and "eat" tables when logout otherwise there will be errors
 
If someone can contact me over discord and talk/screenshare, for an hour or so, I'm sure we can hash something out.

Without a server for me to test stuff, I can't make this work.
The functions are a bit too finnicky. xD

Pm with your discord details if you want to do it, and then I'll post solution here afterwords.
 
Apparently this error happened after I logged out a character that had the train active.
Post automatically merged:


Added but player still trying to eat:

Lua:
function onSay(cid, words, param, channel)
    if players[cid] then
        if players[cid][3] == os.time() then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            return true
        end
        players[cid] = nil
        eat[getPlayerGUID(cid)] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        return true
    end

Try this

Lua:
local players = {}
local eat = {}
local foods = {
    {8, "Crunch.", 2362},
    {15, "Munch.", 2666},
    {12, "Munch.", 2667},
    {10, "Mmmm.", 2668},
    {17, "Munch.", 2669},
    {4, "Gulp.", 2670},
    {30, "Chomp.", 2671},
    {60, "Chomp.", 2672},
    {5, "Yum.", 2673},
    {6, "Yum.", 2674},
    {13, "Yum.", 2675},
    {8, "Yum.", 2676},
    {1, "Yum.", 2677},
    {18, "Slurp.", 2678},
    {1, "Yum.", 2679},
    {2, "Yum.", 2680},
    {9, "Yum.", 2681},
    {20, "Yum.", 2682},
    {17, "Munch.", 2683},
    {8, "Crunch.", 2684},
    {6, "Munch.", 2685},
    {9, "Crunch.", 2686},
    {2, "Crunch.", 2687},
    {9, "Munch.", 2688},
    {10, "Crunch.", 2689},
    {3, "Crunch.", 2690},
    {8, "Crunch.", 2691},
    {6, "Munch.", 2792},
    {9, "Munch.", 2793},
    {6, "Gulp.", 2695},
    {9, "Smack.", 2696},
    {9, "Munch.", 2787},
    {4, "Munch.", 2788},
    {22, "Munch.", 2789},
    {30, "Munch.", 2790},
    {30, "Munch.", 2791},
    {6, "Munch.", 2792},
    {3, "Munch.", 2794},
    {36, "Munch.", 2795},
    {5, "Munch.", 2796},
    {9, "Munch.", 2793},
    {4, "Yum.", 5097},
    {8, "Gulp.", 6125},
    {10, "Mmmm.", 6278},
    {15, "Mmmm.", 6279},
    {12, "Mmmm.", 6393},
    {15, "Mmmm.", 6394},
    {20, "Mmmm.", 6501},
    {6, "Gulp.", 6541},
    {6, "Gulp.", 6542},
    {6, "Gulp.", 6543},
    {6, "Gulp.", 6544},
    {6, "Gulp.", 6545},
    {1, "Mmmm.", 6569},
    {4, "Mmmm.", 6574},
    {15, "Munch.", 7158},
    {13, "Munch.", 7159},
    {7, "Yum.", 7372},
    {7, "Yum.", 7373},
    {7, "Yum.", 7374},
    {7, "Yum.", 7375},
    {7, "Yum.", 7376},
    {7, "Yum.", 7377},
    {4, "Crunch.", 7909},
    {7, "Gulp.", 8838},
    {5, "Yum.", 8839},
    {2, "Yum.", 8840},
    {3, "Urgh.", 8841},
    {3, "Munch.", 8842},
    {3, "Crunch.", 8843},
    {3, "Gulp.", 8844},
    {2, "Munch.", 8845},
    {11, "Yum.", 8447}
}

function autoEat(cid)
    if not isPlayer(cid) then
        local v = eat[getPlayerGUID(cid)]
        if v then v = nil end
        return
    end

    local food = nil
    for _, v in ipairs(foods) do
        if getPlayerItemCount(cid, v[3]) > 0 then
            food = v
            break
        end
    end

    if food == nil then
        eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
        return
    end

    if((getPlayerFood(cid) + food[1]) >= 400) then
        doPlayerSendCancel(cid, "You are full.")
        eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
        return
    end

    doPlayerFeed(cid, food[1] * 4)
    doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
    doPlayerRemoveItem(cid, food[3], 1)
    eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
    return true
end

local function trainMana(cid, startTime)
    if not isPlayer(cid) then
        players[cid] = nil
        return
    end
    if not players[cid] or players[cid][3] ~= startTime then
        return
    end
    if getCreatureMana(cid) >= players[cid][2] then
        doPlayerCastSpell(cid, players[cid][1])
    end
    addEvent(trainMana, 1000, cid, startTime)
end

local function showSpellList(cid)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.level ~= 0) then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. "%"
            end

            table.insert(t, spell)
        end
    end

    table.sort(t, function(a, b) return a.level < b.level end)
    local text, prevLevel = "", -1
    for i, spell in ipairs(t) do
        local line = ""
        if(prevLevel ~= spell.level) then
            if(i ~= 1) then
                line = "\n"
            end

            line = line .. "Spells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
        end

        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .."\n"
    end

    doShowTextDialog(cid, 2175, text)
end

function onSay(cid, words, param, channel)
    if param == "" or param == "info" then
        return doPlayerPopupFYI(cid,
            "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells\n" ..
            "Available parameters:\n\n" ..
            "-- List\n" ..
            "-- Stop\n" ..
            "-- Info\n" ..
            "-- SpellName, ManaThreshold")
    elseif param == "list" then
        showSpellList(cid)
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
    elseif param == "stop" then
        if players[cid] then
            if players[cid][3] == os.time() then
                return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            end
            eat[getPlayerGUID(cid)] = nil
            players[cid] = nil
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        end      
    end

    if players[cid] then
        return doPlayerSendCancel(cid, "You already have the training activated.")
    end

    local t = string.explode(param, ",")
    local name = t[1]
    local manaThreshold = tonumber(t[2])
    if name == nil or manaThreshold == nil then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
    end

    name = name:lower()
    manaThreshold = math.floor(manaThreshold)
 
    if not getPlayerLearnedInstantSpell(cid, name) then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell name (" .. name .. ") either does not exist, or you do not own this spell.")
    end

    local spellInfo = getInstantSpellInfo(cid, name)
    if manaThreshold < 0 or manaThreshold < spellInfo.mana then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. manaThreshold .. ") is lower then the spell cost of the spell (" .. name .. "). Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    elseif manaThreshold > getCreatureMaxMana(cid) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. manaThreshold .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
 
    players[cid] = {spellInfo.words, manaThreshold, os.time()}
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. name .. "), Mana Threshold: " .. manaThreshold .. "")
    trainMana(cid, os.time())
    autoEat(cid)
    return true
end
 
i am trying to compile my project to test this script ... i am very happy and grateful for the help and modifications of the script ... and who wins is the community with new scripts ..
Post automatically merged:

you can add the dance or anti idle parameter to the project... so that the player can use the command to train without falling... thanks for editing the script it's top
 
Last edited:
If someone can contact me over discord and talk/screenshare, for an hour or so, I'm sure we can hash something out.

Without a server for me to test stuff, I can't make this work.
The functions are a bit too finnicky. xD

Pm with your discord details if you want to do it, and then I'll post solution here afterwords.
i will do it thanks. Wich ur discord @Xikini ?
Post automatically merged:

Try this

Lua:
local players = {}
local eat = {}
local foods = {
    {8, "Crunch.", 2362},
    {15, "Munch.", 2666},
    {12, "Munch.", 2667},
    {10, "Mmmm.", 2668},
    {17, "Munch.", 2669},
    {4, "Gulp.", 2670},
    {30, "Chomp.", 2671},
    {60, "Chomp.", 2672},
    {5, "Yum.", 2673},
    {6, "Yum.", 2674},
    {13, "Yum.", 2675},
    {8, "Yum.", 2676},
    {1, "Yum.", 2677},
    {18, "Slurp.", 2678},
    {1, "Yum.", 2679},
    {2, "Yum.", 2680},
    {9, "Yum.", 2681},
    {20, "Yum.", 2682},
    {17, "Munch.", 2683},
    {8, "Crunch.", 2684},
    {6, "Munch.", 2685},
    {9, "Crunch.", 2686},
    {2, "Crunch.", 2687},
    {9, "Munch.", 2688},
    {10, "Crunch.", 2689},
    {3, "Crunch.", 2690},
    {8, "Crunch.", 2691},
    {6, "Munch.", 2792},
    {9, "Munch.", 2793},
    {6, "Gulp.", 2695},
    {9, "Smack.", 2696},
    {9, "Munch.", 2787},
    {4, "Munch.", 2788},
    {22, "Munch.", 2789},
    {30, "Munch.", 2790},
    {30, "Munch.", 2791},
    {6, "Munch.", 2792},
    {3, "Munch.", 2794},
    {36, "Munch.", 2795},
    {5, "Munch.", 2796},
    {9, "Munch.", 2793},
    {4, "Yum.", 5097},
    {8, "Gulp.", 6125},
    {10, "Mmmm.", 6278},
    {15, "Mmmm.", 6279},
    {12, "Mmmm.", 6393},
    {15, "Mmmm.", 6394},
    {20, "Mmmm.", 6501},
    {6, "Gulp.", 6541},
    {6, "Gulp.", 6542},
    {6, "Gulp.", 6543},
    {6, "Gulp.", 6544},
    {6, "Gulp.", 6545},
    {1, "Mmmm.", 6569},
    {4, "Mmmm.", 6574},
    {15, "Munch.", 7158},
    {13, "Munch.", 7159},
    {7, "Yum.", 7372},
    {7, "Yum.", 7373},
    {7, "Yum.", 7374},
    {7, "Yum.", 7375},
    {7, "Yum.", 7376},
    {7, "Yum.", 7377},
    {4, "Crunch.", 7909},
    {7, "Gulp.", 8838},
    {5, "Yum.", 8839},
    {2, "Yum.", 8840},
    {3, "Urgh.", 8841},
    {3, "Munch.", 8842},
    {3, "Crunch.", 8843},
    {3, "Gulp.", 8844},
    {2, "Munch.", 8845},
    {11, "Yum.", 8447}
}

function autoEat(cid)
    if not isPlayer(cid) then
        local v = eat[getPlayerGUID(cid)]
        if v then v = nil end
        return
    end

    local food = nil
    for _, v in ipairs(foods) do
        if getPlayerItemCount(cid, v[3]) > 0 then
            food = v
            break
        end
    end

    if food == nil then
        eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
        return
    end

    if((getPlayerFood(cid) + food[1]) >= 400) then
        doPlayerSendCancel(cid, "You are full.")
        eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
        return
    end

    doPlayerFeed(cid, food[1] * 4)
    doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
    doPlayerRemoveItem(cid, food[3], 1)
    eat[getPlayerGUID(cid)] = addEvent(autoEat, 20000, cid)
    return true
end

local function trainMana(cid, startTime)
    if not isPlayer(cid) then
        players[cid] = nil
        return
    end
    if not players[cid] or players[cid][3] ~= startTime then
        return
    end
    if getCreatureMana(cid) >= players[cid][2] then
        doPlayerCastSpell(cid, players[cid][1])
    end
    addEvent(trainMana, 1000, cid, startTime)
end

local function showSpellList(cid)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.level ~= 0) then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. "%"
            end

            table.insert(t, spell)
        end
    end

    table.sort(t, function(a, b) return a.level < b.level end)
    local text, prevLevel = "", -1
    for i, spell in ipairs(t) do
        local line = ""
        if(prevLevel ~= spell.level) then
            if(i ~= 1) then
                line = "\n"
            end

            line = line .. "Spells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
        end

        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .."\n"
    end

    doShowTextDialog(cid, 2175, text)
end

function onSay(cid, words, param, channel)
    if param == "" or param == "info" then
        return doPlayerPopupFYI(cid,
            "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells\n" ..
            "Available parameters:\n\n" ..
            "-- List\n" ..
            "-- Stop\n" ..
            "-- Info\n" ..
            "-- SpellName, ManaThreshold")
    elseif param == "list" then
        showSpellList(cid)
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
    elseif param == "stop" then
        if players[cid] then
            if players[cid][3] == os.time() then
                return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            end
            eat[getPlayerGUID(cid)] = nil
            players[cid] = nil
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        end 
    end

    if players[cid] then
        return doPlayerSendCancel(cid, "You already have the training activated.")
    end

    local t = string.explode(param, ",")
    local name = t[1]
    local manaThreshold = tonumber(t[2])
    if name == nil or manaThreshold == nil then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
    end

    name = name:lower()
    manaThreshold = math.floor(manaThreshold)
 
    if not getPlayerLearnedInstantSpell(cid, name) then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell name (" .. name .. ") either does not exist, or you do not own this spell.")
    end

    local spellInfo = getInstantSpellInfo(cid, name)
    if manaThreshold < 0 or manaThreshold < spellInfo.mana then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. manaThreshold .. ") is lower then the spell cost of the spell (" .. name .. "). Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    elseif manaThreshold > getCreatureMaxMana(cid) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. manaThreshold .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
 
    players[cid] = {spellInfo.words, manaThreshold, os.time()}
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. name .. "), Mana Threshold: " .. manaThreshold .. "")
    trainMana(cid, os.time())
    autoEat(cid)
    return true
end
Not work for me @Alberto Cabrera , any spell i try to train show me this:

08:14 The spell name (strong haste) either does not exist, or you do not own this spell.

Tried using spell name (ultimate explosion, for example), or magic words (exevo gran mas vis), with gamemaster player works, and after stop training, still try to eat.
 
Last edited:
Can use the spell name or spell words.
Will auto-eat food.

Line 52 has the 'anti-idle' feature, however is disabled by default. Un-greentext this line to enable it.
I have it disabled by default, because I have no idea if the ot-serv-list sites will ban you for using it.
Use the anti-idle at your own risk.

Example ways to use the talkaction.
!train exevo gran mas vis, 800
!train Ultimate Explosion, 800
!train list -- shows list of all spells you own

Lua:
local players = {}

local FOODS, MAX_FOOD = {
    [2328] = {84, "Gulp."},  [2362] = {48, "Yum."}, [2666] = {180, "Munch."}, [2667] = {144, "Munch."},
    [2668] = {120, "Mmmm."}, [2669] = {204, "Munch."}, [2670] = {48, "Gulp."}, [2671] = {360, "Chomp."},
    [2672] = {720, "Chomp."}, [2673] = {60, "Yum."}, [2674] = {72, "Yum."}, [2675] = {156, "Yum."},
    [2676] = {96, "Yum."}, [2677] = {12, "Yum."}, [2678] = {216, "Slurp."}, [2679] = {12, "Yum."},
    [2680] = {24, "Yum."}, [2681] = {108, "Yum."}, [2682] = {240, "Yum."}, [2683] = {204, "Munch."},
    [2684] = {60, "Crunch."}, [2685] = {72, "Munch."}, [2686] = {108, "Crunch."}, [2687] = {24, "Crunch."},
    [2688] = {24, "Mmmm."}, [2689] = {120, "Crunch."}, [2690] = {72, "Crunch."}, [2691] = {96, "Crunch."},
    [2695] = {72, "Gulp."}, [2696] = {108, "Smack."}, [8112] = {108, "Urgh."}, [2787] = {108, "Crunch."},
    [2788] = {48, "Munch."}, [2789] = {264, "Munch."}, [2790] = {360, "Crunch."}, [2791] = {108, "Crunch."},
    [2792] = {72, "Crunch."}, [2793] = {144, "Crunch."}, [2794] = {36, "Crunch."}, [2795] = {432, "Crunch."},
    [2796] = {300, "Crunch."}
}, 1200

local function autoEat(cid)
    for food, foodinfo in pairs(FOODS) do
        if getPlayerItemCount(cid, food) > 0 then
            if getPlayerFood(cid) + foodinfo[1] * 3 < MAX_FOOD then
                doPlayerFeed(cid, foodinfo[1])
                doPlayerRemoveItem(cid, food, 1)
                doCreatureSay(cid, foodinfo[2], TALKTYPE_MONSTER)
            end
            break
        end
    end
end

local function trainMana(cid, startTime)
    if not isPlayer(cid) then
        players[cid] = nil
        return
    end
    if not players[cid] or players[cid][3] ~= startTime then
        return
    end
    if getCreatureMana(cid) >= players[cid][2] then
        if not doCreatureCastSpell(cid, players[cid][1]) then
            doCreatureSay(cid, "Cannot cast spell.")
            players[cid] = nil
            return
        end
        local mana = getInstantSpellInfo(cid, players[cid][1]).mana
        doCreatureAddMana(cid, -(mana), false)
        doPlayerAddSpentMana(cid, mana, true)
        doCreatureSay(cid, getInstantSpellInfo(cid, players[cid][1]).words, TALKTYPE_MONSTER_SAY)
    end
    if getPlayerFood(cid) < 10 then -- if less then 10 seconds of food time left
        autoEat(cid)
    end
    --doPlayerSetIdleTime(cid, 0)
    addEvent(trainMana, 1000, cid, startTime)
end

local function showSpellList(cid)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.mlevel ~= 0) then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. "%"
            end
    
            table.insert(t, spell)
        end
    end
    
    table.sort(t, function(a, b) return a.mlevel < b.mlevel end)
    local text, prevLevel = "", -1
    for i, spell in ipairs(t) do
        local line = ""
        if(prevLevel ~= spell.mlevel) then
            if(i ~= 1) then
                line = "\n"
            end
            line = line .. "Spells for Magic Level " .. spell.mlevel .. "\n"
            prevLevel = spell.mlevel
        end
        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
    end
    doShowTextDialog(cid, 2175, text)
end


function onSay(cid, words, param, channel)
    if players[cid] then
        if players[cid][3] == os.time() then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            return true
        end
        players[cid] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        return true
    end
    
    if param == "" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells")
        return true
    elseif param == "list" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
        showSpellList(cid)
        return true
    end
    
    local t = string.explode(param, ",")
    if t[1] == nil or t[2] == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
        return true
    end
    t[1] = t[1]:lower()
    
    local spell
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        spell = getPlayerInstantSpellInfo(cid, i)
        if spell.name:lower() == t[1] or spell.words:lower() == t[1] then
            t[1] = spell.name:lower()
            spell = true
            break
        end
    end
    
    if spell ~= true then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell (" .. t[1] .. ") does not exist.")
        return true
    end
    
    local manaThreshold = tonumber(t[2])
    if manaThreshold == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is not a known number. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
    
    manaThreshold = math.floor(manaThreshold) -- to get rid of any decimals player might have thrown in
    if manaThreshold < 0 or manaThreshold < getInstantSpellInfo(cid, t[1]).mana then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is lower then the spell cost of the spell (" .. t[1] .. "). Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    elseif manaThreshold > getCreatureMaxMana(cid) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
    
    players[cid] = {getInstantSpellInfo(cid, t[1]).name, manaThreshold, os.time()}   
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. t[1] .. "), Mana Threshold: " .. manaThreshold .. "")
    trainMana(cid, os.time())
    return true
end
 
Last edited:
I made some script joins... but this latest version doesn't cast runes... some solution ?


Lua:
local players = {}


local FOODS, MAX_FOOD = {
    [2328] = {84, "Gulp."},  [2362] = {48, "Yum."}, [2666] = {180, "Munch."}, [2667] = {144, "Munch."},
    [2668] = {120, "Mmmm."}, [2669] = {204, "Munch."}, [2670] = {48, "Gulp."}, [2671] = {360, "Chomp."},
    [2672] = {720, "Chomp."}, [2673] = {60, "Yum."}, [2674] = {72, "Yum."}, [2675] = {156, "Yum."},
    [2676] = {96, "Yum."}, [2677] = {12, "Yum."}, [2678] = {216, "Slurp."}, [2679] = {12, "Yum."},
    [2680] = {24, "Yum."}, [2681] = {108, "Yum."}, [2682] = {240, "Yum."}, [2683] = {204, "Munch."},
    [2684] = {60, "Crunch."}, [2685] = {72, "Munch."}, [2686] = {108, "Crunch."}, [2687] = {24, "Crunch."},
    [2688] = {24, "Mmmm."}, [2689] = {120, "Crunch."}, [2690] = {72, "Crunch."}, [2691] = {96, "Crunch."},
    [2695] = {72, "Gulp."}, [2696] = {108, "Smack."}, [8112] = {108, "Urgh."}, [2787] = {108, "Crunch."},
    [2788] = {48, "Munch."}, [2789] = {264, "Munch."}, [2790] = {360, "Crunch."}, [2791] = {108, "Crunch."},
    [2792] = {72, "Crunch."}, [2793] = {144, "Crunch."}, [2794] = {36, "Crunch."}, [2795] = {432, "Crunch."},
    [2796] = {300, "Crunch."}
}, 1200


local function autoEat(cid)
    for food, foodinfo in pairs(FOODS) do
        if getPlayerItemCount(cid, food) > 0 then
            if getPlayerFood(cid) + foodinfo[1] * 3 < MAX_FOOD then
                doPlayerFeed(cid, foodinfo[1])
                doPlayerRemoveItem(cid, food, 1)
                doCreatureSay(cid, foodinfo[2], TALKTYPE_MONSTER)
            end
            break
        end
    end
end


local function trainMana(cid, startTime)
    if not isPlayer(cid) then
        players[cid] = nil
        return
    end
    if not players[cid] or players[cid][3] ~= startTime then
        return
    end
    if getCreatureMana(cid) >= players[cid][2] then
        print(players[cid][1])
        if not doCreatureCastSpell(cid, players[cid][1]) then
            doCreatureSay(cid, "Cannot cast spell.")
            players[cid] = nil
            return
        end
        local mana = getInstantSpellInfo(cid, players[cid][1]).mana
        doCreatureAddMana(cid, -(mana), false)
        doPlayerAddSpentMana(cid, mana, true)
        doCreatureSay(cid, getInstantSpellInfo(cid, players[cid][1]).words, TALKTYPE_SAY)
    end
    if getPlayerFood(cid) < 10 then -- if less then 10 seconds of food time left
        autoEat(cid)
    end
    --doPlayerSetIdleTime(cid, 0)
    addEvent(trainMana, 3000, cid, startTime)
end


local function showSpellList(cid)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.mlevel ~= 0) then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. "%"
            end
  
            table.insert(t, spell)
        end
    end
  
    table.sort(t, function(a, b) return a.mlevel < b.mlevel end)
    local text, prevLevel = "", -1
    for i, spell in ipairs(t) do
        local line = ""
        if(prevLevel ~= spell.mlevel) then
            if(i ~= 1) then
                line = "\n"
            end
            line = line .. "Spells for Magic Level " .. spell.mlevel .. "\n"
            prevLevel = spell.mlevel
        end
        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
    end
    doShowTextDialog(cid, 2175, text)
end




function onSay(cid, words, param, channel)
    if players[cid] then
        if players[cid][3] == os.time() then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            return true
        end
        players[cid] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        return true
    end
  
  if param == "" or param == "info" then
        return doShowTextDialog(cid, 2175,
            "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells\n" ..
            "Available parameters:\n\n" ..
            "-- List\n" ..
            "-- Stop\n" ..
            "-- Info\n")
    elseif param == "list" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
        showSpellList(cid)
        return true
    end
  
    local t = string.explode(param, ",")
    if t[1] == nil or t[2] == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
        return true
    end
    t[1] = t[1]:lower()
  
    local spell
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        spell = getPlayerInstantSpellInfo(cid, i)
        if spell.name:lower() == t[1] or spell.words:lower() == t[1] then
            t[1] = spell.name:lower()
            spell = true
            break
        end
    end
  
    if spell ~= true then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell (" .. t[1] .. ") does not exist.")
        return true
    end
  
    local manaThreshold = tonumber(t[2])
    if manaThreshold == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is not a known number. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
  
    manaThreshold = math.floor(manaThreshold) -- to get rid of any decimals player might have thrown in
    if manaThreshold < 0 or manaThreshold < getInstantSpellInfo(cid, t[1]).mana then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is lower then the spell cost of the spell (" .. t[1] .. "). Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    elseif manaThreshold > getCreatureMaxMana(cid) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
  
    players[cid] = {getInstantSpellInfo(cid, t[1]).name, manaThreshold, os.time()} 
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. t[1] .. "), Mana Threshold: " .. manaThreshold .. "")
    trainMana(cid, os.time())
    return true
end
 
Can use the spell name or spell words.
Will auto-eat food.

Line 52 has the 'anti-idle' feature, however is disabled by default. Un-greentext this line to enable it.
I have it disabled by default, because I have no idea if the ot-serv-list sites will ban you for using it.
Use the anti-idle at your own risk.

Example ways to use the talkaction.
!train exevo gran mas vis, 800
!train Ultimate Explosion, 800
!train list -- shows list of all spells you own

Lua:
local players = {}

local FOODS, MAX_FOOD = {
    [2328] = {84, "Gulp."},  [2362] = {48, "Yum."}, [2666] = {180, "Munch."}, [2667] = {144, "Munch."},
    [2668] = {120, "Mmmm."}, [2669] = {204, "Munch."}, [2670] = {48, "Gulp."}, [2671] = {360, "Chomp."},
    [2672] = {720, "Chomp."}, [2673] = {60, "Yum."}, [2674] = {72, "Yum."}, [2675] = {156, "Yum."},
    [2676] = {96, "Yum."}, [2677] = {12, "Yum."}, [2678] = {216, "Slurp."}, [2679] = {12, "Yum."},
    [2680] = {24, "Yum."}, [2681] = {108, "Yum."}, [2682] = {240, "Yum."}, [2683] = {204, "Munch."},
    [2684] = {60, "Crunch."}, [2685] = {72, "Munch."}, [2686] = {108, "Crunch."}, [2687] = {24, "Crunch."},
    [2688] = {24, "Mmmm."}, [2689] = {120, "Crunch."}, [2690] = {72, "Crunch."}, [2691] = {96, "Crunch."},
    [2695] = {72, "Gulp."}, [2696] = {108, "Smack."}, [8112] = {108, "Urgh."}, [2787] = {108, "Crunch."},
    [2788] = {48, "Munch."}, [2789] = {264, "Munch."}, [2790] = {360, "Crunch."}, [2791] = {108, "Crunch."},
    [2792] = {72, "Crunch."}, [2793] = {144, "Crunch."}, [2794] = {36, "Crunch."}, [2795] = {432, "Crunch."},
    [2796] = {300, "Crunch."}
}, 1200

local function autoEat(cid)
    for food, foodinfo in pairs(FOODS) do
        if getPlayerItemCount(cid, food) > 0 then
            if getPlayerFood(cid) + foodinfo[1] * 3 < MAX_FOOD then
                doPlayerFeed(cid, foodinfo[1])
                doPlayerRemoveItem(cid, food, 1)
                doCreatureSay(cid, foodinfo[2], TALKTYPE_MONSTER)
            end
            break
        end
    end
end

local function trainMana(cid, startTime)
    if not isPlayer(cid) then
        players[cid] = nil
        return
    end
    if not players[cid] or players[cid][3] ~= startTime then
        return
    end
    if getCreatureMana(cid) >= players[cid][2] then
        if not doCreatureCastSpell(cid, players[cid][1]) then
            doCreatureSay(cid, "Cannot cast spell.")
            players[cid] = nil
            return
        end
        local mana = getInstantSpellInfo(cid, players[cid][1]).mana
        doCreatureAddMana(cid, -(mana), false)
        doPlayerAddSpentMana(cid, mana, true)
        doCreatureSay(cid, getInstantSpellInfo(cid, players[cid][1]).words, TALKTYPE_MONSTER_SAY)
    end
    if getPlayerFood(cid) < 10 then -- if less then 10 seconds of food time left
        autoEat(cid)
    end
    --doPlayerSetIdleTime(cid, 0)
    addEvent(trainMana, 1000, cid, startTime)
end

local function showSpellList(cid)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.mlevel ~= 0) then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. "%"
            end
   
            table.insert(t, spell)
        end
    end
   
    table.sort(t, function(a, b) return a.mlevel < b.mlevel end)
    local text, prevLevel = "", -1
    for i, spell in ipairs(t) do
        local line = ""
        if(prevLevel ~= spell.mlevel) then
            if(i ~= 1) then
                line = "\n"
            end
            line = line .. "Spells for Magic Level " .. spell.mlevel .. "\n"
            prevLevel = spell.mlevel
        end
        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
    end
    doShowTextDialog(cid, 2175, text)
end


function onSay(cid, words, param, channel)
    if players[cid] then
        if players[cid][3] == os.time() then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training cannot be stopped this quickly. Please wait a few seconds.")
            return true
        end
        players[cid] = nil
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has been stopped.")
        return true
    end
   
    if param == "" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400 | !train list -> will show list of owned spells")
        return true
    elseif param == "list" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Here is a list of your current spells.")
        showSpellList(cid)
        return true
    end
   
    local t = string.explode(param, ",")
    if t[1] == nil or t[2] == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Spell name and mana threshold required. Ex: !train Light Healing, 400")
        return true
    end
    t[1] = t[1]:lower()
   
    local spell
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        spell = getPlayerInstantSpellInfo(cid, i)
        if spell.name:lower() == t[1] or spell.words:lower() == t[1] then
            t[1] = spell.name:lower()
            spell = true
            break
        end
    end
   
    if spell ~= true then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The spell (" .. t[1] .. ") does not exist.")
        return true
    end
   
    local manaThreshold = tonumber(t[2])
    if manaThreshold == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is not a known number. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
   
    manaThreshold = math.floor(manaThreshold) -- to get rid of any decimals player might have thrown in
    if manaThreshold < 0 or manaThreshold < getInstantSpellInfo(cid, t[1]).mana then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is lower then the spell cost of the spell (" .. t[1] .. "). Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    elseif manaThreshold > getCreatureMaxMana(cid) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The mana threshold chosen (" .. t[2] .. ") is higher then your maxmimum mana. Mana threshold has been set to your maximum mana.")
        manaThreshold = getCreatureMaxMana(cid)
    end
   
    players[cid] = {getInstantSpellInfo(cid, t[1]).name, manaThreshold, os.time()}  
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Training has started! Spell: (" .. t[1] .. "), Mana Threshold: " .. manaThreshold .. "")
    trainMana(cid, os.time())
    return true
end
is work in tfs 1.2?
 
Back
Top