• 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!

Offline Messages :)

Gandh1

Member
Joined
Jan 15, 2008
Messages
16
Reaction score
8
Hi.

I do this script for few Polish forums, but why do not I put it here too.

Description said:
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.

Little screen:
3508jdc.png


Go to mods/ and create offline_msg.xml and paste there it:
Paste Code: http://wklej.to/Pt7WF

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: <a href="http://otibia.pl/mods-inne-51/mods-offline-messages-system-pisanie-do-graczy-offline-teraz-mozliwe-173" target="_blank">http://otibia.pl/mods-inne-51/mods-o...az-mozliwe-173</a>
  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) .. '.otibia.pl', '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) .. '.otibia.pl')
  end
  file:close()
  return true
  ]]></creatureevent>
  </mod>

Greetings.
 
Last edited:
Will this only work if you type /msg or /priv or will this also work if you have an open conversation with someone and just messages them like normal when they are offline?
 
Only by this command. In lua isn't possible now, because tfs don't have any event when speak to channel. But isn't problem to write it in C++.
 
#up
for 99% wrong path to folder, where messages are saved. Edit in config, messageSavingDirectory. Folder must exsist, so you have to create it before using script.

Hmm soon I'll create version with saving messages in database.
 
I came with porting this to sources. What I mean you dont need to type /msg bblabl, blablalb but when you try to make a private message to offline player he gets that message after he login: D
 
Thanks put it in and works in just a matter of seconds! Excellent script! thanks for posting it!
 
Tried with TFS 0.3.6(b3429). Works perfect, I just had to create the folder listed in the config.
 
dont work..


##work, but only cuz i fixed this bugged and lol script, author put everywhere links to otibia.pl forum and that bugged this nice script lel
 
Last edited:
someone can explain to me how it work ??? what folder i must creat and what i must put in config im use 0.4 C 8.60
 
Back
Top