-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.lua
129 lines (104 loc) · 2.82 KB
/
admin.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
-- Game loaded check
if not game:IsLoaded() then
game.Loaded:Wait()
end
-- Locals
local HttpService = game:GetService("HttpService")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local tps = game:GetService("TeleportService")
local Player = Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local rp = character:WaitForChild("HumanoidRootPart")
local User = Player.Name
local runservice = game:GetService("RunService")
local plugins_directory = "situation_plugins"
local chatPrefix = "!"
local executiontext = [[
Welcome to Situation Admin (Beta)!
Type '!help' for a list of commands.
]]
-- Chat feedback
local function sendChatFeedback(message)
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
Text = "[Situation Admin]: " .. message,
Color = Color3.new(1, 1, 1),
Font = Enum.Font.SourceSansBold,
FontSize = Enum.FontSize.Size18,
})
end
sendChatFeedback(executiontext)
-- Utilities
local function split(str, sep)
if str == nil then
return {}
end
if #sep > 1 then
return {}
end
local tokens = {}
for v in str:gmatch("([^" .. sep .. "]+)") do
table.insert(tokens, v)
end
return tokens
end
local function getroot(char)
return char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso")
end
local function load_plugins()
if isfolder(plugins_directory) == false then
makefolder(plugins_directory)
end
local files = listfiles(plugins_directory)
for key, value in pairs(files) do
local file = value:match("[^\\^/]+%.lua$") or value:match("[^\\^/]+%.txt$")
if file ~= nil then
local filename = file:sub(0, #file - 4)
local call = loadstring(readfile(value))
commands[filename] = call
end
end
end
-- Commands Table
--[[
EXAMPLE
COMMAND_NAME = function(...)
--code for command goes here
end,
]]--
commands = {
help = function()
local i = 0
local helpMessage = "Available Commands:\n"
for key, _ in pairs(commands) do
i = i + 1
helpMessage = helpMessage .. i .. ".) " .. key .. "\n"
end
sendChatFeedback(helpMessage)
end,
}
-- Chat listener
local function processChatMessage(msg)
if msg:sub(1, #chatPrefix) == chatPrefix then
local args = split(msg:sub(#chatPrefix + 1), " ")
local command = string.lower(args[1])
table.remove(args, 1)
if commands[command] then
local success, err = pcall(function()
commands[command](table.unpack(args))
end)
if success then
sendChatFeedback("Executed '" .. command .. "' successfully!")
else
sendChatFeedback("Error executing '" .. command .. "': " .. tostring(err))
end
else
sendChatFeedback("Unknown command: " .. command)
end
end
end
Player.Chatted:Connect(processChatMessage)
while task.wait(5) do
load_plugins()
end