Skip to content

Commit d2d08ec

Browse files
committed
Update v1.4.1
* Added MSK.Round * Added MSK.Trim
1 parent 8b298b1 commit d2d08ec

File tree

2 files changed

+76
-74
lines changed

2 files changed

+76
-74
lines changed

client.lua

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
MSK = {}
2-
MSK.Timeouts = {}
2+
3+
local Timeouts = {}
4+
local callbackRequest = {}
35

46
if Config.Framework:match('esx') then
57
ESX = exports["es_extended"]:getSharedObject()
68
elseif Config.Framework:match('qbcore') then
79
QBCore = exports['qb-core']:GetCoreObject()
810
end
911

10-
local callbackRequest = {}
1112
local Letters = {}
1213
for i = 48, 57 do table.insert(Letters, string.char(i)) end
1314
for i = 65, 90 do table.insert(Letters, string.char(i)) end
1415
for i = 97, 122 do table.insert(Letters, string.char(i)) end
1516

16-
MSK.Round = function(num, decimal)
17-
return tonumber(string.format("%." .. (decimal or 0) .. "f", num))
18-
end
19-
20-
MSK.Trim = function(str)
21-
return (string.gsub(str, "%s+", ""))
22-
end
23-
2417
MSK.GetRandomLetter = function(length)
2518
Wait(0)
2619
if length > 0 then
@@ -30,14 +23,12 @@ MSK.GetRandomLetter = function(length)
3023
end
3124
end
3225

33-
MSK.HasItem = function(item)
34-
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
35-
logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem'))
36-
return
37-
end
26+
MSK.Round = function(num, decimal)
27+
return tonumber(string.format("%." .. (decimal or 0) .. "f", num))
28+
end
3829

39-
local hasItem = MSK.TriggerCallback('msk_core:hasItem', item)
40-
return hasItem
30+
MSK.Trim = function(str)
31+
return (string.gsub(str, "%s+", ""))
4132
end
4233

4334
MSK.Notification = function(text)
@@ -76,25 +67,6 @@ MSK.Draw3DText = function(coords, text, size, font)
7667
ClearDrawOrigin()
7768
end
7869

79-
MSK.Table_Contains = function(table, value)
80-
if type(value) == 'table' then
81-
for k, v in pairs(table) do
82-
for k2, v2 in pairs(value) do
83-
if v == v2 then
84-
return true
85-
end
86-
end
87-
end
88-
else
89-
for k, v in pairs(table) do
90-
if v == value then
91-
return true
92-
end
93-
end
94-
end
95-
return false
96-
end
97-
9870
MSK.TriggerCallback = function(name, ...)
9971
local requestId = GenerateRequestKey(callbackRequest)
10072
local response
@@ -113,12 +85,41 @@ MSK.TriggerCallback = function(name, ...)
11385
end
11486

11587
MSK.AddTimeout = function(ms, cb)
116-
table.insert(MSK.Timeouts, {time = GetGameTimer() + ms, cb = cb})
117-
return #MSK.Timeouts
88+
table.insert(Timeouts, {time = GetGameTimer() + ms, cb = cb})
89+
return #Timeouts
11890
end
11991

12092
MSK.DelTimeout = function(i)
121-
MSK.Timeouts[i] = nil
93+
Timeouts[i] = nil
94+
end
95+
96+
MSK.HasItem = function(item)
97+
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
98+
logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem'))
99+
return
100+
end
101+
102+
local hasItem = MSK.TriggerCallback('msk_core:hasItem', item)
103+
return hasItem
104+
end
105+
106+
MSK.Table_Contains = function(table, value)
107+
if type(value) == 'table' then
108+
for k, v in pairs(table) do
109+
for k2, v2 in pairs(value) do
110+
if v == v2 then
111+
return true
112+
end
113+
end
114+
end
115+
else
116+
for k, v in pairs(table) do
117+
if v == value then
118+
return true
119+
end
120+
end
121+
end
122+
return false
122123
end
123124

