What's new

Mods [MOD] Offline Messages System

Status
Not open for further replies.

Gandhi

Active User
Joined
Aug 7, 2013
Messages
80
Reaction score
19
Siemka.

Dzisiaj mam dla was system wiadomo?ci offline. Teraz b?dziesz m?g? napisa? do gracza, kt?ry jest offline ; o Wiadomo?? wy?wietli mu si? po zalogowaniu. Mo?esz te? wybra? spos?b wy?wietlania, czy skrypt poka?e wszystkie wiadomo?ci od razu, czy po kolei w odst?pach, kt?re i tak sam ustawisz. Je?li gracz zaraz po zalogowaniu si? wyloguje, a skrypt nie zd??y wy?wietli? wszystkich wiadomo?ci, to niewy?wietlone b?d? czeka? na kolejne zalogowanie. Prosty config, ale s? rzeczy do ustawienia te? dla tych bardziej ogarni?tych w temacie.

Skrypt zapisuje wys?ane wiadomo?ci w wskazanym folderze. Gdy gracz si? loguje, sprawdza, czy s? zapisane dla niego jakie? wiadomo?ci. Je?li tak, to wy?wietla je.

Skrypt zrobiony jako mod, wi?c to jeden plik. Testowany na 8.6 TFS 0.4 r3884, ale powinno dzia?a? na ka?dym z modami, a jak sobie przerobisz na normalne skrypty LUA, to i na wcze?niejszych.

Ma?e zdj?tko, z kt?rego i tak nic nie skminisz, p?ki nie stestujesz.
3508jdc.png


w mods/ zr?b plik offline_msg.xml i wklep do niego ten skrypt:

daj? na pastebin, bo parser bbcode na forum wstawia spacje w d?ugie nazwy zmiennych, co psuje skrypt. Skrypt we? z tego linku, je?li nie chcesz mie? k?opot?w.

[xml] <?xml version="1.0" encoding="UTF-8"?>
<mod name="Offline Messages" version="1.0" author="Gandhi [PL]" contact="GG: 38138073" enabled="yes">
<description>
Main Thread: http://tibia.net.pl/threads/561375-MOD-Offline-Messages-System
Author: Gandhi
Date: 18/19 03.2012
Last edit: 29 03.2014

About:
This is simple script, that allow you to send messages to players who are offline.
They will receive message after login. You can choose receiver will get all messages instantly or one message per ex. 0.7sec.
You can also choose separator after nickname of receiver. It's protecting against devided message, because I'm using string.explode
and you should know how works this function (in example if you say "/msg Gandhi, Hey, its me, how are you?"). Don't worry, all is working great :)

Enjoy.

Greetings for people of Go(o)d will.
</description>
<config name="OfflineMessagesConfig"><![CDATA[
OfflineMessagesConfig = {
maxReceiverGroupId = 3, -- if receiver has this or greater group id, message will not be sent
sendMessagesToOnline = true, -- if true and receiver is online, message will be send too
separatorAfterNickname = ',',
messageSavingDirectory = 'data/logs/offline_msg/', -- dir with saved messages (folder must exsist!)
delayBeetwenShowMessageOnLogin = 750, -- delay in ms to show received messages on login, to deactivate type 0
messages = {
messageType = MESSAGE_STATUS_CONSOLE_BLUE,
errorType = MESSAGE_STATUS_CONSOLE_ORANGE,
['notEnoughParams'] = "You have to write nickname and message to send. Example: /msg Gandhi, Siema, co tam?",
['playerNotFound'] = "Player with this name not found.",
['cantSendMessage'] = "Error: Can't save message. Try it later.",
['messageSent'] = 'Ok, yours message has been sent to player %s.',
['playerOnline'] = 'This player is online, why do you want to send him offline message?',
['tooBigAccess'] = 'You can not send message to this player.'
},
-- advanced configuration
messageFormatString = '[%s] %s: %s', -- date, author, message
dateFormatString = '%d.%m.%Y %H:%M:%S' -- date string format
}

]]></config>

<talkaction words="/msg;/priv" event="buffer"><![CDATA[
domodlib('OfflineMessagesConfig')
local params, player = string.explode(param, OfflineMessagesConfig.separatorAfterNickname), 0
if(#params <= 1) then
doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.errorType, OfflineMessagesConfig.messages['notEnoughParams'])
return true
end
player = db.getResult('SELECT `name`, `online`, `group_id` FROM `players` WHERE `name` = "' .. params[1] .. '";')
if(player:getID() == -1) then
doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.errorType, OfflineMessagesConfig.messages['playerNotFound'])
return true
end
table.remove(params, 1)
if(OfflineMessagesConfig.maxReceiverAccess > 0 and player:getDataInt('group_id') >= OfflineMessagesConfig.maxReceiverGroupId) then
doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.errorType, OfflineMessagesConfig.messages['tooBigAccess'])
return true
end
if(player:getDataInt('online') == 1) then
if(OfflineMessagesConfig.sendMessagesToOnline) then
local target = getPlayerByNameWildcard(player:getDataString('name'))
if(isPlayer(target)) then
doPlayerSendTextMessage(target, OfflineMessagesConfig.messages.messageType, OfflineMessagesConfig.messageFormatString:format(os.date(OfflineMessagesConfig.dateFormatString), getCreatureName(cid),
table.concat(params, OfflineMessagesConfig.separatorAfterNickname)))
else
doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.errorType, OfflineMessagesConfig.messages['playerNotFound'])
end
else
doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.errorType, OfflineMessagesConfig.messages['playerOnline'])
end
return true
end

local file = io.open(OfflineMessagesConfig.messageSavingDirectory .. player:getDataString('name') .. '.Gandhi', 'a+')
if(not file) then
doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.errorType, OfflineMessagesConfig.messages['cantSendMessage'])
return true
end
file:write(OfflineMessagesConfig.messageFormatString:format(os.date(OfflineMessagesConfig.dateFormatString),
getCreatureName(cid), table.concat(params, OfflineMessagesConfig.separatorAfterNickname)) .. '\n')
file:close()

doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.errorType, OfflineMessagesConfig.messages['messageSent']:format(player:getDataString('name')))
player:free()
return true
]]></talkaction>

<creatureevent name="OfflineMsgLogin" type="login" event="buffer"><![CDATA[
domodlib('OfflineMessagesConfig')
local file = io.open(OfflineMessagesConfig.messageSavingDirectory .. getCreatureName(cid) .. '.Gandhi', 'r')
if(not file) then
return true
end
if(not OfflineMessagesConfig.delayBeetwenShowMessageOnLogin) then
for line in file:lines() do
doPlayerSendTextMessage(cid, OfflineMessagesConfig.messages.messageType, line)
end
os.remove(OfflineMessagesConfig.messageSavingDirectory .. getCreatureName(cid) .. '.Gandhi')
else
local function sendLine(cid, msgType, filename)
if(not isPlayer(cid)) then -- check player is still online
return
end
local file = io.open(filename, 'r')
if(not file) then
return
end
local first, str = true, ''
for line in file:lines() do
if(first) then
doPlayerSendTextMessage(cid, msgType, line)
first = false
else
str = str .. line .. '\n'
end
end
file:close()
if(str ~= '') then
file = io.open(filename, 'w')
file:write(str)
file:close()

addEvent(sendLine, OfflineMessagesConfig.delayBeetwenShowMessageOnLogin, cid, msgType, filename)
else
os.remove(filename)
end
end
addEvent(sendLine, OfflineMessagesConfig.delayBeetwenShowMessageOnLogin, cid, OfflineMessagesConfig.messages.messageType, OfflineMessagesConfig.messageSavingDirectory .. getCreatureName(cid) .. '.Gandhi')
end
file:close()
return true
]]></creatureevent>
</mod>
[/xml]
Pozdr?wki
 
  • Like
Reactions: Raa

Gandhi

Active User
Joined
Aug 7, 2013
Messages
80
Reaction score
19
Odp:
Notka moderatorska:
Offline Messages System

Od?wie?am - umie?ci?em skrypt na pastebin, poniewa? parser troch? mi psu? skrypta :D

Je?li macie jaki? dziwny b??d z load buffer, to we?cie skrypt z linku podanego w temacie.
 

misztrz440

Banned
Joined
Dec 15, 2012
Messages
1,032
Reaction score
38
Odp:
Notka moderatorska:
Offline Messages System

Jaki? b??d jest nie wiem o co wgl chodzi :
Loading offline_msg.xml...[Error - ScriptingManager::loadFromXml] Cannot load mod mods/offline_msg.xml
[29/03/2014 07:26:44] Line: 1, Info: XML declaration allowed only at the start of the document


[29/03/2014 07:26:44] failed!

---------- Tre?? dodana o 07:33 ----------

Ju? dzia?a na pocz?tku spacja jest trzeba j? usun??.

---------- Tre?? dodana o 07:44 ----------

