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

Solved [OTX3] !spells talkaction not working.

freaked1

Active Member
Joined
Jan 30, 2008
Messages
486
Solutions
5
Reaction score
29
Location
Sweden
A little problem with talkaction !spells.
I don't know if the problem lies within the compat.lua or the script itself.

Error message:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/spells.lua:onSay
data/lib/compat/compat.lua:1010: attempt to call method 'getInstantSpellCount' (a nil value)
stack traceback:
[C]: in function 'getInstantSpellCount'
data/lib/compat/compat.lua:1010: in function 'getPlayerInstantSpellCount'
data/talkactions/scripts/spells.lua:4: in function <data/talkactions/scripts/spells.lua:1>

Function in compat.lua:
Lua:
function getPlayerInstantSpellCount(cid) local p = Player(cid) return p ~= nil and p:getInstantSpellCount() end
function getPlayerInstantSpellInfo(cid, spellId)
    local player = Player(cid)
    if not player then
        return false
    end

    local spell = Spell(spellId)
    if not spell or not player:canCast(spell) then
        return false
    end

    return spell
end

talkactions/scripts/spells.lua
Lua:
function onSay(player, words, param)
    if player:getExhaustion(1000) <= 0 then
        player:setExhaustion(1000, 2)
        local count = getPlayerInstantSpellCount(player)
        local text = ""
        local spells = {}
        for i = 0, count - 1 do
            local spell = getPlayerInstantSpellInfo(player, i)
            if spell.level ~= 0 then
                if spell.manapercent > 0 then
                    spell.mana = spell.manapercent .. "%"
                end
                spells[#spells + 1] = spell
            end
        end

        table.sort(spells, function(a, b) return a.level < b.level end)

        local prevLevel = -1
        for i, spell in ipairs(spells) 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

        player:showTextDialog(SPELL_BOOK, text)
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You\'re exhausted for: '..player:getExhaustion(1000)..' seconds.')
    end
end

Thanks in advance!
 
Solution
It says that player:getInstantSpellCount() function doesn't exist.
On a spellbook script you can see that the substitute to this function is player:getInstantSpells(), which creates a table with info about every learnt spell, where it's size is a count.

For function getPlayerInstantSpellCount(cid), you can try to change it for something like:
Lua:
function getPlayerInstantSpellCount(cid)
 local p = Player(cid)
 local spells = p:getInstantSpells()
return p ~= nil and #spells
end

But, since you can use player:getInstantSpells() right away, i believe it's redundant.
Solved by using the same as spellbook but modifying a little!
Would still be good if someone could help me with the error, I can't figure it out but want to learn a little if someone is a little patient :)

PS: I have no errors now with this:

talkactions/scripts/spells.lua
Lua:
function onSay(player, words, param)
    if player:getExhaustion(1000) <= 0 then
        player:setExhaustion(1000, 2)
        local text = ""
        local spells = {}
        for _, spell in ipairs(player:getInstantSpells()) do
            if spell.level ~= 0 then
                if spell.manapercent > 0 then
                    spell.mana = spell.manapercent .. "%"
                end
                spells[#spells + 1] = spell
            end
        end

        table.sort(spells, function(a, b) return a.level < b.level end)

        local prevLevel = -1
        for i, spell in ipairs(spells) 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
        player:showTextDialog(SPELL_BOOK, text)
        else
    player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You\'re exhausted for: '..player:getExhaustion(1000)..' seconds.')
    end
end
 
It says that player:getInstantSpellCount() function doesn't exist.
On a spellbook script you can see that the substitute to this function is player:getInstantSpells(), which creates a table with info about every learnt spell, where it's size is a count.

For function getPlayerInstantSpellCount(cid), you can try to change it for something like:
Lua:
function getPlayerInstantSpellCount(cid)
 local p = Player(cid)
 local spells = p:getInstantSpells()
return p ~= nil and #spells
end

But, since you can use player:getInstantSpells() right away, i believe it's redundant.
 
Solution
It says that player:getInstantSpellCount() function doesn't exist.
On a spellbook script you can see that the substitute to this function is player:getInstantSpells(), which creates a table with info about every learnt spell, where it's size is a count.

For function getPlayerInstantSpellCount(cid), you can try to change it for something like:
Lua:
function getPlayerInstantSpellCount(cid)
 local p = Player(cid)
 local spells = p:getInstantSpells()
return p ~= nil and #spells
end

But, since you can use player:getInstantSpells() right away, i believe it's redundant.
Ah okey :) I'll use it as is now. It means a lot that you took your time to explain it to me :)
 
Back
Top