Ir para conteúdo
Entre para seguir isso  
Socket

Ses 1.0

Recommended Posts

Socket    0
Socket

..:: [S]ocket's [E]mails [S]ystem ::..

Autor: Socket

 

 

Servidor Testado: TFS 0.3.5 (Crying Damson) - 8.5

 

 

Versão: 2.0

 

 

Comentário: Sistema testado em luaSql (Comunicação da linguagem Lua com a SQL: MySql e SqLite) e em StorageValues.

 

 

Talkaction:

 

[spoiler=Talkaction]

Em data\talkactions\scripts crie um arquivo chamado email.lua e adcione isto em seu conteúdo:

 

local money = 5000

function onSay(cid, words, param)
local emails = {}
 if words == '!check' then
   if param == '' then
     if getInt(getPlayerName(cid)) == 0 then
       doPlayerSendCancel(cid,'You don\'t have any emails.')
       return true
     end
     doReloadInfo(RELOAD_TALKACTIONS)
     doPlayerPopupFYI(cid, 'This is the list of your emails:\n'.. getPlayerName(cid):getList())
     return true
   elseif param:match('%d+') ~= nil and param:match('%a+') == nil then
     if getPlayerName(cid):getByNumber(tonumber(param:match('%d+'))) ~= nil then
       doReloadInfo(RELOAD_TALKACTIONS)
       doPlayerPopupFYI(cid, getPlayerName(cid):getByNumber(tonumber(param:match('%d+'))))
       return true
     else
       doReloadInfo(RELOAD_TALKACTIONS)
       doPlayerSendCancel(cid,'Email not found.')
       return true
     end
   elseif param:match('%a+') ~= nil then
     l = 1
     for i in param:gmatch('%a+') do
       s = (s or '') .. (l == 1 and '' or ' ') .. i
       l = l + 1
     end
     l = 1
     if s:lower() == 'all' then
       doReloadInfo(RELOAD_TALKACTIONS)
       for i in ((getPlayerName(cid)):file('load')):gmatch('%b{}') do
         doPlayerPopupFYI(cid,i:sub(2,-2))
       end 
       doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'Here are your emails.')
       return true
     else
       if getPlayerName(cid):getBySubject(s) ~= nil then
         doReloadInfo(RELOAD_TALKACTIONS)
         doPlayerPopupFYI(cid,getPlayerName(cid):getBySubject(s))
         return true
       else
         doReloadInfo(RELOAD_TALKACTIONS)
         doPlayerSendCancel(cid,'Email not found.')
       end
     end    
   end 
 elseif words == '!buy' then
   if doPlayerRemoveMoney(cid, money) then
     item = doPlayerAddItem(cid,getItemIdByName('Letter'))
     doSetItemActionId(item, 15789)
     doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'Here are your \'magic\' letter.')
     return true
   else
     doPlayerSendCancel(cid,'You don\'t have enought money.')
     return true
   end
 elseif words == '!delete' then
   (getPlayerName(cid)):file('set','')
   setInt(getPlayerName(cid),0)
   doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'You have been deleted your emails.')
   return true
 elseif words == '!help' then
   doPlayerPopupFYI(cid,'Hello, this is the Socket\'s email sytem. To use it follow the instructions below:\n!check -> Use it to see one list of your emails: number: sender [subject].\n-- !check number - Use it to check some e-mail with that number.\n-- !check subject - Use it to check some e-mail with that subject.\n-- !check all - Use it to see all your e-mails.\n!buy -> Use it to buy a \'magic\' letter for '.. money ..' gold coins.\n!delete -> Use it to delete your emails.\n!help -> Use it to see this again.\nAnd to send a email with a \'magic\' letter follow the pattern below:\n--------\nplayerName\nsubject\nmessage\n--------')
   return true
 end
end           
end           

Configuração:

local money = 5000

Configure o preço da carta 'mágica'.

 

 

[spoiler=Creature Script]

Crie um arquivo em data\creaturescripts\scripts chamado text.lua e adcione isto em seu conteúdo:

 

function onTextEdit(cid, item, newText)
local name = newText:match('(.-)\n')
local assunto = newText:match((name or '')..'\n(.-)\n')
local txt = newText:match((assunto or '')..'\n(.+)')
local t = string.explode(name,';')
 if item.actionid == 15789 then
   if assunto == nil and txt == nil and name == nil then
     doPlayerSendCancel(cid,'Enter a subject and message.')
   end 
   for i = 1, #t do
     if not getPlayerGUIDByName(t[i]) then
       doPlayerSendCancel(cid,'Player '.. t[i] .. ' don\'t exists.')
       return true
     end
   end
   if getPlayerName(cid):sendEmail(t,(assunto or ''),(txt or '')) then
     doPlayerPopupFYI(cid,'Email sent successfully.')
   end
   for i = 1, #t do
     setInt(t[i],getInt(t[i])+1)
     if isOnline(t[i]) then
       doPlayerSendTextMessage(getPlayerByName(t[i]),MESSAGE_STATUS_CONSOLE_BLUE,'You received an email from '.. getPlayerName(cid) ..'.')
     end
   end 
 end
 return true
end

 

[spoiler=Lib]

Em data\lib crie um arquivo chamado email.lua e acione isto em seu conteúdo:

-- ALTER TABLE `players` ADD `emails` INT NOT NULL DEFAULT '0' AFTER `name` 

local dir = --[[getDataDir()..]]'C:\\Documents and Settings\\cezarfilho\\Desktop\\Script Live By Colex\\cryingdamson5-gui\\data\\emails'
local tipo = '.txt'
local config = 'SQL' -- Save on 'SQL' or 'Storage Values' 

function string:getDir()
 return dir .. '\\'.. self .. tipo
end

function string:file(type,txt)
 if type == 'add' then
   file = io.open(self:getDir(),'a+')
   file:write(txt)
   file:close()
 elseif type == 'load' then
   i = 1
   for l in io.lines(self:getDir()) do
     str = (str or '') .. (i == 1 and '' or '\n') .. l
     i = i + 1
   end
   i = 1
   return str
 elseif type == 'set' then
   file = io.open(self:getDir(),'w')
   file:write()
   file:close()
 end
end

function string:getTop(player,assunto)
local msg = 'Sender: '.. self ..'\nRecipient: '.. table.concat(player,'; ') ..'\nDate: '.. os.date('%d/%m/%Y') ..'\nSubject: '.. assunto ..'\n'
 return msg
end 

function string:sendEmail(player,assunto,msg)
txt = '{' .. self:getTop(player,assunto) .. msg .. '}'
 for i, v in ipairs(player) do
   v:file('add','\n'.. txt)
 end
 return true
end

function isOnline(name) -- by mock
local players = getOnlinePlayers()
name = string.lower(name)
   for i, player in ipairs(players) do
   player = string.lower(player)
   if name == player then
  return TRUE 
   end 
   end
   return FALSE
end

function getInt(name)
 if config:lower() == 'sql' then
   local query = db.getResult("SELECT `emails` FROM `players` WHERE `name` = '".. name .."';")
   return query:getDataInt('emails')
 elseif config:lower() == 'storage values' then
   return getPlayerStorageValue(getPlayerByName(name),10574)
 end
end

function setInt(name,var)
 if config:lower() == 'sql' then
   local query = db.executeQuery("UPDATE `players` SET `emails` = '".. var .."' WHERE `name` = '".. name .."';")
   return query
 elseif config:lower() == 'storage values' then
   return setPlayerStorageValue(getPlayerByName(name),10574,var)
 end
end

function string:EgetTop(player,assunto)
local msg = 'Sender: '.. player ..'\nRecipient: '.. self ..'\nDate: '.. os.date('%d/%m/%Y') ..'\nSubject: '.. assunto ..'\n'
 return msg
end 

