Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Ban Script 1.0 Loaded")
- ---------------------------------------------------
- -- This script adds the "ban" command to your game.
- -- Certain players can type "ban [player name]" to ban an abusive player from your place.
- --
- -- You can add your name to the 'speakers' list, allowing you to use the command.
- -- You can also add your friend's name, if you want.
- --
- -- You can add a person's name to the 'banned' list if you don't want them to enter your place.
- -- You will not have to use the ban command on them since they're already banned.
- --
- -- When banning someone, you don't need to type the player's full name, just enough letters
- -- to be sure of who you want to ban.
- --
- -- For example: if Builderman and Builderdude are in-game, "ban builderm" is enough.
- -- if Builderman and Telamon are the only people in the game, you can ban both
- -- by typing "ban b t"
- --
- -- Ambiguous bans are ignored:
- -- Example: Builderman and Builderdude are in-game. "ban bu" is ambiguous.
- ---------------------------------------------------
- speakers = {"yome576", "", ""} -- Those who can say the command
- banned = {"CharcterKaiser", "", ""} -- Those who are banned
- function checkSpeakers(name)
- -- check if name matches a speaker
- for i,v in pairs(speakers) do
- -- convert names to all upper case, otherwise we will allow
- -- "Telamon" but not "telamon" or "tELAMON"
- if (string.upper(name) == string.upper(v)) then return true end
- end
- return false
- end
- function banPlayer(banner, victim)
- -- remove if the victim is not also the speaker
- if (victim ~= banner) then
- victim:Remove()
- banned[victim.Name] = victim.Name
- end
- end
- function matchPlayer(str)
- -- find all players that start with the str
- -- if there is only one, match it
- -- 0 or 2+, don't match it
- local result = nil
- local players = game.Players:GetPlayers()
- for i,v in pairs(game.Players:GetPlayers()) do
- if (string.find(string.lower(v.Name), str) == 1) then
- if (result ~= nil) then return nil end
- result = v
- end
- end
- return result
- end
- function onChatted(msg, recipient, speaker)
- -- convert to all lower case
- local source = string.lower(speaker.Name)
- msg = string.lower(msg)
- -- ban the following players
- -- "ban telamon buildman wookong"
- if (string.find(msg, "ban") == 1) then --- msg starts with "ban"
- -- words and numbers
- for word in msg:gmatch("%w+") do
- local p = matchPlayer(word)
- if (p ~= nil) then
- banPlayer(speaker, p)
- end
- end
- end
- end
- function onPlayerEntered(newPlayer)
- -- remove banned player if they try to come back in
- for i,v in pairs(banned) do
- if (v:lower() == newPlayer.Name:lower()) then
- newPlayer:Remove()
- end
- end
- if checkSpeakers(newPlayer.Name) then
- newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
- end
- end
- game.Players.PlayerAdded:connect(onPlayerEntered)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement