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:
and i already had this for string.explode :
and the talkaction script :
and lastly this in login.lua :
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 )
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
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