• 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
299
Solutions
1
Reaction score
10
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
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,810
Solutions
432
Reaction score
3,946
This is my best attempt.. but have no way to test.
I also have no idea if forcing the player to say the spell words will trigger the spell or not.

doPlayerCastSpell(cid, words) might be an alternative.. but it's hit or miss whether or not a distribution has the function.

Anyway, good luck.

!train list
!train Light Healing, 400
XML:
<talkaction words="!train;/train" event="script" value="train.lua"/>
Lua:
local players = {}

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
        doCreatureSay(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())
    return true
end
 

tiag0_bn

New Member
Joined
Dec 8, 2011
Messages
46
Reaction score
4
Hello Xikini thanks for the contribution

I tested it here and it's not releasing the magic, it says:
The spell name (utevo lux) either does not exist, or you do not own this spell.

I was asked to create a new topic with this request... if you can continue there and close this I would be grateful

 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,810
Solutions
432
Reaction score
3,946
Hello Xikini thanks for the contribution

I tested it here and it's not releasing the magic, it says:
The spell name (utevo lux) either does not exist, or you do not own this spell.

I was asked to create a new topic with this request... if you can continue there and close this I would be grateful

You don't use the words of the spell, you use the Name of the spell.

So instead of utevo lux you would use light
instead of exura you would use light healing
 

tiag0_bn

New Member
Joined
Dec 8, 2011
Messages
46
Reaction score
4
I was doing this test now, but with no result... when I pull the !train list, the spells don't appear... I was looking for if this function was correct

Could you help me add this function eating and anti idle...I googled something and was trying to do it according to this script...

Lua:
local players = {}
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
        doCreatureSay(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())
    return true
end
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,810
Solutions
432
Reaction score
3,946
I was doing this test now, but with no result... when I pull the !train list, the spells don't appear... I was looking for if this function was correct

Could you help me add this function eating and anti idle...I googled something and was trying to do it according to this script...

local players = {}
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
doCreatureSay(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())
return true
end

Can you just test my original code first, before we worry about modifying it?
I don't have an old server to test on, so am relying on you guys to test it.

When you type !train list do you get an error in console?
 

tiag0_bn

New Member
Joined
Dec 8, 2011
Messages
46
Reaction score
4
is your original script, it only includes line 2-100
I'm testing your script here and neither utevo lux or light works....
I used the command !train spell and the spells do not appear in the book and not error in console..


Spell name and mana threshold required. Ex: !train Light Healing, 400
The spell name (utevo lux) either does not exist, or you do not own this spell.
The spell name (light) either does not exist, or you do not own this spell.

_____________________


thank you, you read my thoughts... was looking for how to use this...
Post automatically merged:


___________________________
I managed to fix the list of spells... but

10:30 The spell name (light healing) either does not exist, or you do not own this spell.


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 .. " Mana: " .. spell.mana .. "\n"

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

doShowTextDialog(cid, 2175, text)
return true
end
 
Last edited:

potinho

Well-Known Member
Joined
Oct 11, 2009
Messages
678
Solutions
15
Reaction score
52
Location
Brazil
Im trying too:

10:32 The spell name (ultimate explosion) either does not exist, or you do not own this spell.
10:33 The spell name (exevo gran mas vis) either does not exist, or you do not own this spell.

/train list apeear blank
 

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
617
Solutions
12
Reaction score
77
There's no way to trigger any spell in other way than by spells, especially by doCreatureSay function.

You need to add "doPlayerCastSpell" function in your sources and it works:
xd.gif
So after these activities, in the code just replace:
Lua:
doCreatureSay(cid, players[cid][1])
for:
Code:
doPlayerCastSpell(cid, players[cid][1])
 

tiag0_bn

New Member
Joined
Dec 8, 2011
Messages
46
Reaction score
4
There's no way to trigger any spell in other way than by spells, especially by doCreatureSay function.

You need to add "doPlayerCastSpell" function in your sources and it works:
View attachment 63706
So after these activities, in the code just replace:
Lua:
doCreatureSay(cid, players[cid][1])
for:
Code:
doPlayerCastSpell(cid, players[cid][1])
Have other solution?
 

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
617
Solutions
12
Reaction score
77
There's no way to trigger any spell in other way than by spells, especially by doCreatureSay function.
As I have written above there's no way without the function.

The function can be found on the forum, just search. That's 4 steps to add it.

Anyway, what's the problem? You use 0.4 version, so you should have sources. If you serious about it or for fun etc just forget.
 

tiag0_bn

New Member
Joined
Dec 8, 2011
Messages
46
Reaction score
4
As I have written above there's no way without the function.

The function can be found on the forum, just search. That's 4 steps to add it.

Anyway, what's the problem? You use 0.4 version, so you should have sources. If you serious about it or for fun etc just forget.
is old... dont have source files...

tx for u help! good day
 

potinho

Well-Known Member
Joined
Oct 11, 2009
Messages
678
Solutions
15
Reaction score
52
Location
Brazil
As I have written above there's no way without the function.

The function can be found on the forum, just search. That's 4 steps to add it.

Anyway, what's the problem? You use 0.4 version, so you should have sources. If you serious about it or for fun etc just forget.
I have added to my sources (using this thread Lua Function - doPlayerCastSpell(cid, spell) (https://otland.net/threads/doplayercastspell-cid-spell.80043/)), there's a way to works with:

/train utevo lux, 20? and auto eat food?

Still showing none spell to use

16:30 The spell name (antidote) either does not exist, or you do not own this spell.
 
Last edited:

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
617
Solutions
12
Reaction score
77
Yep, but you should use the names on the right( on the list)
/train antidote, 20
If not , there can be another problem with this statement:
Lua:
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
Try to remove it while testing
 

potinho

Well-Known Member
Joined
Oct 11, 2009
Messages
678
Solutions
15
Reaction score
52
Location
Brazil
Yep, but you should use the names on the right( on the list)
/train antidote, 20
If not , there can be another problem with this statement:
Lua:
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
Try to remove it while testing
got error on console (im using tfs 0.3.7):

1638302115303.png
 

tiag0_bn

New Member
Joined
Dec 8, 2011
Messages
46
Reaction score
4
comment

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

potinho

Well-Known Member
Joined
Oct 11, 2009
Messages
678
Solutions
15
Reaction score
52
Location
Brazil
Still gotting error, but is working for spells. There's a way to add auto eat to this script and work with /train utevo lux, 20?

1638302729810.png
Post automatically merged:

Now all functions are working for me, but when i type and incorrect spell nothing is returned and got error above on console, actual script, and eating food event got loop error:
1638307363244.png
Lua:
local players = {}
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}
}

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)
    addEvent(autoeat, 20000, cid)
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()
 
    --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())
    return true
end
 
Last edited:
Top