nokizorque

Untitled

Jul 29th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. local antiSpam = {}
  2. local antiSpamTime = 1000
  3.  
  4. function isPlayerInRangeOfPoint(player,x,y,z,range)
  5.     local px,py,pz=getElementPosition(player)
  6.     return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range
  7. end
  8.  
  9. function clearAntiSpam(player)
  10.     destroyElement(antiSpam[player])
  11. end
  12.  
  13. function main(message, messageType)
  14.     if (message == "") or (message == " ") then return true end
  15.  
  16.     local plrTable = {}    
  17.     local pX, pY, pZ = getElementPosition(source)
  18.     local sourceNick = getPlayerName(source)
  19.  
  20.     for i, v in ipairs(getElementsByType("player")) do
  21.         if (isPlayerInRangeOfPoint(v, pX, pY, pZ, range)) then
  22.             table.insert(plrTable, v)
  23.         end
  24.     end
  25.    
  26.     local playerCount = #plrTable - 1
  27.  
  28.     for _, v in pairs(plrTable) do
  29.         if (isPlayerInRangeOfPoint(source, pX, pY, pZ, range)) then
  30.             outputChatBox("[Local Chat]["..playerCount.."] "..sourceNick.." "..message, v, 200, 50, 150)
  31.             setTimer(clearAntiSpam, antiSpamTime, 1, player)
  32.         end
  33.     end
  34.  
  35.     antiSpam[player] = getTickCount()
  36. end
  37. addEventHandler("onPlayerChat", root, main)
Advertisement
Add Comment
Please, Sign In to add comment