Advertisement
WIXXZI

World Chat Lua File

Jul 2nd, 2012
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. --[[
  2. * Made by Grandelf Mmotop.org.
  3. * Chat System.
  4. * Neglected
  5. * Spread by WIXXZI ( Ac Web )
  6.  
  7.  
  8. * Configuration information.
  9. This system is fairly configurable. You can edit most visual aspects of it.
  10. * chat_prefix
  11. * default: "#chat".
  12. * This is the prefix if you want to send a message.. ie, "#chat Hello, World!" would send "Hello, World!" via the system.
  13. * message_format
  14. * default: "<&rank> &name: &message
  15. * The script will replace &rank with the rank of the sender, &name with the name and &message with the message. Thus, if I was an Admin called Neglected sending "Hello, World!", this would show in the system:
  16. <Administrator> Neglected: Hello, World!
  17. * ranks
  18. * default: many
  19. * This is the rank table. The ranks run off player ranks in the DB. When you create an account you make an account flag (ie, az, a, etc). This script will use those flags in tandem with this script to work. To add a rank you would add a new line like the example format. The first string inside the example is the rank level. This coincides with the account rank flags in the logon database. " " will be the player rank. The second one is the tag that shows before the player's name in World messages, or before the message in Channel messages. The third is the colour of the TAG, and the fourth is the colour of the MESSAGE. Both can be omitted. If you use those, they must either be a preset colour in the preset_colours list, or a hex value, ie #FF6060.
  20. * example: {"az", "Administrator", "RED", "RED"}
  21. ]]
  22.  
  23. local chat_prefix = "#chat";
  24. local message_format = "<&rank> &name: &message" -- &rank for rank, &name for sender name and &message for sender message.
  25. local ranks = {
  26. --[[
  27. * format: {"rank level", "tag", "colour"}
  28. * the "rank level" is what rank they have in the db. Ie, "az" would be for admins. A single whitespace (" ") is the player rank.
  29. * the "tag" is what is shown before their name when they talk. This should be set to false if you do not want a tag to appear.
  30. * prefix colour is the colour of the prefix. It can be a hex code or a preset colour (when omitted this is just the normal colour).
  31. * text colour is the colour of the message. It can be a hex code or a preset colour (when omitted this is just the normal colour).
  32. ]]
  33.  
  34. -- Though these guys would have their tag set normally, whatever. :P
  35. {"az", "Administrator", "LIGHTBLUE", "WHITE"},
  36. {"a", "Gamemaster", "BLUE"},
  37.  
  38. -- Special ranks?
  39. {"d", "Donor", "GREEN"},
  40.  
  41. -- Player rank
  42. {" ", "Player"}
  43. };
  44. local preset_colours = {
  45. -- Source - Chat.h
  46. -- colour ref = "hex"
  47. LIGHTRED = "#ff6060",
  48. LIGHTBLUE = "#00ccff",
  49. TORQUOISEBLUE = "#00C78C",
  50. SPRINGGREEN = "#00FF7F",
  51. GREENYELLOW = "#ADFF2F",
  52. BLUE = "#0000ff",
  53. PURPLE = "#DA70D6",
  54. GREEN = "#00ff00",
  55. RED = "#ff0000",
  56. GOLD = "#ffcc00",
  57. GOLD2 = "#FFC125",
  58. GREY = "#888888",
  59. WHITE = "#ffffff",
  60. SUBWHITE = "#bbbbbb",
  61. MAGENTA = "#ff00ff",
  62. YELLOW = "#ffff00",
  63. ORANGE = "#FF4500",
  64. CHOCOLATE = "#CD661D",
  65. CYAN = "#00ffff",
  66. IVORY = "#8B8B83",
  67. LIGHTYELLOW = "#FFFFE0"
  68. };
  69.  
  70. local function OnChat(_, pPlayer, pMessage)
  71. if pMessage:find(chat_prefix) then
  72. -- Remove the prefix.
  73. local m_message = pMessage:gsub(chat_prefix, "");
  74. print(m_message);
  75.  
  76. -- This isn't a blank message, right?
  77. if m_message == nil or m_message == "" or m_message == " " then
  78. return 0;
  79. end
  80.  
  81. -- Remove the beginning white space.
  82. if not m_message:find("%w") == 1 then
  83. local m_firstchar = m_message:find("%a");
  84. m_message = m_message:sub(m_firstchar, string.len(m_message));
  85. end
  86.  
  87. -- Function to colour our string.
  88. local function ColourifyString(str, colour)
  89. local m_color;
  90. if not colour then colour = preset_colours["WHITE"]; end
  91. if preset_colours[colour] then
  92. m_color = preset_colours[colour]:gsub("#", "");
  93. elseif colour:find("#") then
  94. m_color = colour:gsub("#", "");
  95. else
  96. m_color = preset_colours["WHITE"];
  97. print("No colour was specified in call ColourifyString("..str..", "..colour..")!");
  98. end
  99. return "|cff"..m_color..str.."|r";
  100. end
  101.  
  102. -- Function to grab our rank details from the ranks table.
  103. local function GetRankDetails(rank)
  104. for _, v in pairs(ranks) do
  105. if v[1] == rank then
  106. return v;
  107. end
  108. end
  109. return nil;
  110. end
  111.  
  112. -- Get our rank.
  113. local rank = pPlayer:GetGmRank();
  114. if not rank then rank = " "; end
  115. local m_rankDetails = GetRankDetails(rank);
  116.  
  117. -- If the player has a rank we don't recognize, report and use the Player rank instead.
  118. if not m_rankDetails then
  119. m_rankDetails = GetRankDetails(" ");
  120. print(pPlayer:GetName().."'s rank ("..rank..") is not in the chat system!");
  121. end
  122.  
  123. -- Create our string.
  124. local m_tag = ColourifyString(m_rankDetails[2], m_rankDetails[3]);
  125. local m_name = pPlayer:GetName();
  126.  
  127. -- Are we colouring our main text?
  128. if m_rankDetails[4] then
  129. m_message = ColourifyString(m_message, m_rankDetails[4]);
  130. end
  131.  
  132. -- Push message to world.
  133. local m_string = message_format:gsub("&rank", m_tag);
  134. m_string = m_string:gsub("&name", m_name);
  135. m_string = m_string:gsub("&message", m_message);
  136. SendWorldMessage(m_string, 2);
  137. return 0;
  138. end
  139. end
  140.  
  141. RegisterServerHook(16, OnChat);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement