Skip to content

Commit 8c6a4c9

Browse files
committedAug 12, 2023
Update v1.9
* Fixed some errors * Added new Callbacks * Added MSK.GetPlayer * Added MSK.GetPlayers
1 parent defaef9 commit 8c6a4c9

10 files changed

+298
-90
lines changed
 

‎VERSION

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

‎client/client.lua

+44-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
11
MSK = {}
22

3-
local callbackRequest = {}
3+
local callbackRequest, Callbacks = {}, {}
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+
MSK.RegisterCallback = function(name, cb)
12+
Callbacks[name] = cb
13+
end
14+
15+
MSK.TriggerCallback = function(name, ...)
16+
local requestId = GenerateRequestKey(callbackRequest)
17+
local response
18+
19+
callbackRequest[requestId] = function(...)
20+
response = {...}
21+
end
22+
23+
TriggerServerEvent('msk_core:triggerCallback', name, requestId, ...)
24+
25+
while not response do Wait(0) end
26+
27+
return table.unpack(response)
28+
end
29+
1130
MSK.Notification = function(title, message, info, time)
1231
if Config.Notification == 'native' then
1332
SetNotificationTextEntry('STRING')
1433
AddTextComponentString(message)
1534
DrawNotification(false, true)
16-
else
35+
elseif Config.Notification == 'nui' or Config.Notification == 'msk' then
1736
SendNUIMessage({
1837
action = 'notify',
1938
title = title,
2039
message = message,
2140
info = info or 'general',
2241
time = time or 5000
2342
})
43+
elseif Config.Notification == 'okok' then
44+
exports['okokNotify']:Alert(title, message, time or 5000, info or 'info')
2445
end
2546
end
2647

@@ -65,23 +86,6 @@ MSK.Draw3DText = function(coords, text, size, font)
6586
ClearDrawOrigin()
6687
end
6788

68-
MSK.TriggerCallback = function(name, ...)
69-
local requestId = GenerateRequestKey(callbackRequest)
70-
local response
71-
72-
callbackRequest[requestId] = function(...)
73-
response = {...}
74-
end
75-
76-
TriggerServerEvent('msk_core:triggerCallback', name, requestId, ...)
77-
78-
while not response do
79-
Wait(0)
80-
end
81-
82-
return table.unpack(response)
83-
end
84-
8589
MSK.HasItem = function(item)
8690
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
8791
logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem'))
@@ -116,8 +120,19 @@ MSK.IsVehicleEmpty = function(vehicle)
116120
return passengers == 0 and driverSeatFree
117121
end
118122

123+
MSK.GetPedMugshot = function(ped, transparent)
124+
if not DoesEntityExist(ped) then return end
125+
local mugshot = transparent and RegisterPedheadshotTransparent(ped) or RegisterPedheadshot(ped)
126+
127+
while not IsPedheadshotReady(mugshot) do
128+
Wait(0)
129+
end
130+
131+
return mugshot, GetPedheadshotTxdString(mugshot)
132+
end
133+
119134
GenerateRequestKey = function(tbl)
120-
local id = string.upper(MSK.GetRandomLetter(3)) .. math.random(000, 999) .. string.upper(MSK.GetRandomLetter(2)) .. math.random(00, 99)
135+
local id = string.upper(MSK.GetRandomString(3)) .. math.random(000, 999) .. string.upper(MSK.GetRandomString(2)) .. math.random(00, 99)
121136

122137
if not tbl[id] then
123138
return tostring(id)
@@ -134,6 +149,15 @@ AddEventHandler("msk_core:responseCallback", function(requestId, ...)
134149
end
135150
end)
136151

152+
RegisterNetEvent('msk_core:triggerCallback')
153+
AddEventHandler('msk_core:triggerCallback', function(name, requestId, ...)
154+
if Callbacks[name] then
155+
Callbacks[name](GetPlayerServerId(PlayerId()), function(...)
156+
TriggerServerEvent("msk_core:responseCallback", requestId, ...)
157+
end, ...)
158+
end
159+
end)
160+
137161
RegisterNetEvent("msk_core:notification")
138162
AddEventHandler("msk_core:notification", function(title, message, info, time)
139163
MSK.Notification(title, message, info, time)

‎client/client_progress.lua

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
progressStart = function(text, time, color)
2+
SendNUIMessage({
3+
action = 'progressBarStart',
4+
text = text,
5+
time = time,
6+
color = color or '#5eb131',
7+
})
8+
end
9+
MSK.ProgressBar = progressStart
10+
exports('ProgressBar', progressStart)
11+
12+
progressStop = function()
13+
SendNUIMessage({
14+
action = 'progressBarStop',
15+
})
16+
end
17+
MSK.ProgressStop = progressStop
18+
exports('ProgressStop', progressStop)

‎common/common.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,18 @@ MSK.logging = function(code, ...)
128128
end
129129
end
130130

131+
exports('getConfig', function()
132+
return Config
133+
end)
134+
131135
logging = function(code, ...)
132136
if not Config.Debug then return end
133-
MSK.logging(code, ...)
137+
138+
if code == 'error' then
139+
print("[^2msk_core^0]", '[^1ERROR^0]', ...)
140+
elseif code == 'debug' then
141+
print("[^2msk_core^0]", '[^3DEBUG^0]', ...)
142+
elseif code == 'info' then
143+
print("[^2msk_core^0]", '[^4Info^0]', ...)
144+
end
134145
end

‎config.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ Config.showCoords = {
1313
}
1414
----------------------------------------------------------------
1515
-- Set to 'native' for FiveM Native Notification
16-
-- Set to 'nui' for NUI Notification
17-
Config.Notification = 'nui'
16+
-- Set to 'msk' for NUI Notification
17+
-- Set to 'okok' for OKOK Notification
18+
Config.Notification = 'msk'

‎fxmanifest.lua

+1-1
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.8'
7+
version '1.9'
88

99
lua54 'yes'
1010

‎html/script.js

+54-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ window.addEventListener('message', (event) => {
2121
document.getElementById(input).placeholder = data.placeholder;
2222
$(".msk-input-container").fadeIn()
2323
$("#msk-input-title").text(data.header)
24+
} else if (event.data.action == 'progressBarStart') {
25+
progressBarStart(event.data);
26+
} else if (event.data.action == 'progressBarStop') {
27+
progressBarStop(event.data.id);
2428
}
2529
})
2630

