• 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/global.lua:55: attempt to get length of local 'str' (a boolean value)

  • Thread starter Thread starter Shadow_
  • Start date Start date
S

Shadow_

Guest
Hello guys as always when i try to use 0.4 scripts in my 1.2 tfs it always works except this i want to add offline msg script so i searched and i found a script but it didn't work for me.
i added those to my global.lua
1:
LUA:
messageSep = "<msgSep>" --used on database
senderSep = "<sendSep>" --used on database
function getPlayerMessages(name)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    local messages = {}
    local x
    if query ~= -1 then
        x = result.getDataInt("messages")
        x = string.explode(x, messageSep)
        for i = 1, table.maxn(x) do
            table.insert(messages, x[i])
        end
    end
    return messages
end
function doPlayerAddMessage(name, message, sender)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    if query ~= -1 then
        local m = result.getDataInt("messages")
        m = m .. (m ~= "" and messageSep or "") .. message .. senderSep .. getCreatureName(sender) .. senderSep .. os.date()
        local newquery = db.storeQuery("update players set messages = " .. db.escapeString(m) .. " where name = " .. db.escapeString(name) .. ";")
        if not newquery then
            return false
        end
    else
        return false
    end
    return true
end
function doPlayerRemoveMessages(name)
    local query = db.storeQuery("update players set messages = '' where name = " .. db.escapeString(name) .. ";")
    if not query then
        return false
    end
    return true
end
function getPlayerMessagesLenght(name)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    if query ~= -1 then
        return string.len(result.getDataInt("messages"))
    end
    return -1
end
and i already had this for string.explode :
LUA:
function string.trim(str)
    -- Function by Colandus
    return (str:gsub("^%s*(.-)%s*$", "%1"))
end
function string.explode(str, sep, limit)
    -- Function by Colandus
    if limit and type(limit) ~= 'number' then
        error("string.explode: limit must be a number", 2)
    end
    if #sep == 0 or #str == 0 then return end
   local pos, i, t = 1, 1, {}
    for s, e in function() return str:find(sep, pos) end do
        table.insert(t, str:sub(pos, s-1):trim())
        pos = e + 1
        i = i + 1
        if limit and i == limit then break end
    end
    table.insert(t, str:sub(pos):trim())
    return t
end

and the talkaction script :
LUA:
local maxMessageLenght = 1500
local deleteMessageAsRead = false
function onSay(cid, words, param, channel)
    local msg = getPlayerMessages(getCreatureName(cid))
    if words == "!msg" then
        param = string.explode(param, ";")
        if table.maxn(param) < 2 then
            return doPlayerSendCancel(cid, "No player specified.")
        end
        if param[2]:lower() == getCreatureName(cid):lower() then
            return doPlayerSendCancel(cid, "You cannot send messages to yourself.")
        end
        if string.len(param[1]) > maxMessageLenght then
            return doPlayerSendCancel(cid, "Message is too long, only " .. maxMessageLenght .. " characters are admitted.")
        end
        if playerExists(param[2]) and getPlayerMessagesLenght(param[2]) >= 10000 then
            return doPlayerSendCancel(cid, "You cannot send more messages to " .. param[2] .. " until he/she clean his/her inbox.")
        end
        if doPlayerAddMessage(param[2], param[1], cid) then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Message successfully sended to " .. param[2] .. ".")
            if getPlayerByNameWildcard(param[2]) then
                doPlayerSendTextMessage(getPlayerByNameWildcard(param[2]), MESSAGE_INFO_DESCR, "You have received a new private message.")
            end
        else
            doPlayerSendCancel(cid, "Player with that name does not exists.")
        end
    elseif words == "!read" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Reading " .. table.maxn(msg) .. " message(s)" .. (not deleteMessageAsRead and getPlayerMessagesLenght(getCreatureName(cid)) >= 10000 and ", your inbox is full, you should delete messages or you won't receive more messages" or "") .. ".")
        if table.maxn(msg) > 0 then
            for i = 1, table.maxn(msg) do
                local t = string.explode(msg[i], senderSep)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Message from " .. t[2] .. " at " .. (t[3] or "No Date") .. " > " .. t[1])
            end
        end
        if deleteMessageAsRead and table.maxn(msg) > 0 then
            if doPlayerRemoveMessages(getCreatureName(cid)) then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The following message(s) have been deleted.")
            end
        end
    elseif words == "!delete" then
        local limit = (tonumber(param) and tonumber(param) > 0 and tonumber(param) <= table.maxn(msg) and tonumber(param) or table.maxn(msg))
        if doPlayerRemoveMessages(getCreatureName(cid), limit) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have deleted " .. limit .. " message(s).")
        end
    end
    return true
end

and lastly this in login.lua :
LUA:
    local msg = getPlayerMessages(getCreatureName(cid))
    if table.maxn(msg) > 0 then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have " .. table.maxn(msg) .. " new message(s).")
    end
can anybody help me ? iam using tfs 1.2 ( the script is 0.4 i know but 0.4 scripts usually works for 1.2 )
 
Solution
I'll assume the script you posted above is the one which is throwing these errors? I got a little clever and wrote you a universal table function.
LUA:
-- table.length(t, c[, l])
function table.length(t, c, l)
    local v = false
    if t and type(t) == "table" then
        if c then
            local n = table.maxn(t)
            -- return just the size
            if c == "size" then
                return n
            end
            -- return the original table
            if c == "table" then
                return t
            end
            -- comparisons
            -- less than
            if c == "<" then
                v = n < l
            -- less than or equal to
            elseif c == "<=" then
                v = n <=...
change
LUA:
return string.len(result.getDataInt("messages"))
to
LUA:
return string.len(result.getDataInt(query, "messages"))

you have more than 1 of those errors in your code, result.getDataInt(queryid, "column_name")
you're omitting the query id parameter, you can't get a data int from a column if you don't provide the query result in that function
 
Last edited:
change
LUA:
return string.len(result.getDataInt("messages"))
to
LUA:
return string.len(result.getDataInt(query, "messages"))

you have more than 1 of those errors in your code, result.getDataInt(queryid, "column_name")
you're omitting the query id parameter, you can't get a data int from a column if you don't provide the query result in that function
before editting it it was like this
LUA:
        return string.len(query:getDataString("messages"))
and i changed it to
LUA:
return string.len(result.getDataInt("messages"))

+ i tried yours i got this
Code:
data/global.lua:55: attempt to get length of local 'str' (a boolean value)
on login and when i delete the login lines and try the command same error with the command files
 
before editting it it was like this
LUA:
        return string.len(query:getDataString("messages"))
and i changed it to
LUA:
return string.len(result.getDataInt("messages"))

+ i tried yours i got this
Code:
data/global.lua:55: attempt to get length of local 'str' (a boolean value)
on login and when i delete the login lines and try the command same error with the command files
which script is the error actually coming from?
i'm not a wizard, i don't feel like sitting here guessing if you don't give the full error
 
which script is the error actually coming from?
i'm not a wizard, i don't feel like sitting here guessing if you don't give the full error
for the 2 scripts login and command as i told you
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/login.lua:onLogin
data/global.lua:55: attempt to get length of local 'str' (a boolean value)
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/offlinemsg.lua:onSay
data/global.lua:55: attempt to get length of local 'str' (a boolean value)
 
LUA:
function string.explode(str, sep, limit)
    -- Function by Colandus
    if limit and type(limit) ~= 'number' then
        error("string.explode: limit must be a number", 2)
    end
    if #sep == 0 or #str == 0 then return end
   local pos, i, t = 1, 1, {}
    for s, e in function() return str:find(sep, pos) end do
        table.insert(t, str:sub(pos, s-1):trim())
        pos = e + 1
        i = i + 1
        if limit and i == limit then break end
    end
    table.insert(t, str:sub(pos):trim())
    return t
end

I just did a simple ctrl+f on code you provided and the only place that looks for the length of str is this:
LUA:
if #sep == 0 or #str == 0 then return end
The hash # in front of str returns the size of str if its a string, char or table.
So to trouble shoot the issue with the error you have to account for the data str might be holding.

