LynXS_

Untitled

Jun 29th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.11 KB | None | 0 0
  1. -- Default command prefix
  2. local COMMAND_PREFIX = "."
  3.  
  4. -- Table to store command handlers and usage instructions
  5. local KryptonManager = {}
  6.  
  7. -- Function to handle player chats for old chat system
  8. local function onPlayerChatted(player, message)
  9. -- Check if the message starts with the current command prefix
  10. if string.sub(message, 1, #COMMAND_PREFIX) == COMMAND_PREFIX then
  11. -- Split the message into command and arguments
  12. local parts = {}
  13. for part in message:gmatch("%S+") do
  14. table.insert(parts, part)
  15. end
  16.  
  17. -- Check if there is at least one argument after the prefix
  18. if #parts > 0 then
  19. local command = parts[1]:sub(2):lower() -- Get the command (ignoring case and prefix)
  20. local args = table.concat(parts, " ", 2) -- Concatenate arguments
  21.  
  22. -- Check if the command exists in the KryptonManager table
  23. if KryptonManager[command] then
  24. -- Call the command handler function
  25. KryptonManager[command].handler(player, args)
  26. else
  27. -- Print usage instructions to the output console
  28. print("[Usage] " .. player.Name .. ": ." .. command .. " " .. KryptonManager[command].usage)
  29. end
  30. end
  31. end
  32. end
  33.  
  34. -- Function to handle player chats for new chat system (Roblox >= 487)
  35. local function onPlayerChattedNew(player, message, recipient)
  36. -- Check if the message starts with the current command prefix
  37. if string.sub(message, 1, #COMMAND_PREFIX) == COMMAND_PREFIX then
  38. -- Split the message into command and arguments
  39. local parts = {}
  40. for part in message:gmatch("%S+") do
  41. table.insert(parts, part)
  42. end
  43.  
  44. -- Check if there is at least one argument after the prefix
  45. if #parts > 0 then
  46. local command = parts[1]:sub(2):lower() -- Get the command (ignoring case and prefix)
  47. local args = table.concat(parts, " ", 2) -- Concatenate arguments
  48.  
  49. -- Check if the command exists in the KryptonManager table
  50. if KryptonManager[command] then
  51. -- Call the command handler function
  52. KryptonManager[command].handler(player, args)
  53. else
  54. -- Print usage instructions to the output console
  55. player:SendSystemMessage("[Usage] ." .. command .. " " .. KryptonManager[command].usage, Enum.ChatColor.Blue)
  56. end
  57. end
  58. end
  59. end
  60.  
  61. -- Function to find a player by username or display name
  62. local function findPlayerByName(name)
  63. local players = game.Players:GetPlayers()
  64. for _, player in ipairs(players) do
  65. if player.Name:lower() == name:lower() or player.DisplayName:lower() == name:lower() then
  66. return player
  67. end
  68. end
  69. return nil
  70. end
  71.  
  72. -- Function to register a new command handler
  73. function KryptonManager:RegisterCommand(command, handler, usage)
  74. self[command] = {
  75. handler = handler,
  76. usage = usage,
  77. }
  78. end
  79.  
  80. -- Command handler for changing the command prefix
  81. KryptonManager:RegisterCommand("changeprefix", function(player, args)
  82. if args and #args == 1 then
  83. local newPrefix = args
  84. COMMAND_PREFIX = newPrefix
  85. print("[Prefix Change] Command prefix changed to '" .. COMMAND_PREFIX .. "' by " .. player.Name)
  86. else
  87. print("[Usage] " .. player.Name .. ": .changeprefix <new_prefix>")
  88. end
  89. end, "<new_prefix>")
  90.  
  91. -- Command handler for help command
  92. KryptonManager:RegisterCommand("help", function(player, args)
  93. local helpMessage = "[Help] Available commands:\n"
  94. for command, info in pairs(KryptonManager) do
  95. if type(info) == "table" and info.usage then
  96. helpMessage = helpMessage .. "- ." .. command .. " " .. info.usage .. "\n"
  97. end
  98. end
  99. print(helpMessage)
  100. player:SendSystemMessage(helpMessage, Enum.ChatColor.Blue)
  101. end, "")
  102.  
  103. -- Command handler for printing a message
  104. KryptonManager:RegisterCommand("print", function(player, args)
  105. -- Print the message to the output console
  106. print("[Chat Print] " .. player.Name .. ": " .. args)
  107. end, "<message>")
  108.  
  109. -- Command handler for logging an error message
  110. KryptonManager:RegisterCommand("error", function(player, args)
  111. -- Print an error message to the output console
  112. warn("[Error] " .. player.Name .. ": " .. args)
  113. end, "<message>")
  114.  
  115. -- Command handler for logging a warning message
  116. KryptonManager:RegisterCommand("warn", function(player, args)
  117. -- Print a warning message to the output console
  118. warn("[Warning] " .. player.Name .. ": " .. args)
  119. end, "<message>")
  120.  
  121. -- Command handler for retrieving and printing coordinates
  122. KryptonManager:RegisterCommand("coords", function(player, args)
  123. if args == "me" then
  124. local position = player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position or Vector3.new()
  125. print("[Coords] " .. player.Name .. "'s coordinates: (" .. position.X .. ", " .. position.Y .. ", " .. position.Z .. ")")
  126. elseif args == "others" then
  127. local players = game.Players:GetPlayers()
  128. for _, otherPlayer in ipairs(players) do
  129. local position = otherPlayer.Character and otherPlayer.Character.PrimaryPart and otherPlayer.Character.PrimaryPart.Position or Vector3.new()
  130. print("[Coords] " .. otherPlayer.Name .. "'s coordinates: (" .. position.X .. ", " .. position.Y .. ", " .. position.Z .. ")")
  131. end
  132. else
  133. local targetPlayer = findPlayerByName(args)
  134. if targetPlayer then
  135. local position = targetPlayer.Character and targetPlayer.Character.PrimaryPart and targetPlayer.Character.PrimaryPart.Position or Vector3.new()
  136. print("[Coords] " .. targetPlayer.Name .. "'s coordinates: (" .. position.X .. ", " .. position.Y .. ", " .. position.Z .. ")")
  137. else
  138. print("[Usage] " .. player.Name .. ": .coords <player name / display name or me or others>")
  139. end
  140. end
  141. end, "<player name / display name or me or others>")
  142.  
  143. -- Command handler for teleporting to a player or coordinates
  144. KryptonManager:RegisterCommand("goto", function(player, args)
  145. local targetPlayer = findPlayerByName(args)
  146. if targetPlayer then
  147. -- Teleport player to target player's position
  148. local targetPosition = targetPlayer.Character and targetPlayer.Character.PrimaryPart and targetPlayer.Character.PrimaryPart.Position
  149. if targetPosition then
  150. player.Character:SetPrimaryPartCFrame(CFrame.new(targetPosition))
  151. print("[Teleport] " .. player.Name .. " teleported to " .. targetPlayer.Name)
  152. else
  153. print("[Teleport] " .. targetPlayer.Name .. " does not have a valid position.")
  154. end
  155. elseif args == "me" then
  156. -- Teleport player to their own position
  157. local position = player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position
  158. if position then
  159. player.Character:SetPrimaryPartCFrame(CFrame.new(position))
  160. print("[Teleport] " .. player.Name .. " teleported to their own position.")
  161. else
  162. print("[Teleport] " .. player.Name .. " does not have a valid position.")
  163. end
  164. elseif args == "coords" then
  165. -- Teleport player to specified coordinates
  166. local coords = Vector3.new(args:match("[-+]?%d*%.?%d+"), args:match("[-+]?%d*%.?%d+"), args:match("[-+]?%d*%.?%d+"))
  167. if coords then
  168. player.Character:SetPrimaryPartCFrame(CFrame.new(coords))
  169. print("[Teleport] " .. player.Name .. " teleported to coordinates: (" .. coords.X .. ", " .. coords.Y .. ", " .. coords.Z .. ")")
  170. else
  171. print("[Usage] " .. player.Name .. ": .goto <player name / me / coordinates>")
  172. end
  173. else
  174. print("[Usage] " .. player.Name .. ": .goto <player name / me / coordinates>")
  175. end
  176. end, "<player name / me / coordinates>")
  177.  
  178. -- Command handler for leaving the game
  179. KryptonManager:RegisterCommand("leavegame", function(player, args)
  180. -- Forcefully remove the player from the game
  181. player:Kick("Left the game by command.")
  182. end, "")
  183.  
  184. -- Command handler for rejoining the game
  185. KryptonManager:RegisterCommand("rejoingame", function(player, args)
  186. -- Store current place ID and rejoin
  187. local placeId = game.PlaceId
  188. local jobId = game.JobId
  189. player:LoadCharacter() -- Reset character before rejoining
  190. game:GetService("TeleportService"):TeleportToPlaceInstance(placeId, jobId, player)
  191. end, "")
  192.  
  193. -- Connect the function to the PlayerChatted event (for old chat system)
  194. game.Players.PlayerAdded:Connect(function(player)
  195. player.Chatted:Connect(function(message)
  196. onPlayerChatted(player, message)
  197. end)
  198. end)
  199.  
  200. if game:GetService("RunService"):IsNewChatSystemEnabled() then
  201. -- Connect the function to the new OnChat event
  202. game.Players.PlayerAdded:Connect(function(player)
  203. player.OnChat:Connect(function(message, recipient)
  204. onPlayerChattedNew(player, message, recipient)
  205. end)
  206. end)
  207. end
  208.  
Advertisement
Add Comment
Please, Sign In to add comment