function string:EsendEmail(player,assunto,msg)
txt = '{' .. self:EgetTop(player,assunto) .. msg .. '}'
 player:file('add','\n'.. txt)
 return true
end

function sendEmailForAll(player,assunto,msg)
local players = getOnlinePlayers()
 for i, v in ipairs(players) do
   player:EsendEmail(v,assunto,msg)
   doPlayerSendTextMessage(getPlayerByName(v),MESSAGE_STATUS_CONSOLE_BLUE,'You received an email from '.. player ..'.')
   setInt(v,getInt(v) + 1)
 end
end

function string:getList()
p = 1
 for i,v,t in ((self):file('load')):gmatch('Sender: (.-)\nRecipient: (.-)\nSubject: (.-)\n') do
   s = (s or '') .. '\n' .. p..': '..i..' ['..t..']'
   p = p +1
 end
 p = 1
 return s
end

function string:getByNumber(n)
local Q = {}
local p = 1
 for i in (self):file('load'):gmatch('%b{}') do
   for v, t, q, k in i:gmatch('Sender: (.-)\nRecipient: (.-)\nSubject: (.-)\n(.+)') do
     table.insert(Q,p,'Sender: '.. v .. '\nRecipient: '.. t ..'\nSubject: '.. q ..'\n'.. k:sub(1,-2))
     p = p + 1
   end
 end
 p = 1
 return Q[n]
end 

function string:getBySubject(n)
local Q = {}
 for i in (self):file('load'):gmatch('%b{}') do
   for v, t, q, k in i:gmatch('Sender: (.-)\nRecipient: (.-)\nSubject: (.-)\n(.+)') do
     Q[q:lower()] = 'Sender: '.. v .. '\nRecipient: '.. t ..'\nSubject: '.. q ..'\n'.. k:sub(1,-2)
   end
 end
 return Q[n:lower()]
end

Configure:

local config = 'SQL'

'SQL' para gravar a quantidade e emails em databases (aconselhado a quem já tem conhecimento em MySql ou SqLite), ou 'Storage Values' para gravar em storage values(aconselhado a iniciantes).

Obs: Pra quem escolher 'SQL' terá uma etapa a mais na instalação.

 

 

 

 

Instalação:

 

[spoiler=Instalação]

Em data\talkactions abra o arquivo talkactions.xml e adcione isto:

<talkaction words="!buy" event="script" value="email.lua"/>
<talkaction words="!check" event="script" value="email.lua"/>
<talkaction words="!delete" event="script" value="email.lua"/>
<talkaction words="!help" event="script" value="email.lua"/>

Em data\lib abra o arquivo data.lua ou global.lua e adcione isto:

dofile(getDataDir() .. "lib/email.lua")

Em data\creaturescripts abra o arquivo creaturescripts.xml e adcione isto:

<event type="textedit" name="text" event="script" value="text.lua"/>

Em data\creaturescripts\scripts abra o arquivo chamado login.lua e antes de return true coloque isso:

registerCreatureEvent(cid, "text")
   if getInt(getPlayerName(cid)) == -1 then
     setInt(getPlayerName(cid),0)
   end
   doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,(getInt(getPlayerName(cid)) == 0 and 'You don\'t have any emails on your inbox. To help say !help.' or getInt(getPlayerName(cid)) == 1 and 'You have 1 email on your inbox. To help say !help.' or 'You have '.. getInt(getPlayerName(cid)) ..' emails on your inbox. To help say !help.'))    

Na sua pasta data crie uma pasta chamada emails , escreva corretamente se não o script não funcionará.

Pra quem escolheu 'SQL' na talkaction:

[spoiler=Faça]

Execute a seguinte query:

ALTER TABLE `players` ADD `emails` INT NOT NULL DEFAULT '0' AFTER `name`

 

 

 

 

SS

[spoiler=SS]

Login:

 

loginja.png

!help:

fyi.png

Enviar/Ver emails:

emailme.png

 

Obs: Pra quem quiser enviar um email para todos os players (online apenas), eu fiz uma função:

