What's new

Mods System wiadomo?ci offline

Status
Not open for further replies.

MysleRapem

User
Joined
Sep 3, 2011
Messages
29
Reaction score
1
Siemka. Postanowi?em, ?e na tym forum, kt?re kiedy? by?o skupiskiem jednych z najlepszych skrypter?w w Polsce, a teraz jest niczym biblijna ?wi?tynia pe?na handlarzy i reklam, te? umieszcz? m?j skrypt.

Tak wi?c 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:
Je?li w polu ni?ej nie wy?wietla si? ca?e, spr?buj wzi?? st?d:
Code:
<?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://forum.tibia.tv/showthread.php?p=218426#post218426
		Author: Gandhi
		Date: 18/19 03.2012
		
		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 = {
			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.'
			},
			-- 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` 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(player:getDataInt('online') == 1) 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
			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
		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>

Pozdr?wki.
 

mumia6

Active User
Joined
Jan 29, 2010
Messages
86
Reaction score
1
Odp: System wiadomo?ci offline

Fajny skrypt, a chcia?o by ci si? go przerobi? tak ?eby dzia?a? na ots'ie kt?ry niema mods? Ja jestem w tym zielony a przyda? by mi sie taki skrypt
 

Replay3run

Advanced User
Joined
Feb 8, 2011
Messages
162
Reaction score
19
Odp: System wiadomo?ci offline

mi to nie dzia?a, wstawi?em do mods ale nic dalej si? nie dzieje. Zachowuje si? tak jakby go nie by?o bo w konsoli nic nie wywala.
 

Marolz

Killed by death
Joined
Jan 18, 2012
Messages
388
Reaction score
29
Odp: System wiadomo?ci offline

Fajny, przemy?lany skrypt. Nie wiem czy dzia?a, bo nie mam jak przetestowa? :p Ale sama idea mi si? podoba, kto teraz wysy?a listy?

Btw. tam powinno by? "your", a nie "yours".

Pozdrawiam
 
Joined
Aug 9, 2012
Messages
21
Reaction score
0
Odp: System wiadomo?ci offline

Skrypt zosta? przetestowany na najnowszym TFS 0.4 i niestety nie dzia?a. Da?em /reload mods, jednak nie wida? poprawy. By? moze restart co? zdzia?a, zaraz sprawdz?.

#edit
Nie wida? poprawy po restarcie.
 
Last edited:

pejos

User
Joined
Apr 28, 2011
Messages
44
Reaction score
2
Odp: System wiadomo?ci offline

dziala tylko szkoda ze to nie twoj skrypt :<
 

Placek

Blue Waffle
Joined
Sep 30, 2008
Messages
6,793
Reaction score
672
Age
9
Odp: System wiadomo?ci offline

Dziala, sam go testowalem pierwszy raz juz pare tygodni temu. A teraz go zostawilem zalaczonego na serwerze.

No ale tak jak pisal pejos, szkoda, ze nie twoj i ze napisales, ze twoj...
No chyba, ze Kanciak(otland) = MysleRapem... W co smiem watpic.
 

Dubler

Lua Factory =)
Joined
Apr 8, 2009
Messages
1,874
Reaction score
112
Odp: System wiadomo?ci offline

messageSavingDirectory = 'data/logs/offline_msg/', -- dir with saved messages (folder must exsist!)
Mo?e wam nie dzia?a bo nie zrobili?cie tego folderu?
 
Status
Not open for further replies.
Top