1
1
MSK = {}
2
+ RegisteredCommands = {}
3
+
4
+ if Config .Framework :match (' esx' ) then
5
+ ESX = exports [" es_extended" ]:getSharedObject ()
6
+ elseif Config .Framework :match (' qbcore' ) then
7
+ QBCore = exports [' qb-core' ]:GetCoreObject ()
8
+ end
2
9
3
10
local Callbacks = {}
4
11
local Letters = {}
@@ -15,6 +22,92 @@ MSK.GetRandomLetter = function(length)
15
22
end
16
23
end
17
24
25
+ MSK .RegisterCommand = function (name , group , cb , console , suggestion )
26
+ if RegisteredCommands [name ] then
27
+ logging (' debug' , (' Command %s is already registerd. Overriding Command...' ):format (name ))
28
+ end
29
+
30
+ if type (name ) == ' table' then
31
+ for k , v in ipairs (name ) do
32
+ MSK .RegisterCommand (v , group , cb , console , suggestion )
33
+ end
34
+ return
35
+ end
36
+
37
+ local added = addChatSuggestions (name , suggestion )
38
+ while not added do Wait (1 ) end
39
+
40
+ RegisteredCommands [name ] = {group = group , cb = cb , console = console , suggestion = suggestion }
41
+
42
+ RegisterCommand (name , function (source , args , rawCommand )
43
+ local source = source
44
+ local Command , error = RegisteredCommands [name ], nil
45
+
46
+ if not Command .console and source == 0 then
47
+ logging (' error' , ' You can not run this Command in Server Console!' )
48
+ else
49
+ if Command .suggestion and Command .suggestion .arguments then
50
+ local newArgs = {}
51
+
52
+ for k , v in ipairs (Command .suggestion .arguments ) do
53
+ if v .action == ' number' then
54
+ if args [k ] then
55
+ if tonumber (args [k ]) then
56
+ newArgs [v .name ] = args [k ]
57
+ else
58
+ error = (' Argument %s is not a number!' ):format (v .name )
59
+ end
60
+ end
61
+ elseif v .action == ' playerId' then
62
+ if args [k ] then
63
+ if tonumber (args [k ]) > 0 and doesPlayerIdExist (args [k ]) then
64
+ newArgs [v .name ] = args [k ]
65
+ else
66
+ error = (' PlayerId %s does not exist!' ):format (args [k ])
67
+ end
68
+ end
69
+ else
70
+ newArgs [v .name ] = args [k ]
71
+ end
72
+
73
+ if not error and not newArgs [v .name ] and v .val then
74
+ error = (' Argument Mismatch with Argument %s' ):format (v .name )
75
+ end
76
+ if error then break end
77
+ end
78
+
79
+ args = newArgs
80
+ end
81
+
82
+ if error then
83
+ if source == 0 then
84
+ logging (' error' , error )
85
+ else
86
+ MSK .Notification (source , error )
87
+ end
88
+ else
89
+ if Config .Framework :match (' standalone' ) then
90
+ cb (source , args , rawCommand )
91
+ elseif Config .Framework :match (' esx' ) then
92
+ local xPlayer = ESX .GetPlayerFromId (source )
93
+ cb (xPlayer , args , rawCommand )
94
+ elseif Config .Framework :match (' qbcore' ) then
95
+ local Player = QBCore .Functions .GetPlayer (source )
96
+ cb (Player , args , rawCommand )
97
+ end
98
+ end
99
+ end
100
+ end , true )
101
+
102
+ if type (group ) == ' table' then
103
+ for k , v in ipairs (group ) do
104
+ ExecuteCommand ((' add_ace group.%s command.%s allow' ):format (v , name ))
105
+ end
106
+ else
107
+ ExecuteCommand ((' add_ace group.%s command.%s allow' ):format (group , name ))
108
+ end
109
+ end
110
+
18
111
MSK .Notification = function (src , text )
19
112
TriggerClientEvent (' msk_core:notification' , src , text )
20
113
end
@@ -73,23 +166,11 @@ MSK.RegisterCallback = function(name, cb)
73
166
Callbacks [name ] = cb
74
167
end
75
168
76
- MSK .logging = function (script , code , msg , msg2 , msg3 )
169
+ MSK .logging = function (script , code , ... )
77
170
if code == ' error' then
78
- if msg3 then
79
- print (script , ' [^1ERROR^0]' , msg , msg2 , msg3 )
80
- elseif msg2 and not msg3 then
81
- print (script , ' [^1ERROR^0]' , msg , msg2 )
82
- else
83
- print (script , ' [^1ERROR^0]' , msg )
84
- end
171
+ print (script , ' [^1ERROR^0]' , ... )
85
172
elseif code == ' debug' then
86
- if msg3 then
87
- print (script , ' [^3DEBUG^0]' , msg , msg2 , msg3 )
88
- elseif msg2 and not msg3 then
89
- print (script , ' [^3DEBUG^0]' , msg , msg2 )
90
- else
91
- print (script , ' [^3DEBUG^0]' , msg )
92
- end
173
+ print (script , ' [^3DEBUG^0]' , ... )
93
174
end
94
175
end
95
176
@@ -103,6 +184,37 @@ AddEventHandler('msk_core:triggerCallback', function(name, requestId, ...)
103
184
end
104
185
end )
105
186
187
+ doesPlayerIdExist = function (playerId )
188
+ for k , id in pairs (GetPlayers ()) do
189
+ if id == playerId then
190
+ return true
191
+ end
192
+ end
193
+ return false
194
+ end
195
+
196
+ addChatSuggestions = function (name , suggestion )
197
+ if RegisteredCommands [name ] then
198
+ if RegisteredCommands [name ].suggestion then
199
+ TriggerClientEvent (' chat:removeSuggestion' , - 1 , ' /' .. name )
200
+ end
201
+ end
202
+
203
+ if suggestion then
204
+ if not suggestion .arguments then suggestion .arguments = {} end
205
+ if not suggestion .help then suggestion .help = ' ' end
206
+
207
+ TriggerClientEvent (' chat:addSuggestion' , - 1 , ' /' .. name , suggestion .help , suggestion .arguments )
208
+ end
209
+
210
+ return true
211
+ end
212
+
213
+ logging = function (code , ...)
214
+ local script = " [^2" .. GetCurrentResourceName ().. " ^0]"
215
+ MSK .logging (script , code , ... )
216
+ end
217
+
106
218
GithubUpdater = function ()
107
219
GetCurrentVersion = function ()
108
220
return GetResourceMetadata ( GetCurrentResourceName (), " version" )
0 commit comments