Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. MessageRp by Rickoff for Sędzia
  2. tes3mp 0.7.0
  3. ---------------------------
  4. DESCRIPTION :
  5. Script principal for rp message in chat
  6. ---------------------------
  7. INSTALLATION:
  8. Save the file as MessageRp.lua inside your server/scripts/custom folder.
  9.  
  10. Edits to customScripts.lua
  11. MessageRp = require("custom.MessageRp")
  12.  
  13. ---------------------------
  14. FUNCTION:
  15. your message received by players just in your cell
  16. ! before message in your chat for global chat
  17. ---------------------------
  18. ]]
  19.  
  20. local Methods = {}
  21.  
  22. Methods.OnPlayerSendMessage = function(eventStatus, pid, message)
  23.  
  24. if Players[pid] ~= nil and Players[pid]:IsLoggedIn() then
  25. if message:sub(1, 1) == '/' then
  26. else
  27. local message1 = color.Grey .. logicHandler.GetChatName(pid) .. color.White .. " : " .. message
  28.  
  29. if Players[pid]:IsServerStaff() then
  30. if Players[pid]:IsServerOwner() then
  31. message1 = config.rankColors.serverOwner .. "[Adm] " .. message1 .. "\n"
  32. elseif Players[pid]:IsAdmin() then
  33. message1 = config.rankColors.admin .. "[Adm] " .. message1 .. "\n"
  34. elseif Players[pid]:IsModerator() then
  35. message1 = config.rankColors.moderator .. "[Mod] " .. message1 .. "\n"
  36. end
  37. end
  38. if message:sub(1, 1) == '!' then
  39. Methods.SendGlobalMessage(pid, message1)
  40. else
  41. Methods.SendLocalMessage(pid, message1)
  42. end
  43.  
  44. return customEventHooks.makeEventStatus(false,false)
  45. end
  46. end
  47. end
  48.  
  49. Methods.SendGlobalMessage = function(pid, message)
  50. tes3mp.SendMessage(pid, message, true)
  51. end
  52.  
  53. Methods.SendLocalMessage = function(pid, message)
  54. local playerName = Players[pid].name
  55. local localChatCellRadius = 1
  56. -- Get top left cell from our cell
  57. local myCellDescription = Players[pid].data.location.cell
  58.  
  59. if tes3mp.IsInExterior(pid) == true then
  60. local cellX = tonumber(string.sub(myCellDescription, 1, string.find(myCellDescription, ",") - 1))
  61. local cellY = tonumber(string.sub(myCellDescription, string.find(myCellDescription, ",") + 2))
  62.  
  63. local firstCellX = cellX - localChatCellRadius
  64. local firstCellY = cellY + localChatCellRadius
  65.  
  66. local length = localChatCellRadius * 2
  67.  
  68. for x = 0, length, 1 do
  69. for y = 0, length, 1 do
  70. -- loop through all y inside of x
  71. local tempCell = (x+firstCellX)..", "..(firstCellY-y)
  72. -- send message to each player in cell
  73. if LoadedCells[tempCell] ~= nil then
  74. SendMessageToAllInCell(tempCell, message)
  75. end
  76. end
  77. end
  78. else
  79. SendMessageToAllInCell(myCellDescription, message)
  80. end
  81. end
  82.  
  83. function SendMessageToAllInCell(cellDescription, message)
  84. for index,pid in pairs(LoadedCells[cellDescription].visitors) do
  85. if Players[pid].data.location.cell == cellDescription then
  86. tes3mp.SendMessage(pid, message, false)
  87. end
  88. end
  89. end
  90.  
  91. customEventHooks.registerValidator("OnPlayerSendMessage", Methods.OnPlayerSendMessage)
  92.  
  93. return Methods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement