vexler222
Active Member
- Joined
- Apr 22, 2012
- Messages
- 714
- Solutions
- 15
- Reaction score
- 46
Hi, i have error when i try open spellbook but same script working on commands (!spells)
Error
Script from actions
Error
Code:
Lua Script Error: [Scripts Interface]
C:\Users\XX\Desktop\XX\data\scripts\actions\spellbook.lua:callback
...hu\Desktop\XX\data\scripts\actions\spellbook.lua:7: attempt to call method 'level' (a number value)
stack traceback:
[C]: in function 'level'
...hu\Desktop\XX\data\scripts\actions\spellbook.lua:7: in function <...hu\Desktop\XX\data\scripts\actions\spellbook.lua:3>
Lua Script Error: [Scripts Interface]
C:\Users\XX\Desktop\XX\data\scripts\actions\spellbook.lua:callback
...hu\Desktop\XX\data\scripts\actions\spellbook.lua:7: attempt to call method 'level' (a number value)
stack traceback:
[C]: in function 'level'
...hu\Desktop\XX\data\scripts\actions\spellbook.lua:7: in function <...hu\Desktop\XX\data\scripts\actions\spellbook.lua:3>
Script from actions
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
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(item:getId(), text)
return true
end