forked from BlueMountainsIO/OnsetLuaScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleFunctions_s.lua
More file actions
111 lines (98 loc) · 2.45 KB
/
ConsoleFunctions_s.lua
File metadata and controls
111 lines (98 loc) · 2.45 KB
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
local commandMap = {}
local helpMap = {}
function AddConsoleCommand(name, help_or_callback, callback)
if name == nil or help_or_callback == nil then
return false
end
if type(help_or_callback) == "string" then
if type(callback) ~= "function" then
return false
end
helpMap[name] = help_or_callback
commandMap[name] = callback
else
commandMap[name] = help_or_callback
end
return true
end
AddFunctionExport("AddConsoleCommand", AddConsoleCommand)
AddEvent("OnPackageStart", function()
print("Type 'help' to get a list of consle commands")
end)
function ProcessInput(input)
local cmd
local args = {}
for word in input:gmatch("%w+") do
if cmd == nil then
cmd = word
else
table.insert(args, word)
end
end
if commandMap[cmd] ~= nil then
commandMap[cmd](table.unpack(args))
else
print("Command '"..cmd.."' not found")
end
end
AddEvent("OnConsoleInput", function(input)
ProcessInput(input)
end)
AddRemoteEvent("OnClientConsoleInput", function(player, input)
ProcessInput(input)
end)
AddConsoleCommand("help", function()
print("Available commands:")
table.sort(commandMap, function(a, b)
return a:upper() < b:upper()
end)
for k, v in pairs(commandMap) do
print("", k, helpMap[k] or "")
end
end)
AddConsoleCommand("restart", "Restarts a package", function(package_name)
if package_name == nil then
return print("Syntax: restart <package_name>")
end
if IsPackageStarted(package_name) then
StopPackage(package_name)
Delay(100, function()
StartPackage(package_name)
end)
else
print("Package "..package_name.." not started, use 'start' command")
end
end)
AddConsoleCommand("start", "Starts a package", function(package_name)
if package_name == nil then
return print("Syntax: start <package_name>")
end
if IsPackageStarted(package_name) then
print("Package "..package_name.." already started")
else
StartPackage(package_name)
end
end)
AddConsoleCommand("stop", "Stops a package", function(package_name)
if package_name == nil then
return print("Syntax: stop <package_name>")
end
if not IsPackageStarted(package_name) then
print("Package "..package_name.." not started")
else
StopPackage(package_name)
end
end)
AddConsoleCommand("list", "List all started packages", function()
print("Started packages:")
for _, v in pairs(GetAllPackages()) do
print("", v)
end
end)
AddConsoleCommand("exit", "Stops the server", function(...)
if ... then
ServerExit(table.concat({...}, " "))
else
ServerExit()
end
end)