@@ -104,22 +108,69 @@ notification = (title, message, info, time) => {
104108

105109
/* MSK Input */
106110

107-
function closeInputUI(send) {
111+
closeInputUI = (send) => {
108112
$(".msk-input-container").fadeOut()
109113
if (!send) { $.post(`http://${GetParentResourceName()}/closeInput`, JSON.stringify({})) }
110114
}
111115

112-
document.onkeyup = function(data) {
116+
document.onkeyup = (data) => {
113117
if (data.which == 27) {
114118
closeInputUI()
115119
}
116120
}
117121

118-
function input() {
122+
$("#small-input").keydown((event) => {
123+
if (event.keyCode == 13) {
124+
event.preventDefault();
125+
}
126+
})
127+
128+
input = () => {
119129
var textfield = '#small-input'
120130
if (field) {textfield = '#big-input'}
121131

122132
$.post(`http://${GetParentResourceName()}/submitInput`, JSON.stringify({input: $(textfield).val()}));
123133
$(textfield).val('');
124134
closeInputUI(true)
135+
}
136+
137+
/* MSK ProgressBar */
138+
139+
let activeBars = new Map(); // Using a Map to store active bars with their IDs as keys
140+
let isProgressActive = false
141+
142+
progressBarStart = (data) => {
143+
if (activeBars.has(data.id)) {
144+
$.post(`https://${GetParentResourceName()}/notif`, JSON.stringify({ text: "Already doing an action." }));
145+
return;
146+
}
147+
148+
let progressBar = {
149+
element: $('#progress'),
150+
elementValue: $('#progress-value')
151+
};
152+
153+
activeBars.set(data.id, progressBar);
154+
155+
progressBar.element.removeClass('hidden');
156+
progressBar.elementValue.css("animation",`load ${data.time}s normal forwards`);
157+
progressBar.element.css("animation",`glow ${data.time}s normal forwards`);
158+
159+
$('#progress-text').text(data.text);
160+
document.body.style.setProperty('--mainColor', data.color);
161+
162+
setTimeout(() => {
163+
stopProgress(data.id);
164+
}, data.time);
165+
}
166+
167+
progressBarStop = (id) => {
168+
let progressBar = activeBars.get(id);
169+
170+
if (progressBar) {
171+
progressBar.element.addClass('hidden');
172+
progressBar.elementValue.css("animation",'');
173+
progressBar.element.css("animation",'');
174+
activeBars.delete(id);
175+
}
125176
}

‎html/style.css

+57-57
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
/* MSK Input */
5252

5353
body {
54-
overflow:hidden;
54+
overflow: hidden;
5555
user-select: none;
5656
}
5757

@@ -61,104 +61,104 @@ textarea {
6161

6262
::placeholder {
6363
color: white;
64-
opacity:0.8
65-
}
64+
opacity: 0.8
65+
}
6666

6767
* {
6868
--Main: radial-gradient(180vh circle at 0 -60%,#086d04,#050505);
69-
--Input: #1fb11f59;
70-
--Input-Border: #24b11f79;
69+
--Input: #1fb11f59;
70+
--Input-Border: #24b11f79;
7171

7272
user-select: none;
7373
box-sizing: border-box;
74-
font-family:poppins
74+
font-family: poppins
7575
}
7676

7777
#close {
7878
position: absolute;
79-
width:2vh;
80-
height:2vh;
81-
right:1.04vh;
82-
text-align:center;
83-
line-height:2vh;
84-
border-radius:0.4vh;
85-
background:#1fb11f59;
79+
width: 2vh;
80+
height: 2vh;
81+
right: 1.04vh;
82+
text-align: center;
83+
line-height: 2vh;
84+
border-radius: 0.4vh;
85+
background: #1fb11f59;
8686
transition: 400ms;
8787
}
8888

8989
#close:hover {
90-
background:#1fb11f;
90+
background: #1fb11f;
9191
}
9292

9393
.msk-input-container {
94-
display:none;
94+
display: none;
9595
position: absolute;
96-
width:40vh;
97-
height:auto;
98-
background:radial-gradient(110vh circle at 0 -60%,#075705,#050505);
99-
left:50%;
100-
top:50%;
96+
width: 40vh;
97+
height: auto;
98+
background: radial-gradient(110vh circle at 0 -60%,#075705,#050505);
99+
left: 50%;
100+
top: 50%;
101101
transform: translate(-50%, -50%);
102-
border-radius:1.4vh;
103-
color:white;
104-
text-align:center;
105-
padding-top:0.8vh;
106-
text-transform:uppercase;
102+
border-radius: 1.4vh;
103+
color: white;
104+
text-align: center;
105+
padding-top: 0.8vh;
106+
text-transform: uppercase;
107107
font-weight: bold;
108-
font-size:1.4vh;
109-
padding-bottom:1.4vh;
110-
border:0.2vh #1fb11f solid;
108+
font-size: 1.4vh;
109+
padding-bottom: 1.4vh;
110+
border: 0.2vh #1fb11f solid;
111111
}
112112

113113
.msk-input {
114-
width:36vh;
115-
background:#1fb11f2c;
116-
outline:none;
117-
border:none;
118-
overflow:hidden;
119-
border:0.1vh #1fb11f solid;
120-
border-radius:0.4vh;
121-
color:white;
122-
padding:0.72vh;
123-
padding-top:0.4vh;
124-
padding-bottom:0.2vh;
114+
width: 36vh;
115+
background: #1fb11f2c;
116+
outline: none;
117+
border: none;
118+
overflow: hidden;
119+
border: 0.1vh #1fb11f solid;
120+
border-radius: 0.4vh;
121+
color: white;
122+
padding: 0.72vh;
123+
padding-top: 0.4vh;
124+
padding-bottom: 0.2vh;
125125
transition: 400ms;
126126
}
127127

128128
.msk-input:hover {
129-
border-color:#00ff00
129+
border-color: #00ff00
130130
}
131131

132132
#big-input {
133-
display:none;
134-
margin-top:1.2vh;
135-
height:10vh;
133+
display: none;
134+
margin-top: 1.2vh;
135+
height: 10vh;
136136
}
137137

138138
#small-input {
139-
display:all;
140-
margin-top:1.4vh;
139+
display: all;
140+
margin-top: 1.4vh;
141141
white-space: nowrap;
142142

143143
}
144144

145145
.msk-submit-button {
146146
position: relative;
147-
width:16vh;
148-
height:3.2vh;
149-
right:-10vh;
150-
top:0.4vh;
151-
background:#1fb11f2c;
152-
border:0.1vh #1fb11f solid;
153-
border-radius:0.4vh;
154-
font-weight:bold;
155-
font-size:1.4vh;
147+
width: 16vh;
148+
height: 3.2vh;
149+
right: -10vh;
150+
top: 0.4vh;
151+
background: #1fb11f2c;
152+
border: 0.1vh #1fb11f solid;
153+
border-radius: 0.4vh;
154+
font-weight: bold;
155+
font-size: 1.4vh;
156156
text-transform: uppercase;
157-
color:white;
157+
color: white;
158158
transition: 400ms;
159159
}
160160

161161
.msk-submit-button:hover {
162-
background:#1fb11f;
163-
letter-spacing:0.2vh;
162+
background: #1fb11f;
163+
letter-spacing: 0.2vh;
164164
}

‎server/server.lua

+38-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MSK = {}
22

3-
local RegisteredCommands, Callbacks = {}, {}
3+
local RegisteredCommands, Callbacks, callbackRequest = {}, {}, {}
44

55
AddEventHandler('onResourceStart', function(resource)
66
if GetCurrentResourceName() ~= 'msk_core' then
@@ -16,6 +16,25 @@ elseif Config.Framework:match('qbcore') then
1616
QBCore = exports['qb-core']:GetCoreObject()
1717
end
1818

19+
MSK.RegisterCallback = function(name, cb)
20+
Callbacks[name] = cb
21+
end
22+
23+
MSK.TriggerCallback = function(name, playerId, ...)
24+
local requestId = GenerateRequestKey(callbackRequest)
25+
local response
26+
27+
callbackRequest[requestId] = function(...)
28+
response = {...}
29+
end
30+
31+
TriggerClientEvent('msk_core:triggerCallback', playerId, name, requestId, ...)
32+
33+
while not response do Wait(0) end
34+
35+
return table.unpack(response)
36+
end
37+
1938
MSK.RegisterCommand = function(name, group, cb, console, framework, suggestion)
2039
if type(name) == 'table' then
2140
for k, v in ipairs(name) do
@@ -155,10 +174,6 @@ MSK.AddWebhook = function(webhook, botColor, botName, botAvatar, title, descript
155174
})
156175
end
157176

158-
MSK.RegisterCallback = function(name, cb)
159-
Callbacks[name] = cb
160-
end
161-
162177
MSK.HasItem = function(xPlayer, item)
163178
if not xPlayer then logging('error', 'Player on Function MSK.HasItem does not exist!') return end
164179
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
@@ -201,6 +216,24 @@ AddEventHandler('msk_core:triggerCallback', function(name, requestId, ...)
201216
end
202217
end)
203218

219+
RegisterNetEvent("msk_core:responseCallback")
220+
AddEventHandler("msk_core:responseCallback", function(requestId, ...)
221+
if callbackRequest[requestId] then
222+
callbackRequest[requestId](...)
223+
callbackRequest[requestId] = nil
224+
end
225+
end)
226+
227+
GenerateRequestKey = function(tbl)
228+
local id = string.upper(MSK.GetRandomString(3)) .. math.random(000, 999) .. string.upper(MSK.GetRandomString(2)) .. math.random(00, 99)
229+
230+
if not tbl[id] then
231+
return tostring(id)
232+
else
233+
GenerateRequestKey(tbl)
234+
end
235+
end
236+
204237
doesPlayerIdExist = function(playerId)
205238
for k, id in pairs(GetPlayers()) do
206239
if id == playerId then

‎server/server_player.lua

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
MSK.GetPlayer = function(player)
2+
local Player
3+
4+
if player.source then
5+
if Config.Framework == 'esx' then
6+
Player = ESX.GetPlayerFromId(player.source)
7+
elseif Config.Framework == 'qbcore' then
8+
Player = QBCore.Functions.GetPlayer(player.source)
9+
end
10+
elseif player.identifier then
11+
if Config.Framework == 'esx' then
12+
Player = ESX.GetPlayerFromIdentifier(player.identifier)
13+
elseif Config.Framework == 'qbcore' then
14+
Player = MSK.GetPlayer({source = QBCore.Functions.GetSource(player.identifier)})
15+
end
16+
elseif player.citizenid then
17+
if Config.Framework == 'esx' then
18+
Player = ESX.GetPlayerFromIdentifier(player.citizenid)
19+
elseif Config.Framework == 'qbcore' then
20+
Player = QBCore.Functions.GetPlayerByCitizenId(player.citizenid)
21+
end
22+
elseif player.phone then
23+
if Config.Framework == 'esx' then
24+
if ESX.GetPlayerFromPhoneNumber then
25+
Player = ESX.GetPlayerFromPhoneNumber(player.phone)
26+
else
27+
local data = MySQL.query.await('SELECT * from users WHERE phone_number = ?', {player.phone})
28+
if data and data[1] then Player = ESX.GetPlayerFromIdentifier(data[1].identifier) end
29+
end
30+
elseif Config.Framework == 'qbcore' then
31+
Player = QBCore.Functions.GetPlayerByPhone(tostring(player.phone))
32+
end
33+
end
34+
35+
return Player
36+
end
37+
38+
MSK.GetPlayers = function(key, val)
39+
local Players
40+
41+
if Config.Framework == 'esx' then
42+
Players = ESX.GetExtendedPlayers(key, val)
43+
elseif Config.Framework == 'qbcore' then
44+
if not key then
45+
Players = QBCore.Functions.GetQBPlayers()
46+
else
47+
local qbPlayers
48+
49+
for k, Player in pairs(QBCore.Functions.GetQBPlayers()) do
50+
if key == 'job' then
51+
if Player.PlayerData.job.name == val then
52+
qbPlayers[#qbPlayers + 1] = Player
53+
end
54+
elseif key == 'gang' then
55+
if Player.PlayerData.gang.name == val then
56+
qbPlayers[#qbPlayers + 1] = Player
57+
end
58+
elseif key == 'group' then
59+
if IsPlayerAceAllowed(Player.PlayerData.source, val) then
60+
qbPlayers[#qbPlayers + 1] = Player
61+
end
62+
end
63+
end
64+
65+
Players = qbPlayers
66+
end
67+
end
68+
69+
return Players
70+
end

0 commit comments

Comments
 (0)
Please sign in to comment.