124125
MSK.logging = function(script, code, ...)
@@ -161,14 +162,14 @@ CreateThread(function()
161162
while true do
162163
local sleep = 200
163164

164-
if #MSK.Timeouts > 0 then
165+
if #Timeouts > 0 then
165166
local currTime = GetGameTimer()
166167
sleep = 0
167168

168-
for i = 1, #MSK.Timeouts, 1 do
169-
if currTime >= MSK.Timeouts[i].time then
170-
MSK.Timeouts[i].cb()
171-
MSK.Timeouts[i] = nil
169+
for i = 1, #Timeouts, 1 do
170+
if currTime >= Timeouts[i].time then
171+
Timeouts[i].cb()
172+
Timeouts[i] = nil
172173
end
173174
end
174175
end

server.lua

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
MSK = {}
2-
RegisteredCommands = {}
2+
3+
local RegisteredCommands = {}
4+
local Callbacks = {}
35

46
AddEventHandler('onResourceStart', function(resource)
57
if GetCurrentResourceName() ~= 'msk_core' then
@@ -15,29 +17,28 @@ elseif Config.Framework:match('qbcore') then
1517
QBCore = exports['qb-core']:GetCoreObject()
1618
end
1719

18-
local Callbacks = {}
1920
local Letters = {}
2021
for i = 48, 57 do table.insert(Letters, string.char(i)) end
2122
for i = 65, 90 do table.insert(Letters, string.char(i)) end
2223
for i = 97, 122 do table.insert(Letters, string.char(i)) end
2324

24-
MSK.Round = function(num, decimal)
25-
return tonumber(string.format("%." .. (decimal or 0) .. "f", num))
26-
end
27-
28-
MSK.Trim = function(str)
29-
return (string.gsub(str, "%s+", ""))
30-
end
31-
3225
MSK.GetRandomLetter = function(length)
3326
Wait(0)
3427
if length > 0 then
35-
return GetRandomLetter(length - 1) .. Letters[math.random(1, #Letters)]
28+
return MSK.GetRandomLetter(length - 1) .. Letters[math.random(1, #Letters)]
3629
else
3730
return ''
3831
end
3932
end
4033

34+
MSK.Round = function(num, decimal)
35+
return tonumber(string.format("%." .. (decimal or 0) .. "f", num))
36+
end
37+
38+
MSK.Trim = function(str)
39+
return (string.gsub(str, "%s+", ""))
40+
end
41+
4142
MSK.RegisterCommand = function(name, group, cb, console, framework, suggestion)
4243
if type(name) == 'table' then
4344
for k, v in ipairs(name) do
@@ -128,25 +129,6 @@ MSK.Notification = function(src, text)
128129
TriggerClientEvent('msk_core:notification', src, text)
129130
end
130131

131-
MSK.Table_Contains = function(table, value)
132-
if type(value) == 'table' then
133-
for k, v in pairs(table) do
134-
for k2, v2 in pairs(value) do
135-
if v == v2 then
136-
return true
137-
end
138-
end
139-
end
140-
else
141-
for k, v in pairs(table) do
142-
if v == value then
143-
return true
144-
end
145-
end
146-
end
147-
return false
148-
end
149-
150132
MSK.AddWebhook = function(webhook, botColor, botName, botAvatar, title, description, fields, footer, time)
151133
if footer then
152134
if time then
@@ -183,6 +165,25 @@ MSK.RegisterCallback = function(name, cb)
183165
Callbacks[name] = cb
184166
end
185167

168+
MSK.Table_Contains = function(table, value)
169+
if type(value) == 'table' then
170+
for k, v in pairs(table) do
171+
for k2, v2 in pairs(value) do
172+
if v == v2 then
173+
return true
174+
end
175+
end
176+
end
177+
else
178+
for k, v in pairs(table) do
179+
if v == value then
180+
return true
181+
end
182+
end
183+
end
184+
return false
185+
end
186+
186187
MSK.logging = function(script, code, ...)
187188
if code == 'error' then
188189
print(script, '[^1ERROR^0]', ...)

0 commit comments

Comments
 (0)