sendEmailForAll(player,assunto,msg)

player: Nome que vai aparecer no 'Remetente';

assunto: assunto;

msg: a mensagem;

 

Atualizações:

V1.0:

 

  • Email para uma pessoa apenas.
  • Sistema de visualização 'precária'.

v2.0:

  • Email para várias pessoas separado por ';'.
  • Sistema de visualização:

 

  1. !check: Mostra uma lista: 'id: destinatário [assunto]'.
  2. !check id: Ver um email com aquele id.
  3. !check assunto: Ver um email com aquele assunto.
  4. !check all: Sistema de visualização da V1.0

Editado por Socket

Compartilhar este post


Link para o post
Mock    32
Mock

Comentario: Legalzudo cara! :o

 

Aprovadoico_aprovado.png & Movidoicon_movido.giffechado22xnux7.gif

 

mock.png

Editado por Mock

Compartilhar este post


Link para o post
dragonlorde    0
dragonlorde

Parabens cara ate que enfim aprovaram em

O script ta mto completo.

Todos os dias melhorando em PQP

Compartilhar este post


Link para o post
pejuge2    1
pejuge2

Apesar de ser um sistema bem simples, de io.open (em termos de dificuldade de scripting), ele é muito rebuscado e por isso pode gerar muitos erros e requer muita atenção e perspicácia para seu desenvolvimento. Parabens!

 

Atenciosamente,

PeJuGe.

Compartilhar este post


Link para o post
olha pro post    0
olha pro post

dahora kra

Compartilhar este post


Link para o post
Socket    0
Socket
Apesar de ser um sistema bem simples, de io.open (em termos de dificuldade de scripting), ele é muito rebuscado e por isso pode gerar muitos erros e requer muita atenção e perspicácia para seu desenvolvimento. Parabens!

 

Atenciosamente,

PeJuGe. __________

Sim, é muito simples mas ao desenvolvimento vem aparecendo mais e mais erros, eu como nunca quase nunca desisto continuei até alcançar meu objetivo.

Obrigado.

Att.

Socket

Compartilhar este post


Link para o post
ninexin    0
ninexin

aqui nao funfo na hora de envia ele nao envia e da o seguinte erro no server

 

[19/08/2010 00:54:17] [Error - TalkAction Interface]

[19/08/2010 00:54:17] data/talkactions/scripts/email.lua:onSay

[19/08/2010 00:54:17] Description:

[19/08/2010 00:54:17] data/talkactions/scripts/email.lua:52: attempt to call global 'doSetItemActionId' (a nil value)

[19/08/2010 00:54:17] stack traceback:

[19/08/2010 00:54:17] data/talkactions/scripts/email.lua:52: in function <data/talkactions/scripts/email.lua:3>

 

 

 

e quando eu vo tenda da um !check all ou number ou subject da isso:

 

[19/08/2010 00:55:52] [Error - TalkAction Interface]

[19/08/2010 00:55:52] data/talkactions/scripts/email.lua:onSay

[19/08/2010 00:55:52] Description:

[19/08/2010 00:55:52] data/lib/email.lua:18: bad argument #1 to 'lines' (C:\Documents and Settings\Xin\Desktop\CastleHell\data\emails\GOD Cannabis.txt: No such file or directory)

[19/08/2010 00:55:52] stack traceback:

[19/08/2010 00:55:52] [C]: in function 'lines'

[19/08/2010 00:55:52] data/lib/email.lua:18: in function 'file'

[19/08/2010 00:55:52] data/talkactions/scripts/email.lua:33: in function <data/talkactions/scripts/email.lua:3>

Compartilhar este post


Link para o post
ped123    0
ped123

socket nerdzao kkk

Compartilhar este post


Link para o post
iuniX    4
iuniX
socket nerdzao kkk

 

Evite reviver tópicos antigos, com assuntos fora do mesmo.

 

Tópioco fechado para evitar futuros floods.

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×