I mam jeszcze jeden problem gdy kto? jest offline to pisz? do niego to mu wiadomo?? nie przychodzi wszystko all pi?knie dzia?a wiadomo?? zostaje zapisywana nie ma b??d?w. A gdy on jest online to jak napisz? to mu przychodzi heh.
 

Gandhi

Active User
Joined
Aug 7, 2013
Messages
80
Reaction score
19
Odp:
Notka moderatorska:
Offline Messages System

Spr?bujcie w configu zamieni?:
[lua]delayBeetwenShowMessageOnLogin = 750, -- delay in ms to show received messages on login, to deactivate type 0

[/lua]
na
[lua]
delayBeetwenShowMessageOnLogin = false, -- delay in ms to show received messages on login, to deactivate type 0
[/lua]
 

misztrz440

Banned
Joined
Dec 15, 2012
Messages
1,032
Reaction score
38
Odp:
Notka moderatorska:
Offline Messages System

No dziena dzia?a, tylko ?e teraz jest takie co?, ?e ca?y czas s? te wiadomo?ci wyloguje si? i zaloguj? i s?, a ?eby tylko to by?o tak, ?e tylko przy pierwszym logowaniu si? pokazywa?o a nie ca?y czas.
 

Anakonta

Senior User
Joined
Oct 5, 2010
Messages
536
Reaction score
10
Odp:
Notka moderatorska:
Offline Messages System

Ciekawy mod. Gandhi, da?o by rade aby? doda? do niego aby nie mo?na by?o pisa? do graczy kt?rzy s? online i zablokowanie pisania do accesa wi?kszego ni? ma gracz(aby mo?na by?o w configu zmieni?)
 
Last edited:

Gandhi

Active User
Joined
Aug 7, 2013
Messages
80
Reaction score
19
Odp:
Notka moderatorska:
Offline Messages System

Od?wie?am, doda?em mo?liwo??: blokowania wysy?ania wiadomo?ci do graczy offline, ustawienia maksymalnego group id do kt?rej mog? by? wysy?ane oraz bug, o kt?rym m?wi? mistrz440 w ostatnim po?cie. Co do pierwszego posta mistrza - to nie wiem. Nowe zmiany nie by?y testowane - jak co? piszcie.
 

Placek

Blue Waffle
Joined
Sep 30, 2008
Messages
6,780
Reaction score
662
Age
6
Odp:
Notka moderatorska:
Offline Messages System

blokowania wysy?ania wiadomo?ci do graczy offline
Notka moderatorska:
Offline Messages System
Notka moderatorska:


Seems legit.

Btw. Skrypt stary. Gdzies tu juz byl, testowalem go w uj czasu temu i nawet pare rzeczy pozmienialem i uzywalem przez jakis czas. Ale tak faktycznie to nie widze zadnego sensownego zastosowania. Ot, jest to jest i tyle. Niby cos ciekawego, a tak na prawde do niczego nie potrzebne i zbedne.
 

Gandhi

Active User
Joined
Aug 7, 2013
Messages
80
Reaction score
19
Odp:
Notka moderatorska:
Offline Messages System

Tak na prawd? takie co? ma sens tylko z integracj? w ?r?d?ach, co pozwala u?ywa? normalnego prywatnego kana?u do takiego chatu + zapis do mysql i mo?emy nawet zrobi? na stronie czat z graczmi online, co kiedy? mi si? uda?o. Ten skrypt zrobi?em w sumie te 2 lata temu staraj?c si? zrobi? wersj? tego bez kompilacji, jednak maj?c takie mo?liwo?ci w CPP nie by?o sensu si? rozp?dza? w modzie.
 

Anakonta

Senior User
Joined
Oct 5, 2010
Messages
536
Reaction score
10
Odp:
Notka moderatorska:
Offline Messages System

Gandhi masz mo?e pliki do tego czatu na strone?
Kikimora Wszystkie skrypty s? stare, teraz ?eby trafi? na co? innowacyjnego trzeba cudu bo prawie wszystko ju? jest tylko pozostaje kwestia przeniesienia skryptu na odpowiedni protok??.
 

misztrz440

Banned
Joined
Dec 15, 2012
Messages
1,032
Reaction score
38
Odp:
Notka moderatorska:
Offline Messages System

Nie wiem dziwaczny b??d mam
[Error - TalkAction Interface]
[30/03/2014 09:32:06] buffer
[30/03/2014 09:32:06] Description:
[30/03/2014 09:32:06] [string "loadBuffer"]:17: attempt to compare number with nil

Nie wiem o co chodzi, wi?c na 2 silnikach testowa?em i to samo jest.
 
Status
Not open for further replies.
Top