freaked1
Active Member
A little problem with talkaction !spells.
I don't know if the problem lies within the compat.lua or the script itself.
Error message:
Function in compat.lua:
talkactions/scripts/spells.lua
Thanks in advance!
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!