krithion2424
New Member
- Joined
- Apr 20, 2008
- Messages
- 73
- Reaction score
- 1
I'm trying to change spellbook.lua to display spells by magic level instead of level. All spells work in spell.xml
I am working with theforgottenserver and heres what I have so far:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local count = getPlayerInstantSpellCount(cid)
local text = ""
local t = {}
for i = 0, count - 1 do
local spell = getPlayerInstantSpellInfo(cid, i)
if spell.maglv ~= 0 then
if spell.manapercent > 0 then
spell.mana = spell.manapercent .. "%"
end
t[#t+1] = spell
end
end
table.sort(t, function(a, b) return a.maglv < b.maglv end)
local prevmaglv = -1
for i, spell in ipairs(t) do
local line = ""
if prevmaglv ~= spell.maglv then
if i ~= 1 then
line = "\n"
end
line = line .. "Spells for Magic Level " .. spell.maglv .. "\n"
prevmaglv = spell.maglv
end
text = text .. line .. " " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
end
Player(cid):showTextDialog(item.itemid, text)
return true
end
My error in command prompt is:
Lua Script Error: [Action Interface]
data/actions/scripts/other/spellbook.luanUse
data/actions/scripts/other/spellbook.lua:14: attempt to compare two nil values stack traceback:
[C]: in funtion '__lt'
data/actions/scripts/other/spellbook.lua:14: in function <data/actions/scripts/other/spellbook.lua:1>
I am working with theforgottenserver and heres what I have so far:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local count = getPlayerInstantSpellCount(cid)
local text = ""
local t = {}
for i = 0, count - 1 do
local spell = getPlayerInstantSpellInfo(cid, i)
if spell.maglv ~= 0 then
if spell.manapercent > 0 then
spell.mana = spell.manapercent .. "%"
end
t[#t+1] = spell
end
end
table.sort(t, function(a, b) return a.maglv < b.maglv end)
local prevmaglv = -1
for i, spell in ipairs(t) do
local line = ""
if prevmaglv ~= spell.maglv then
if i ~= 1 then
line = "\n"
end
line = line .. "Spells for Magic Level " .. spell.maglv .. "\n"
prevmaglv = spell.maglv
end
text = text .. line .. " " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
end
Player(cid):showTextDialog(item.itemid, text)
return true
end
My error in command prompt is:
Lua Script Error: [Action Interface]
data/actions/scripts/other/spellbook.luanUse
data/actions/scripts/other/spellbook.lua:14: attempt to compare two nil values stack traceback:
[C]: in funtion '__lt'
data/actions/scripts/other/spellbook.lua:14: in function <data/actions/scripts/other/spellbook.lua:1>