This may not solve the entire problem you but it may resolve the current error.
LUA:
function string.explode(str, sep, limit)
    -- Function by Colandus
    if limit and type(limit) ~= 'number' then
        error("string.explode: limit must be a number", 2)
    end
    -- lets make sure str is a string
    if type(str) ~= "string" then
        return
    end
    if #sep == 0 or #str == 0 then
        return
    end
    local pos, i, t = 1, 1, {}
    for s, e in function() return str:find(sep, pos) end do
        table.insert(t, str:sub(pos, s-1):trim())
        pos = e + 1
        i = i + 1
        if limit and i == limit then break end
    end
    table.insert(t, str:sub(pos):trim())
    return t
end

We know that str is a string not just because it's labeled "str" but because of the methods that are applied to it later on in the script such as find, sub and so forth.
 
LUA:
function string.explode(str, sep, limit)
    -- Function by Colandus
    if limit and type(limit) ~= 'number' then
        error("string.explode: limit must be a number", 2)
    end
    if #sep == 0 or #str == 0 then return end
   local pos, i, t = 1, 1, {}
    for s, e in function() return str:find(sep, pos) end do
        table.insert(t, str:sub(pos, s-1):trim())
        pos = e + 1
        i = i + 1
        if limit and i == limit then break end
    end
    table.insert(t, str:sub(pos):trim())
    return t
end

I just did a simple ctrl+f on code you provided and the only place that looks for the length of str is this:
LUA:
if #sep == 0 or #str == 0 then return end
The hash # in front of str returns the size of str if its a string, char or table.
So to trouble shoot the issue with the error you have to account for the data str might be holding.

This may not solve the entire problem you but it may resolve the current error.
LUA:
function string.explode(str, sep, limit)
    -- Function by Colandus
    if limit and type(limit) ~= 'number' then
        error("string.explode: limit must be a number", 2)
    end
    -- lets make sure str is a string
    if type(str) ~= "string" then
        return
    end
    if #sep == 0 or #str == 0 then
        return
    end
    local pos, i, t = 1, 1, {}
    for s, e in function() return str:find(sep, pos) end do
        table.insert(t, str:sub(pos, s-1):trim())
        pos = e + 1
        i = i + 1
        if limit and i == limit then break end
    end
    table.insert(t, str:sub(pos):trim())
    return t
end

We know that str is a string not just because it's labeled "str" but because of the methods that are applied to it later on in the script such as find, sub and so forth.

yes now i get that error :
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/login.lua:onLogin
data/global.lua:492: bad argument #1 to 'maxn' (table expected, got nil)

from those lines :
LUA:
messageSep = "<msgSep>" --used on database
senderSep = "<sendSep>" --used on database
function getPlayerMessages(name)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    local messages = {}
    local x
    if query ~= -1 then
        x = result.getDataInt("messages")
        x = string.explode(x, messageSep)
        for i = 1, table.maxn(x) do
            table.insert(messages, x[i])
        end
    end
    return messages
end
function doPlayerAddMessage(name, message, sender)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    if query ~= -1 then
        local m = result.getDataInt("messages")
        m = m .. (m ~= "" and messageSep or "") .. message .. senderSep .. getCreatureName(sender) .. senderSep .. os.date()
        local newquery = db.storeQuery("update players set messages = " .. db.escapeString(m) .. " where name = " .. db.escapeString(name) .. ";")
        if not newquery then
            return false
        end
    else
        return false
    end
    return true
end
function doPlayerRemoveMessages(name)
    local query = db.storeQuery("update players set messages = '' where name = " .. db.escapeString(name) .. ";")
    if not query then
        return false
    end
    return true
end
function getPlayerMessagesLenght(name)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    if query ~= -1 then
        return string.len(result.getDataInt("messages"))
    end
    return -1
end
 
This is lines 485 to 497
LUA:
function getPlayerMessages(name)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    local messages = {}
    local x
    if query ~= -1 then
        x = (result.getDataString(query, 'messages'))
        x = string.explode(x, messageSep)
        for i = 1, table.maxn(x) do
            table.insert(messages, x[i])
        end
    end
    return messages
end
and this is line 492
LUA:
for i = 1, table.maxn(x) do
So this error says that max is expecting a table but instead its getting nil. This function in general is expecting a table to be passed to it from x as if x is guaranteed to contain a value.
Code:
data/global.lua:492: bad argument #1 to 'maxn' (table expected, got nil)
Even an empty table contains a value print(table.maxn({})) would print 0.
So lets wrap this for loop with an if statement
LUA:
function getPlayerMessages(name)
    local query = db.storeQuery("select messages from players where name = " .. db.escapeString(name) .. ";")
    local messages = {}
    local x = nil
    if query ~= -1 then
        x = (result.getDataString(query, 'messages'))
        x = string.explode(x, messageSep)
        -- does x contain a value and if it does is that value a table?
        if x and type(x) == "table" then
            -- if x is a table but has nothing in it then the for loop won't even execute
            for i = 1, table.maxn(x) do
                table.insert(messages, x[i])
            end
        end
    end
    return messages
end
 
the script is not working but giving those errors in console , and give me bad argument when i say it like this !msg without anynames and if i said names it sends error here is the errors :
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/offlinemsg.lua:onSay
data/talkactions/scripts/offlinemsg.lua:9: bad argument #1 to 'maxn' (table expected, got nil)
[Error - mysql_store_result] Query: update players set messages = '' where name = 'Admin Carcoo';
Message:
[Error - mysql_store_result] Query: update players set messages = '' where name = 'Admin Carcoo';
Message:

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/offlinemsg.lua:onSay
data/talkactions/scripts/offlinemsg.lua:18: attempt to call global 'playerExists' (a nil value)
[Error - mysql_store_result] Query: update players set messages = '' where name = 'Admin Carcoo';
Message:
[Error - mysql_store_result] Query: update players set messages = 'carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:04:48 2018' where name = 'carcoo';
Message:
[Error - mysql_store_result] Query: update players set messages = 'carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:04:48 2018<msgSep>carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:09:10 2018' where name = 'carcoo';
Message:
[Error - mysql_store_result] Query: update players set messages = '' where name = 'Admin Carcoo';
Message:
[Error - mysql_store_result] Query: UPDATE `players` SET `messages` = '' WHERE `name` = 'Admin Carcoo';
Message:
[Error - mysql_store_result] Query: update players set messages = 'carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:04:48 2018<msgSep>carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:09:10 2018<msgSep>carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:09:59 2018' where name = 'carcoo';
Message:
Admin Carcoo has logged out.
Admin Carcoo has logged in.
[Error - mysql_store_result] Query: update players set messages = 'carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:04:48 2018<msgSep>carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:09:10 2018<msgSep>carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:09:59 2018<msgSep>hello<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:11:12 2018' where name = 'Carcoo';
Message:
[Error - mysql_store_result] Query: UPDATE `players` SET `messages` = 'carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:04:48 2018<msgSep>carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:09:10 2018<msgSep>carcoo<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:09:59 2018<msgSep>hello<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:11:12 2018<msgSep>hello<sendSep>Admin Carcoo<sendSep>Fri Jul 20 06:13:32 2018' WHERE `name` = 'Carcoo';
Message:

and i have deleted playerExists to test the script but i got those errors but its working and it says that the player does not exists when i try to send msg
 
I'll assume the script you posted above is the one which is throwing these errors? I got a little clever and wrote you a universal table function.
LUA:
-- table.length(t, c[, l])
function table.length(t, c, l)
    local v = false
    if t and type(t) == "table" then
        if c then
            local n = table.maxn(t)
            -- return just the size
            if c == "size" then
                return n
            end
            -- return the original table
            if c == "table" then
                return t
            end
            -- comparisons
            -- less than
            if c == "<" then
                v = n < l
            -- less than or equal to
            elseif c == "<=" then
                v = n <= l
            -- greater than
            elseif c == ">" then
                v = n > l
            -- greater than or equal to
            elseif c == ">=" then
                v = n >= l
            -- equal to
            elseif c == "==" then
                v = n == l
            -- not equal
            elseif c == "~=" then
                v = n ~= l
            end
        end
    end
    return v
end

