• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua data/chatchannels/scripts/spells/lua

Jfrye

Mapper, trying to learn scripting
Joined
Jan 8, 2009
Messages
366
Solutions
5
Reaction score
86
Location
Mexico Missouri
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.

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
 
why use addevent at all?
either way passing userdata through addevent is unsafe because the player might not exist when the function executes
so you have to pass the creature id and reconstruct player with cid and check if it exists or not, if it does continue the rest of the function
if it doesn't exist you use return to stop execution
local player = Player(cid)
if not player then
return
end
 
I dont even know where this came from? I guess it was in the server when I downloaded it a couple years ago. Is it safe to delete the channel, or what?
 
Back
Top