Jfrye
Mapper, trying to learn scripting
Hey all, Im getting a console error regarding the title above. Im not sure how to fix it. Does anyone know how to fix this so I can get rid of this annoying pop up on the console?
EDIT: This error happens everytime a player logs in.
data/chatchannels/scripts/spells.lua
EDIT: This error happens everytime a player logs in.
Code:
Lua Script Error: [Chat interface]
data/chatchannels/scripts/spells.lua:onJoin
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
[C]: in fucntion 'addEvent'
data/chatchannels/scripts/spells.lua:49: in function <data/chatchannels/scrips/spells.lua:48>
Lua Script Error: [Main Interface]
in a timer event called from:
(unknown scriptfile)
data/chatchannels/scripts/spells.lua:35: attempt to index local 'player' (a number value)
stack traceback:
[C]: in function '_index'
data/chatchannels/scripts/spells.lua:35: in function <data/chatchannels/scripts/spells.lua:12>
data/chatchannels/scripts/spells.lua
Code:
local CHANNEL_CHARACTER = 4
local tier =
{
[0] = "[ Apprentice ]",
[1] = "[ Journeyman ]",
[2] = "[ Adept ]",
[3] = "[ Expert ]",
[4] = "[ Master ]",
[5] = "[ Grandmaster ]"
}
local function listSpells(player)
local count = getPlayerInstantSpellCount(player)
local text = ""
local t = {}
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
t[#t+1] = spell
end
end
table.sort(t, function(a, b) return a.level < b.level end)
local 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 .. "\nSpells for Level " .. spell.level .. "\n"
prevLevel = spell.level
player:sendChannelMessage(cid, line, TALKTYPE_CHANNEL_O, CHANNEL_CHARACTER)
end
if player:getStorageValue(SPELL_WORDS[spell.words]) > 0 then
local index = player:getStorageValue(SPELL_WORDS[spell.words])
text = " " .. spell.words .. " " .. tier[index] .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
else
text = " " .. spell.words .. " " .. tier[0] .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
end
player:sendChannelMessage(cid, text, TALKTYPE_CHANNEL_Y, CHANNEL_CHARACTER)
end
end
function onJoin(player)
addEvent(listSpells, 100, player)
return true
end
function onSpeak(player, type, message)
player:sendCancelMessage("You may not speak in this chat.")
return false
end