local maxMessageLenght = 1500
local deleteMessageAsRead = false
function onSay(cid, words, param, channel)
    local msg = getPlayerMessages(getCreatureName(cid))
    if words == "!msg" then
        param = string.explode(param, ";")
        if table.length(param, "<", 2) then
            return doPlayerSendCancel(cid, "No player specified.")
        end
        if param[2]:lower() == getCreatureName(cid):lower() then
            return doPlayerSendCancel(cid, "You cannot send messages to yourself.")
        end
        if string.len(param[1]) > maxMessageLenght then
            return doPlayerSendCancel(cid, "Message is too long, only " .. maxMessageLenght .. " characters are admitted.")
        end
        if playerExists(param[2]) and getPlayerMessagesLenght(param[2]) >= 10000 then
            return doPlayerSendCancel(cid, "You cannot send more messages to " .. param[2] .. " until he/she clean his/her inbox.")
        end
        if doPlayerAddMessage(param[2], param[1], cid) then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Message successfully sended to " .. param[2] .. ".")
            if getPlayerByNameWildcard(param[2]) then
                doPlayerSendTextMessage(getPlayerByNameWildcard(param[2]), MESSAGE_INFO_DESCR, "You have received a new private message.")
            end
        else
            doPlayerSendCancel(cid, "Player with that name does not exists.")
        end
    elseif words == "!read" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Reading " .. table.length(msg, "size") .. " message(s)" .. (not deleteMessageAsRead and getPlayerMessagesLenght(getCreatureName(cid)) >= 10000 and ", your inbox is full, you should delete messages or you won't receive more messages" or "") .. ".")
        if table.length(msg, ">", 0) then
            for i = 1, table.length(msg, "size") do
                local t = string.explode(msg[i], senderSep)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Message from " .. t[2] .. " at " .. (t[3] or "No Date") .. " > " .. t[1])
            end
        end
        if deleteMessageAsRead and table.length(msg, ">". 0) then
            if doPlayerRemoveMessages(getCreatureName(cid)) then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The following message(s) have been deleted.")
            end
        end
    elseif words == "!delete" then
        local limit = (tonumber(param) and tonumber(param) > 0 and table.length(msg, "<=", tonumber(param)) and tonumber(param) or table.length(msg, "size"))
        if doPlayerRemoveMessages(getCreatureName(cid), limit) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have deleted " .. limit .. " message(s).")
        end
    end
    return true
end
 
Solution
I'll assume the script you posted above is the one which is throwing these errors? I got a little clever and wrote you a universal table function.
LUA:
-- table.length(t, c[, l])
function table.length(t, c, l)
    local v = false
    if t and type(t) == "table" then
        if c then
            local n = table.maxn(t)
            -- return just the size
            if c == "size" then
                return n
            end
            -- return the original table
            if c == "table" then
                return t
            end
            -- comparisons
            -- less than
            if c == "<" then
                v = n < l
            -- less than or equal to
            elseif c == "<=" then
                v = n <= l
            -- greater than
            elseif c == ">" then
                v = n > l
            -- greater than or equal to
            elseif c == ">=" then
                v = n >= l
            -- equal to
            elseif c == "==" then
                v = n == l
            -- not equal
            elseif c == "~=" then
                v = n ~= l
            end
        end
    end
    return v
end

local maxMessageLenght = 1500
local deleteMessageAsRead = false
function onSay(cid, words, param, channel)
    local msg = getPlayerMessages(getCreatureName(cid))
    if words == "!msg" then
        param = string.explode(param, ";")
        if table.length(param, "<", 2) then
            return doPlayerSendCancel(cid, "No player specified.")
        end
        if param[2]:lower() == getCreatureName(cid):lower() then
            return doPlayerSendCancel(cid, "You cannot send messages to yourself.")
        end
        if string.len(param[1]) > maxMessageLenght then
            return doPlayerSendCancel(cid, "Message is too long, only " .. maxMessageLenght .. " characters are admitted.")
        end
        if playerExists(param[2]) and getPlayerMessagesLenght(param[2]) >= 10000 then
            return doPlayerSendCancel(cid, "You cannot send more messages to " .. param[2] .. " until he/she clean his/her inbox.")
        end
        if doPlayerAddMessage(param[2], param[1], cid) then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Message successfully sended to " .. param[2] .. ".")
            if getPlayerByNameWildcard(param[2]) then
                doPlayerSendTextMessage(getPlayerByNameWildcard(param[2]), MESSAGE_INFO_DESCR, "You have received a new private message.")
            end
        else
            doPlayerSendCancel(cid, "Player with that name does not exists.")
        end
    elseif words == "!read" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Reading " .. table.length(msg, "size") .. " message(s)" .. (not deleteMessageAsRead and getPlayerMessagesLenght(getCreatureName(cid)) >= 10000 and ", your inbox is full, you should delete messages or you won't receive more messages" or "") .. ".")
        if table.length(msg, ">", 0) then
            for i = 1, table.length(msg, "size") do
                local t = string.explode(msg[i], senderSep)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Message from " .. t[2] .. " at " .. (t[3] or "No Date") .. " > " .. t[1])
            end
        end
        if deleteMessageAsRead and table.length(msg, ">". 0) then
            if doPlayerRemoveMessages(getCreatureName(cid)) then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The following message(s) have been deleted.")
            end
        end
    elseif words == "!delete" then
        local limit = (tonumber(param) and tonumber(param) > 0 and table.length(msg, "<=", tonumber(param)) and tonumber(param) or table.length(msg, "size"))
        if doPlayerRemoveMessages(getCreatureName(cid), limit) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have deleted " .. limit .. " message(s).")
        end
    end
    return true
end
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/offlinemsg.lua:onSay
data/talkactions/scripts/offlinemsg.lua:55: attempt to call global 'playerExists' (a nil value)

and on login msg is not working but no errors
 
I don't know I am still learning myself
thank you for this step anyway :D
Code:
[Error - mysql_store_result] Query: UPDATE `players` SET `messages` = '' WHERE `name` = 'Admin Carcoo'
Message:
this is the last error guys idk why it appears ( script working right but wothout sending messages but it deletes the messages and reading and sending but when i try to send it says this player does not exists but he receives it and onlogin nothing appears and when i say delete the msg is not sent which it should say You have delete XX messages. thats all !read working good @Vulcan_ any ideas for this ?
 
Last edited by a moderator:
Solved .
Add this in global.lua

LUA:
messageSep = "<msgSep>" --used on database
senderSep = "<sendSep>" --used on database
function getPlayerMessages(name)
    local query = db.storeQuery("SELECT `messages` FROM `players` WHERE `name` = " .. db.escapeString(name))
    local messages = {}
    local x = nil
    if query ~= -1 then
        x = (result.getDataString(query, 'messages'))
        x = string.explode(x, messageSep)
        -- does x contain a value and if it does is that value a table?
        if x and type(x) == "table" then
            -- if x is a table but has nothing in it then the for loop won't even execute
            for i = 1, table.maxn(x) do
                table.insert(messages, x[i])
            end
        end
    end
    return messages
end
function doPlayerAddMessage(name, message, sender)
    local query = db.storeQuery("SELECT `messages` FROM `players` WHERE `name` = " .. db.escapeString(name))
    if query ~= -1 then
        local m = (result.getDataString(query, 'messages'))
        m = m .. (m ~= "" and messageSep or "") .. message .. senderSep .. getCreatureName(sender) .. senderSep .. os.date()
        local newquery = db.query("UPDATE `players` SET `messages` = " .. db.escapeString(m) .. " WHERE `name` = " .. db.escapeString(name))
        if not newquery then
            return false
        end
    else
        return false
    end
    return true
end
function doPlayerRemoveMessages(name, limit)
    local query = db.storeQuery("SELECT `messages` FROM `players` WHERE `name` = " .. db.escapeString(name))
    local messages = {}
    local x, y
    local t, tt = "", ""
    if query ~= -1 then
        x, y = (result.getDataString(query, 'messages')), (result.getDataString(query, 'messages'))
        x = string.explode(x, messageSep)
        for i = 1, limit do
            t = t .. x[i]
        end
        tt = string.sub(y, string.len(t) + (string.len(messageSep) * limit) + 1, string.len(y))
        local newquery = db.query("UPDATE `players` SET `messages` = " .. db.escapeString(tt) .. " WHERE `name` = " .. db.escapeString(name))
        if not newquery then
            return false
        end
    end
    return true
end
function getPlayerMessagesLenght(name)
    local query = db.storeQuery("SELECT `messages` FROM `players` WHERE `name` = " .. db.escapeString(name))
    if query ~= -1 then
        return string.len(result.getDataString(query, 'messages'))
    end
    return -1
end

function playerExists(name)
   return (getPlayerGUIDByName(name) ~= 0)
end
 
Back
Top