Advertisement
yome576

Untitled

Aug 7th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. print("Ban Script 1.0 Loaded")
  2.  
  3. ---------------------------------------------------
  4. -- This script adds the "ban" command to your game.
  5. -- Certain players can type "ban [player name]" to ban an abusive player from your place.
  6. --
  7. -- You can add your name to the 'speakers' list, allowing you to use the command.
  8. -- You can also add your friend's name, if you want.
  9. --
  10. -- You can add a person's name to the 'banned' list if you don't want them to enter your place.
  11. -- You will not have to use the ban command on them since they're already banned.
  12. --
  13. -- When banning someone, you don't need to type the player's full name, just enough letters
  14. -- to be sure of who you want to ban.
  15. --
  16. -- For example: if Builderman and Builderdude are in-game, "ban builderm" is enough.
  17. -- if Builderman and Telamon are the only people in the game, you can ban both
  18. -- by typing "ban b t"
  19. --
  20. -- Ambiguous bans are ignored:
  21. -- Example: Builderman and Builderdude are in-game. "ban bu" is ambiguous.
  22. ---------------------------------------------------
  23.  
  24.  
  25.  
  26.  
  27. speakers = {"yome576", "", ""} -- Those who can say the command
  28. banned = {"CharcterKaiser", "", ""} -- Those who are banned
  29.  
  30. function checkSpeakers(name)
  31.  
  32. -- check if name matches a speaker
  33. for i,v in pairs(speakers) do
  34. -- convert names to all upper case, otherwise we will allow
  35. -- "Telamon" but not "telamon" or "tELAMON"
  36. if (string.upper(name) == string.upper(v)) then return true end
  37. end
  38. return false
  39. end
  40.  
  41. function banPlayer(banner, victim)
  42.  
  43. -- remove if the victim is not also the speaker
  44. if (victim ~= banner) then
  45. victim:Remove()
  46. banned[victim.Name] = victim.Name
  47. end
  48. end
  49.  
  50. function matchPlayer(str)
  51.  
  52. -- find all players that start with the str
  53. -- if there is only one, match it
  54. -- 0 or 2+, don't match it
  55. local result = nil
  56.  
  57. local players = game.Players:GetPlayers()
  58.  
  59. for i,v in pairs(game.Players:GetPlayers()) do
  60. if (string.find(string.lower(v.Name), str) == 1) then
  61. if (result ~= nil) then return nil end
  62. result = v
  63. end
  64. end
  65.  
  66. return result
  67. end
  68.  
  69. function onChatted(msg, recipient, speaker)
  70.  
  71. -- convert to all lower case
  72. local source = string.lower(speaker.Name)
  73. msg = string.lower(msg)
  74.  
  75. -- ban the following players
  76. -- "ban telamon buildman wookong"
  77. if (string.find(msg, "ban") == 1) then --- msg starts with "ban"
  78. -- words and numbers
  79. for word in msg:gmatch("%w+") do
  80. local p = matchPlayer(word)
  81. if (p ~= nil) then
  82. banPlayer(speaker, p)
  83. end
  84. end
  85. end
  86. end
  87.  
  88. function onPlayerEntered(newPlayer)
  89.  
  90. -- remove banned player if they try to come back in
  91. for i,v in pairs(banned) do
  92. if (v:lower() == newPlayer.Name:lower()) then
  93. newPlayer:Remove()
  94. end
  95. end
  96. if checkSpeakers(newPlayer.Name) then
  97. newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
  98. end
  99. end
  100.  
  101. game.Players.PlayerAdded:connect(onPlayerEntered)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement