Guest User

Untitled

a guest
Nov 13th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. -- DISCLAIMER
  2. --[[
  3. Any user of this resource is allowed to modify the code for personal use, and are not allowed to share their own version with people. Do not attempt to resell this resource as it is avaiblable for FREE. Anyone caught breaking the disclamer will find themselves in trouble with the law under the Copyright Act 2008. You may use / edit only for PERSONAL USE. This code is copyrighted to Christopher Graham Smith (Urangan, Queensland, AUS).
  4. ]]
  5.  
  6. -- Settings - These settings will change the scripts functions and allow you to disable certain parts.
  7. settings = {
  8. ['enableTeamChat'] = true,
  9. ['adminTag'] = {
  10. ['enabled'] = true,
  11. ['ACL'] = { -- A bit more advanced.
  12. { 'serverowner', '#FFFF00Server Owner ' },
  13. { 'HQStaff', '#FFFF00HQ STAFF ' },
  14. { 'Administrator', '#FFFF00Administrator ' },
  15. { 'SeniorMod', '#FFFF00Senior Mod ' },
  16. { 'Modgroup', '#FFFF00Moderator ' },
  17. { 'Probationary', '#FFFF00Probationary ' },
  18. { 'Scripter', '#FFFF00Scripter ' },
  19. { 'Mapper', '#FFFF00Mapper ' },
  20. { 'Premium', '#FF0000[Premium] '},
  21. { 'VIP', '#9900FF[VIP] '},
  22. { 'dp', '#00FFFFVeteran '},
  23. { 'Everyone', ' ' }
  24. }
  25. },
  26. ['swearFilter'] = {
  27. ['enabled'] = true,
  28. ['swearCost'] = 0,
  29. ['swears'] = { -- Allows you to set the blocked swear words, syntax is ['WORD'] = 'REPLACEMENT'
  30. }
  31. },
  32. ['antiSpamFilter'] = {
  33. ['enabled'] = true,
  34. ['execeptionGroups'] = 'Staff', -- Groups which can spam, eg. 'Admin,SuperModerator,Moderator'
  35. ['chatTimeOut'] = 1.5 -- Set in seconds.
  36. },
  37. ['freezeChat'] = {
  38. ['enabled'] = false,
  39. ['command'] = 'freezechat', -- Command to use when activating frozen chat.
  40. ['allowedGroups'] = 'Admin,SuperModerator', -- Groups which have access to this command.
  41. ['resetTime'] = 5 -- Time in minutes before it automatically resets.
  42. },
  43. ['clearChat'] = {
  44. ['enabled'] = false,
  45. ['command'] = 'clearchat',
  46. ['allowedGroups'] = 'Admin,SuperModerator'
  47. }
  48. }
  49.  
  50. -- Required variables
  51. spam = { }
  52. stopChat = false
  53.  
  54. function chatbox(message, msgtype)
  55. if stopChat then cancelEvent() outputChatBox('#FF0000[FREEZECHAT] #FFFFFFAn admin has recently frozen chat.', source, 255, 255, 255, true) return end
  56. local account = getAccountName(getPlayerAccount(source))
  57. local name = getPlayerName(source)
  58. local serial = getPlayerSerial(source)
  59. local r, g, b = getPlayerNametagColor(source)
  60. local check = 0
  61. local spamCheck = false
  62. local text = message
  63. if settings['swearFilter']['enabled'] then
  64. for i, v in pairs(settings['swearFilter']['swears']) do
  65. while text:lower():find(i:lower(),1,true) do
  66. local start, end_ = text:lower():find(i:lower(),1,true)
  67. local found = text:sub(start,end_)
  68. text = text:gsub(found,v)
  69. if settings['swearFilter']['swearCost'] ~= 0 then
  70. takePlayerMoney(source, settings['swearFilter']['swearCost'])
  71. end
  72. end
  73. end
  74. end
  75. if msgtype == 0 then
  76. cancelEvent()
  77. if not settings['adminTag']['enabled'] and not spam[serial] then
  78. message = RGBToHex(r, g, b) .. name .. ':#FFFFFF ' .. text
  79. if 500 <= #message then
  80. outputChatBox('#FF0000Error: The message you entered is too big, please lower it!', source, 255, 255, 255, true)
  81. else
  82. outputChatBox(message, getRootElement(), 255, 255, 255, true)
  83. aclgroup = split(settings['antiSpamFilter']['execeptionGroups'], ', ') or settings['antiSpamFilter']['execeptionGroups']
  84. for i, v in ipairs(aclgroup) do if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), aclGetGroup(v)) then spamCheck = true end end
  85. if not spamCheck then
  86. if settings['antiSpamFilter']['enabled'] then
  87. spam[serial] = true
  88. setTimer(function()
  89. spam[serial] = false
  90. end, settings['antiSpamFilter']['chatTimeOut']*1000, 1)
  91. end
  92. end
  93. outputServerLog('CHAT: ' .. name .. ': ' .. text)
  94. end
  95. return
  96. end
  97. for _,v in ipairs(settings['adminTag']['ACL']) do
  98. if isObjectInACLGroup('user.' .. account, aclGetGroup(v[1])) and check == 0 and not spam[serial] then
  99. local message = v[2] .. RGBToHex(r, g, b) .. name .. ":#FFFFFF " .. text
  100. if 500 <= #message then
  101. outputChatBox('#FF0000Error: The message you entered is too big, please lower it!', source, 255, 255, 255, true)
  102. check = 1
  103. else
  104. check = 1
  105. outputChatBox(message, getRootElement(), 255, 255, 255, true)
  106. if settings['antiSpamFilter']['enabled'] then
  107. aclgroup = split(settings['antiSpamFilter']['execeptionGroups'], ', ') or settings['antiSpamFilter']['execeptionGroups']
  108. for i, v in ipairs(aclgroup) do if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), aclGetGroup(v)) then spamCheck = true end end
  109. if not spamCheck then
  110. spam[serial] = true
  111. check = 1
  112. setTimer(function()
  113. spam[serial] = false
  114. end, settings['antiSpamFilter']['chatTimeOut']*1000, 1)
  115. end
  116. end
  117. outputServerLog('CHAT: '.. v[2] .. name .. ': ' .. text)
  118. end
  119. elseif spam[serial] and check == 0 then
  120. outputChatBox('#FF0000Error: Please wait '..settings['antiSpamFilter']['chatTimeOut']..' seconds before saying a message!', source, 255, 255, 255, true)
  121. check = 1
  122. end
  123. end
  124. elseif msgtype == 1 and not settings['enableTeamChat'] then
  125. cancelEvent()
  126. end
  127. end
  128. addEventHandler("onPlayerChat", getRootElement(), chatbox)
  129.  
  130. addEventHandler("onPlayerQuit", getRootElement(),
  131. function()
  132. local serial = getPlayerName(source)
  133. spam[serial] = false
  134. end )
  135.  
  136. -- Freeze chat
  137. addCommandHandler(settings['freezeChat']['command'],
  138. function(player)
  139. if not settings['freezeChat']['enabled'] then return end
  140. aclgroup = split(settings['freezeChat']['allowedGroups'], ', ') or settings['freezeChat']['allowedGroups']
  141. for i, v in ipairs(aclgroup) do if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup(v)) then check = true end end
  142. if not check then return end
  143.  
  144. if not stopChat then
  145. outputChatBox('#FF0000[FREEZECHAT] #FFFFFF'..getPlayerName(player)..' has frozen the chat!', getRootElement(), 255, 255, 255, true)
  146. stopChat = true
  147. frozenTimer = setTimer(function() stopChat = false end, (settings['freezeChat']['resetTime'] * 60000), 1)
  148. else
  149. outputChatBox('#FF0000[FREEZECHAT] #FFFFFF'..getPlayerName(player)..' has unfrozen the chat!', getRootElement(), 255, 255, 255, true)
  150. stopChat = false
  151. end
  152. end
  153. )
  154.  
  155. -- Clear chat
  156. addCommandHandler(settings['clearChat']['command'],
  157. function(player)
  158. if not settings['clearChat']['enabled'] then return end
  159. aclgroup = split(settings['clearChat']['allowedGroups'], ',') or settings['clearChat']['allowedGroups']
  160. for i, v in ipairs(aclgroup) do if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup(v)) then check = true end end
  161. if not check then return end
  162.  
  163. for i = 2, getElementData(player, 'chatLines') do
  164. outputChatBox(' ')
  165. end
  166. outputChatBox('#FF0000[CLEARCHAT]#FFFFFF '..getPlayerName(player)..' has cleared the chat', getRootElement(), 255, 255, 255, true)
  167. end
  168. )
  169.  
  170. function RGBToHex(red, green, blue, alpha)
  171. return string.format("#%.2X%.2X%.2X", red,green,blue)
  172. end
Advertisement
Add Comment
Please, Sign In to add comment