Skip to content

Commit d0878c8

Browse files
committed
Update v1.8
* New folder structure * Added MSK.DumpTable * Added MSK.Input * Changed MSK.logging
1 parent 3dede4f commit d0878c8

15 files changed

+448
-251
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.7
1+
1.8

client.lua renamed to client/client.lua

+8-97
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
11
MSK = {}
22

3-
local Timeouts, callbackRequest = {}, {}
3+
local callbackRequest = {}
44

55
if Config.Framework:match('esx') then
66
ESX = exports["es_extended"]:getSharedObject()
77
elseif Config.Framework:match('qbcore') then
88
QBCore = exports['qb-core']:GetCoreObject()
99
end
1010

11-
local Letters = {}
12-
for i = 48, 57 do table.insert(Letters, string.char(i)) end
13-
for i = 65, 90 do table.insert(Letters, string.char(i)) end
14-
for i = 97, 122 do table.insert(Letters, string.char(i)) end
15-
16-
MSK.GetRandomLetter = function(length)
17-
Wait(0)
18-
if length > 0 then
19-
return MSK.GetRandomLetter(length - 1) .. Letters[math.random(1, #Letters)]
20-
else
21-
return ''
22-
end
23-
end
24-
25-
MSK.Round = function(num, decimal)
26-
return tonumber(string.format("%." .. (decimal or 0) .. "f", num))
27-
end
28-
29-
MSK.Trim = function(str, bool)
30-
if bool then return (str:gsub("^%s*(.-)%s*$", "%1")) end
31-
return (str:gsub("%s+", ""))
32-
end
33-
34-
MSK.Split = function(str, delimiter)
35-
local result = {}
36-
37-
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
38-
table.insert(result, match)
39-
end
40-
41-
return result
42-
end
43-
4411
MSK.Notification = function(title, message, info, time)
4512
if Config.Notification == 'native' then
4613
SetNotificationTextEntry('STRING')
@@ -115,24 +82,6 @@ MSK.TriggerCallback = function(name, ...)
11582
return table.unpack(response)
11683
end
11784

118-
local Timeout = 0
119-
MSK.AddTimeout = function(ms, cb)
120-
local requestId = Timeout + 1
121-
122-
SetTimeout(ms, function()
123-
if Timeouts[requestId] then Timeouts[requestId] = nil return end
124-
cb()
125-
end)
126-
127-
Timeout = requestId
128-
return requestId
129-
end
130-
131-
MSK.DelTimeout = function(requestId)
132-
if not requestId then return end
133-
Timeouts[requestId] = true
134-
end
135-
13685
MSK.HasItem = function(item)
13786
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
13887
logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem'))
@@ -143,40 +92,6 @@ MSK.HasItem = function(item)
14392
return hasItem
14493
end
14594

146-
MSK.Table_Contains = function(table, value)
147-
if type(value) == 'table' then
148-
for k, v in pairs(table) do
149-
for k2, v2 in pairs(value) do
150-
if v == v2 then
151-
return true
152-
end
153-
end
154-
end
155-
else
156-
for k, v in pairs(table) do
157-
if v == value then
158-
return true
159-
end
160-
end
161-
end
162-
return false
163-
end
164-
165-
MSK.Comma = function(int, tag)
166-
if not tag then tag = '.' end
167-
local newInt = int
168-
169-
while true do
170-
newInt, k = string.gsub(newInt, "^(-?%d+)(%d%d%d)", '%1'..tag..'%2')
171-
172-
if (k == 0) then
173-
break
174-
end
175-
end
176-
177-
return newInt
178-
end
179-
18095
MSK.GetVehicleInDirection = function()
18196
local playerPed = PlayerPedId()
18297
local playerCoords = GetEntityCoords(playerPed)
@@ -186,23 +101,19 @@ MSK.GetVehicleInDirection = function()
186101

187102
if hit == 1 and GetEntityType(entityHit) == 2 then
188103
local entityCoords = GetEntityCoords(entityHit)
189-
return entityHit, entityCoords
104+
local entityDistance = #(playerCoords - entityCoords)
105+
return entityHit, entityCoords, entityDistance
190106
end
191107

192108
return nil
193109
end
194110

195-
MSK.logging = function(script, code, ...)
196-
if code == 'error' then
197-
print(script, '[^1ERROR^0]', ...)
198-
elseif code == 'debug' then
199-
print(script, '[^3DEBUG^0]', ...)
200-
end
201-
end
111+
MSK.IsVehicleEmpty = function(vehicle)
112+
if not vehicle or (vehicle and not DoesEntityExist(vehicle)) then return end
113+
local passengers = GetVehicleNumberOfPassengers(vehicle)
114+
local driverSeatFree = IsVehicleSeatFree(vehicle, -1)
202115

203-
logging = function(code, ...)
204-
local script = "[^2"..GetCurrentResourceName().."^0]"
205-
MSK.logging(script, code, ...)
116+
return passengers == 0 and driverSeatFree
206117
end
207118

208119
GenerateRequestKey = function(tbl)

client/client_input.lua

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local isOpen = false
2+
local callback = {}
3+
4+
openInput = function(header, placeholder, field, cb)
5+
if isOpen then return print('Input is already open') end
6+
if not cb then callback = field else callback = cb end
7+
8+
SetNuiFocus(true, true)
9+
SendNUIMessage({
10+
action = "openInput",
11+
header = header,
12+
placeholder = placeholder,
13+
field = field and type(field) == 'boolean'
14+
})
15+
isOpen = true
16+
end
17+
MSK.Input = openInput
18+
exports('openInput', openInput)
19+
20+
closeInput = function()
21+
SetNuiFocus(false, false)
22+
isOpen = false
23+
end
24+
exports('closeInput', closeInput)
25+
26+
RegisterNUICallback('closeInput', function(data)
27+
callback()
28+
closeInput()
29+
end)
30+
31+
RegisterNUICallback('submitInput', function(data)
32+
callback(data.input)
33+
closeInput()
34+
end)
35+
36+
AddEventHandler('onResourceStop', function(resourceName)
37+
if resourceName == GetCurrentResourceName() then
38+
closeInput()
39+
end
40+
end)
File renamed without changes.

common/common.lua

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
local Timeouts, Letters = {}, {}
2+
3+
for i = 48, 57 do table.insert(Letters, string.char(i)) end
4+
for i = 65, 90 do table.insert(Letters, string.char(i)) end
5+
for i = 97, 122 do table.insert(Letters, string.char(i)) end
6+
7+
MSK.GetRandomString = function(length)
8+
Wait(0)
9+
if length > 0 then
10+
return MSK.GetRandomLetter(length - 1) .. Letters[math.random(1, #Letters)]
11+
else
12+
return ''
13+
end
14+
end
15+
MSK.GetRandomLetter = MSK.GetRandomString
16+
17+
MSK.Round = function(num, decimal)
18+
return tonumber(string.format("%." .. (decimal or 0) .. "f", num))
19+
end
20+
21+
MSK.Trim = function(str, bool)
22+
if bool then return (str:gsub("^%s*(.-)%s*$", "%1")) end
23+
return (str:gsub("%s+", ""))
24+
end
25+
26+
MSK.Split = function(str, delimiter)
27+
local result = {}
28+
29+
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
30+
table.insert(result, match)
31+
end
32+
33+
return result
34+
end
35+
36+
MSK.Table_Contains = function(table, value)
37+
if type(value) == 'table' then
38+
for k, v in pairs(table) do
39+
for k2, v2 in pairs(value) do
40+
if v == v2 then
41+
return true
42+
end
43+
end
44+
end
45+
else
46+
for k, v in pairs(table) do
47+
if v == value then
48+
return true
49+
end
50+
end
51+
end
52+
return false
53+
end
54+
55+
MSK.Comma = function(int, tag)
56+
if not tag then tag = '.' end
57+
local newInt = int
58+
59+
while true do
60+
newInt, k = string.gsub(newInt, "^(-?%d+)(%d%d%d)", '%1'..tag..'%2')
61+
62+
if (k == 0) then
63+
break
64+
end
65+
end
66+
67+
return newInt
68+
end
69+
70+
local Timeout = 0
71+
MSK.AddTimeout = function(ms, cb)
72+
local requestId = Timeout + 1
73+
74+
SetTimeout(ms, function()
75+
if Timeouts[requestId] then Timeouts[requestId] = nil return end
76+
cb()
77+
end)
78+
79+
Timeout = requestId
80+
return requestId
81+
end
82+
83+
MSK.DelTimeout = function(requestId)
84+
if not requestId then return end
85+
Timeouts[requestId] = true
86+
end
87+
88+
MSK.DumpTable = function(tbl, n)
89+
if not n then n = 0 end
90+
if type(tbl) ~= "table" then return tostring(tbl) end
91+
local s = '{\n'
92+
93+
for k, v in pairs(tbl) do
94+
if type(k) ~= 'number' then k = '"'..k..'"' end
95+
for i = 1, n, 1 do s = s .. " " end
96+
s = s .. ' ['..k..'] = ' .. MSK.DumpTable(v, n + 1) .. ',\n'
97+
end
98+
99+
for i = 1, n, 1 do s = s .. " " end
100+
101+
return s .. '}'
102+
end
103+
104+
MSK.logging = function(code, ...)
105+
local script = "[^2"..GetInvokingResource().."^0]"
106+
107+
if not MSK.Table_Contains({'error', 'debug', 'info'}, code) then
108+
script = code
109+
local action = ...
110+
local args = {...}
111+
table.remove(args, 1)
112+
113+
if action == 'error' then
114+
print(script, '[^1ERROR^0]', table.unpack(args))
115+
elseif action == 'debug' then
116+
print(script, '[^3DEBUG^0]', table.unpack(args))
117+
elseif action == 'info' then
118+
print(script, '[^4Info^0]', table.unpack(args))
119+
end
120+
else
121+
if code == 'error' then
122+
print(script, '[^1ERROR^0]', ...)
123+
elseif code == 'debug' then
124+
print(script, '[^3DEBUG^0]', ...)
125+
elseif code == 'info' then
126+
print(script, '[^4Info^0]', ...)
127+
end
128+
end
129+
end
130+
131+
logging = function(code, ...)
132+
if not Config.Debug then return end
133+
MSK.logging(code, ...)
134+
end

config.lua

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Config = {}
22
----------------------------------------------------------------
3+
Config.Debug = true
34
Config.VersionChecker = true
45
----------------------------------------------------------------
56
-- Only Required for MSK.RegisterCommand // View Wiki for more Information about that!

fxmanifest.lua

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ games { 'gta5' }
44
author 'Musiker15 - MSK Scripts'
55
name 'msk_core'
66
description 'Core functions for MSK Scripts'
7-
version '1.7.7'
7+
version '1.8'
88

99
lua54 'yes'
1010

@@ -14,14 +14,16 @@ shared_scripts {
1414
}
1515

1616
client_scripts {
17-
'client.lua',
18-
'client_*.lua'
17+
'client/client.lua',
18+
'client/client_*.lua',
19+
'common/common.lua',
1920
}
2021

2122
server_scripts {
2223
'@oxmysql/lib/MySQL.lua',
23-
'server.lua',
24-
'server_*.lua'
24+
'server/server.lua',
25+
'server/server_*.lua',
26+
'common/common.lua',
2527
}
2628

2729
ui_page 'html/index.html'

html/index.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
6-
<title>MSK Notification</title>
6+
<title>MSK Scripts</title>
7+
<link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
8+
<script src="https://kit.fontawesome.com/57b9d31625.js" crossorigin="anonymous"></script>
79
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet">
8-
<link rel="stylesheet" href="styles.css">
10+
<link rel="stylesheet" href="style.css">
911
</head>
1012

1113
<body style="background-color: transparent;">
1214
<div class="d-grid notify-wrapper"></div>
1315
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
1416
<script src="script.js"></script>
17+
18+
<div class="msk-input-container"><span id="msk-input-title">Das ist eine Überschrift</span>
19+
<span id="close" onclick="closeInputUI()"><i class="fa-solid fa-xmark"></i></span>
20+
<textarea class="msk-input" rows="5" cols="50" id="big-input" placeholder=""></textarea>
21+
<textarea class="msk-input" rows="1" cols="50" id="small-input" placeholder=""></textarea>
22+
<button class="msk-submit-button" onclick="input()">Confirm</button>
23+
</div>
1524
</body>
1625
</html>

0 commit comments

Comments
 (0)