• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Offline Messages

Nostradamus

Member
Joined
Jun 2, 2007
Messages
219
Reaction score
6
Content removed, i don't want to share my knowleagement with a retarded forum staff. Feel free to contact me if you still want that.
 
Last edited:
Actually this works like MSN, you can send message to players who is offline. Oh, almost forgot. I will edit the topic with a thing that i've forgot.
 
oi sorry for bother u, where i have to put this
Code:
--[[
Offline Messages Alpha 0.1
Nostradamus

Messages DB
    playerid
    writer
    text
    read (boolean) [ 1 = read | 0 = new]
    
TODO
    Add an anti-spam thing
    
DETAIL
    Not tested
    
PURPOSE
    Demonstrate a cool way of making talkactions
]]--

Message = inheritsFrom(Talkhandler)

Message:setAttributes({
    env = nil,
    conn = nil
})

Message:registerWordEvent('!show', Message.showMsg) -- !show
Message:registerWordEvent('!send!', Message.sendMsg) -- !send"<player>, <msg>

function Message:onSay(cid, words, param)
    self:callWordEvent(words, cid, param)
    return false -- Needed so server wont send messages to client
end


function Message:showMsg(cid, param)
    local pid = getPlayerGUID(cid)
    local env, con = self:getConnection()
    local cur = assert(con:execute('SELECT * FROM `messages` WHERE `playerid` = ' .. Database:quote(pid) .. ' AND `read` = '1';')
    if (cur:numrows() > 0) then
        local row = cur:fetch({}, "a")
        while (row) do
            doPlayerSendTextMessage(cid, TALKTYPE_PRIVATE, row.writer .. ": " .. row.text)
            row = cur:fetch({},"a")
            assert(con:execute('DELETE FROM `messages` WHERE `playerid` = ' .. Database:quote(pid) .. ';'))
        end
        return true
    end
    conn:close()
    env:close()
    return false
end

function Message:sendMsg(cid, param)
    local separator = string.explode(param, ",")
    local targetId = getPlayerGUIDByName(separator[1])
    if not (isPlayer(targetId) == TRUE) then
        warnPlayer('Can only send messages to offline and exiting players.')
    else
        local env, con = Database:getConnection()
        local writerName = getPlayerName(cid)
        if (separator[2] ~= '' and Database:isPlayer(targetId) == false) then
            sql:execute('INSERT INTO `messages` (`playerid`, `writer`, `text`, `read`) VALUES (' .. targetId .. ', ' .. writerName .. ', ' .. separator[2] .. ', '0')')
            doPlayerSendCancel(cid, 'Message successfuly sent to ' .. separator[1] .. '.') 
            return true
        end
        return false
    end
en

and this
Code:
function onSay(...) 
    return OwnLootBag:new():onSay(...)
end

i put this in data/talkactions/scripts/
Code:
--[[
Offline Messages Alpha 0.1
Nostradamus

Messages DB
    playerid
    writer
    text
    read (boolean) [ 1 = read | 0 = new]
    
TODO
    Add an anti-spam thing
    
DETAIL
    Not tested
    
PURPOSE
    Demonstrate a cool way of making talkactions
]]--

Message = inheritsFrom(Talkhandler)

Message:setAttributes({
    env = nil,
    conn = nil
})

Message:registerWordEvent('!show', Message.showMsg) -- !show
Message:registerWordEvent('!send!', Message.sendMsg) -- !send"<player>, <msg>

function Message:onSay(cid, words, param)
    self:callWordEvent(words, cid, param)
    return false -- Needed so server wont send messages to client
end


function Message:showMsg(cid, param)
    local pid = getPlayerGUID(cid)
    local env, con = self:getConnection()
    local cur = assert(con:execute('SELECT * FROM `messages` WHERE `playerid` = ' .. Database:quote(pid) .. ' AND `read` = '1';')
    if (cur:numrows() > 0) then
        local row = cur:fetch({}, "a")
        while (row) do
            doPlayerSendTextMessage(cid, TALKTYPE_PRIVATE, row.writer .. ": " .. row.text)
            row = cur:fetch({},"a")
            assert(con:execute('DELETE FROM `messages` WHERE `playerid` = ' .. Database:quote(pid) .. ';'))
        end
        return true
    end
    conn:close()
    env:close()
    return false
end

function Message:sendMsg(cid, param)
    local separator = string.explode(param, ",")
    local targetId = getPlayerGUIDByName(separator[1])
    if not (isPlayer(targetId) == TRUE) then
        warnPlayer('Can only send messages to offline and exiting players.')
    else
        local env, con = Database:getConnection()
        local writerName = getPlayerName(cid)
        if (separator[2] ~= '' and Database:isPlayer(targetId) == false) then
            sql:execute('INSERT INTO `messages` (`playerid`, `writer`, `text`, `read`) VALUES (' .. targetId .. ', ' .. writerName .. ', ' .. separator[2] .. ', '0')')
            doPlayerSendCancel(cid, 'Message successfuly sent to ' .. separator[1] .. '.') 
            return true
        end
        return false
    end
end

and talkactions.xml
Code:
	<talkaction words="!send" script="offline msg.lua" />

and this in global.lua
Code:
function onSay(...) 
    return OwnLootBag:new():onSay(...)
end

is anything wrong?please and my server show a error here
The Forgotten Server - Version 0.2rc10 (Mystic Spirit).
A server developed by Talaturen, Kiper, Kornholijo, Jonern, Lithium & slawkens.
Visit our forum for updates, support and resources: http://otland.net/.

>> Loading config
>> Loading RSA key
>> Testing SQL connection... SqLite.
>> Loading bans
>> Loading vocations
>> Loading commands
>> Loading items
>> Loading script systems
Warning: [Event::loadScript] Can not load script. data/talkactions/scripts/offli
ne msg.lua
data/talkactions/scripts/offline msg.lua:40: ')' expected near '1'

>> Loading monsters
>> Loading quests
>> Loading outfits
>> Loading admin protocol config
>> Loading experience stages
>> Checking world type... PVP
>> Loading map
> Map size: 1024x1024.
> Map loading time: 4.244 seconds.
>> Loading raids
>> All modules has been loaded, server starting up...
>> Mystic Ot Server Online!
 
Last edited:
#up
ye, "GeKirAh" is sux user and posting many arleady posting threads. Nostra is coder of this script and first post here this script.:)
 
Back
Top