Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Default command prefix
- local COMMAND_PREFIX = "."
- -- Table to store command handlers and usage instructions
- local KryptonManager = {}
- -- Function to handle player chats for old chat system
- local function onPlayerChatted(player, message)
- -- Check if the message starts with the current command prefix
- if string.sub(message, 1, #COMMAND_PREFIX) == COMMAND_PREFIX then
- -- Split the message into command and arguments
- local parts = {}
- for part in message:gmatch("%S+") do
- table.insert(parts, part)
- end
- -- Check if there is at least one argument after the prefix
- if #parts > 0 then
- local command = parts[1]:sub(2):lower() -- Get the command (ignoring case and prefix)
- local args = table.concat(parts, " ", 2) -- Concatenate arguments
- -- Check if the command exists in the KryptonManager table
- if KryptonManager[command] then
- -- Call the command handler function
- KryptonManager[command].handler(player, args)
- else
- -- Print usage instructions to the output console
- print("[Usage] " .. player.Name .. ": ." .. command .. " " .. KryptonManager[command].usage)
- end
- end
- end
- end
- -- Function to handle player chats for new chat system (Roblox >= 487)
- local function onPlayerChattedNew(player, message, recipient)
- -- Check if the message starts with the current command prefix
- if string.sub(message, 1, #COMMAND_PREFIX) == COMMAND_PREFIX then
- -- Split the message into command and arguments
- local parts = {}
- for part in message:gmatch("%S+") do
- table.insert(parts, part)
- end
- -- Check if there is at least one argument after the prefix
- if #parts > 0 then
- local command = parts[1]:sub(2):lower() -- Get the command (ignoring case and prefix)
- local args = table.concat(parts, " ", 2) -- Concatenate arguments
- -- Check if the command exists in the KryptonManager table
- if KryptonManager[command] then
- -- Call the command handler function
- KryptonManager[command].handler(player, args)
- else
- -- Print usage instructions to the output console
- player:SendSystemMessage("[Usage] ." .. command .. " " .. KryptonManager[command].usage, Enum.ChatColor.Blue)
- end
- end
- end
- end
- -- Function to find a player by username or display name
- local function findPlayerByName(name)
- local players = game.Players:GetPlayers()
- for _, player in ipairs(players) do
- if player.Name:lower() == name:lower() or player.DisplayName:lower() == name:lower() then
- return player
- end
- end
- return nil
- end
- -- Function to register a new command handler
- function KryptonManager:RegisterCommand(command, handler, usage)
- self[command] = {
- handler = handler,
- usage = usage,
- }
- end
- -- Command handler for changing the command prefix
- KryptonManager:RegisterCommand("changeprefix", function(player, args)
- if args and #args == 1 then
- local newPrefix = args
- COMMAND_PREFIX = newPrefix
- print("[Prefix Change] Command prefix changed to '" .. COMMAND_PREFIX .. "' by " .. player.Name)
- else
- print("[Usage] " .. player.Name .. ": .changeprefix <new_prefix>")
- end
- end, "<new_prefix>")
- -- Command handler for help command
- KryptonManager:RegisterCommand("help", function(player, args)
- local helpMessage = "[Help] Available commands:\n"
- for command, info in pairs(KryptonManager) do
- if type(info) == "table" and info.usage then
- helpMessage = helpMessage .. "- ." .. command .. " " .. info.usage .. "\n"
- end
- end
- print(helpMessage)
- player:SendSystemMessage(helpMessage, Enum.ChatColor.Blue)
- end, "")
- -- Command handler for printing a message
- KryptonManager:RegisterCommand("print", function(player, args)
- -- Print the message to the output console
- print("[Chat Print] " .. player.Name .. ": " .. args)
- end, "<message>")
- -- Command handler for logging an error message
- KryptonManager:RegisterCommand("error", function(player, args)
- -- Print an error message to the output console
- warn("[Error] " .. player.Name .. ": " .. args)
- end, "<message>")
- -- Command handler for logging a warning message
- KryptonManager:RegisterCommand("warn", function(player, args)
- -- Print a warning message to the output console
- warn("[Warning] " .. player.Name .. ": " .. args)
- end, "<message>")
- -- Command handler for retrieving and printing coordinates
- KryptonManager:RegisterCommand("coords", function(player, args)
- if args == "me" then
- local position = player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position or Vector3.new()
- print("[Coords] " .. player.Name .. "'s coordinates: (" .. position.X .. ", " .. position.Y .. ", " .. position.Z .. ")")
- elseif args == "others" then
- local players = game.Players:GetPlayers()
- for _, otherPlayer in ipairs(players) do
- local position = otherPlayer.Character and otherPlayer.Character.PrimaryPart and otherPlayer.Character.PrimaryPart.Position or Vector3.new()
- print("[Coords] " .. otherPlayer.Name .. "'s coordinates: (" .. position.X .. ", " .. position.Y .. ", " .. position.Z .. ")")
- end
- else
- local targetPlayer = findPlayerByName(args)
- if targetPlayer then
- local position = targetPlayer.Character and targetPlayer.Character.PrimaryPart and targetPlayer.Character.PrimaryPart.Position or Vector3.new()
- print("[Coords] " .. targetPlayer.Name .. "'s coordinates: (" .. position.X .. ", " .. position.Y .. ", " .. position.Z .. ")")
- else
- print("[Usage] " .. player.Name .. ": .coords <player name / display name or me or others>")
- end
- end
- end, "<player name / display name or me or others>")
- -- Command handler for teleporting to a player or coordinates
- KryptonManager:RegisterCommand("goto", function(player, args)
- local targetPlayer = findPlayerByName(args)
- if targetPlayer then
- -- Teleport player to target player's position
- local targetPosition = targetPlayer.Character and targetPlayer.Character.PrimaryPart and targetPlayer.Character.PrimaryPart.Position
- if targetPosition then
- player.Character:SetPrimaryPartCFrame(CFrame.new(targetPosition))
- print("[Teleport] " .. player.Name .. " teleported to " .. targetPlayer.Name)
- else
- print("[Teleport] " .. targetPlayer.Name .. " does not have a valid position.")
- end
- elseif args == "me" then
- -- Teleport player to their own position
- local position = player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position
- if position then
- player.Character:SetPrimaryPartCFrame(CFrame.new(position))
- print("[Teleport] " .. player.Name .. " teleported to their own position.")
- else
- print("[Teleport] " .. player.Name .. " does not have a valid position.")
- end
- elseif args == "coords" then
- -- Teleport player to specified coordinates
- local coords = Vector3.new(args:match("[-+]?%d*%.?%d+"), args:match("[-+]?%d*%.?%d+"), args:match("[-+]?%d*%.?%d+"))
- if coords then
- player.Character:SetPrimaryPartCFrame(CFrame.new(coords))
- print("[Teleport] " .. player.Name .. " teleported to coordinates: (" .. coords.X .. ", " .. coords.Y .. ", " .. coords.Z .. ")")
- else
- print("[Usage] " .. player.Name .. ": .goto <player name / me / coordinates>")
- end
- else
- print("[Usage] " .. player.Name .. ": .goto <player name / me / coordinates>")
- end
- end, "<player name / me / coordinates>")
- -- Command handler for leaving the game
- KryptonManager:RegisterCommand("leavegame", function(player, args)
- -- Forcefully remove the player from the game
- player:Kick("Left the game by command.")
- end, "")
- -- Command handler for rejoining the game
- KryptonManager:RegisterCommand("rejoingame", function(player, args)
- -- Store current place ID and rejoin
- local placeId = game.PlaceId
- local jobId = game.JobId
- player:LoadCharacter() -- Reset character before rejoining
- game:GetService("TeleportService"):TeleportToPlaceInstance(placeId, jobId, player)
- end, "")
- -- Connect the function to the PlayerChatted event (for old chat system)
- game.Players.PlayerAdded:Connect(function(player)
- player.Chatted:Connect(function(message)
- onPlayerChatted(player, message)
- end)
- end)
- if game:GetService("RunService"):IsNewChatSystemEnabled() then
- -- Connect the function to the new OnChat event
- game.Players.PlayerAdded:Connect(function(player)
- player.OnChat:Connect(function(message, recipient)
- onPlayerChattedNew(player, message, recipient)
- end)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment