Skip to content

Commit

Permalink
Update v1.9
Browse files Browse the repository at this point in the history
* Fixed some errors
* Added new Callbacks
* Added MSK.GetPlayer
* Added MSK.GetPlayers
  • Loading branch information
Musiker15 committed Aug 12, 2023
1 parent defaef9 commit 8c6a4c9
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 90 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8
1.9
64 changes: 44 additions & 20 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
MSK = {}

local callbackRequest = {}
local callbackRequest, Callbacks = {}, {}

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

MSK.RegisterCallback = function(name, cb)
Callbacks[name] = cb
end

MSK.TriggerCallback = function(name, ...)
local requestId = GenerateRequestKey(callbackRequest)
local response

callbackRequest[requestId] = function(...)
response = {...}
end

TriggerServerEvent('msk_core:triggerCallback', name, requestId, ...)

while not response do Wait(0) end

return table.unpack(response)
end

MSK.Notification = function(title, message, info, time)
if Config.Notification == 'native' then
SetNotificationTextEntry('STRING')
AddTextComponentString(message)
DrawNotification(false, true)
else
elseif Config.Notification == 'nui' or Config.Notification == 'msk' then
SendNUIMessage({
action = 'notify',
title = title,
message = message,
info = info or 'general',
time = time or 5000
})
elseif Config.Notification == 'okok' then
exports['okokNotify']:Alert(title, message, time or 5000, info or 'info')
end
end

Expand Down Expand Up @@ -65,23 +86,6 @@ MSK.Draw3DText = function(coords, text, size, font)
ClearDrawOrigin()
end

MSK.TriggerCallback = function(name, ...)
local requestId = GenerateRequestKey(callbackRequest)
local response

callbackRequest[requestId] = function(...)
response = {...}
end

TriggerServerEvent('msk_core:triggerCallback', name, requestId, ...)

while not response do
Wait(0)
end

return table.unpack(response)
end

MSK.HasItem = function(item)
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem'))
Expand Down Expand Up @@ -116,8 +120,19 @@ MSK.IsVehicleEmpty = function(vehicle)
return passengers == 0 and driverSeatFree
end

MSK.GetPedMugshot = function(ped, transparent)
if not DoesEntityExist(ped) then return end
local mugshot = transparent and RegisterPedheadshotTransparent(ped) or RegisterPedheadshot(ped)

while not IsPedheadshotReady(mugshot) do
Wait(0)
end

return mugshot, GetPedheadshotTxdString(mugshot)
end

GenerateRequestKey = function(tbl)
local id = string.upper(MSK.GetRandomLetter(3)) .. math.random(000, 999) .. string.upper(MSK.GetRandomLetter(2)) .. math.random(00, 99)
local id = string.upper(MSK.GetRandomString(3)) .. math.random(000, 999) .. string.upper(MSK.GetRandomString(2)) .. math.random(00, 99)

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

RegisterNetEvent('msk_core:triggerCallback')
AddEventHandler('msk_core:triggerCallback', function(name, requestId, ...)
if Callbacks[name] then
Callbacks[name](GetPlayerServerId(PlayerId()), function(...)
TriggerServerEvent("msk_core:responseCallback", requestId, ...)
end, ...)
end
end)

RegisterNetEvent("msk_core:notification")
AddEventHandler("msk_core:notification", function(title, message, info, time)
MSK.Notification(title, message, info, time)
Expand Down
18 changes: 18 additions & 0 deletions client/client_progress.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
progressStart = function(text, time, color)
SendNUIMessage({
action = 'progressBarStart',
text = text,
time = time,
color = color or '#5eb131',
})
end
MSK.ProgressBar = progressStart
exports('ProgressBar', progressStart)

progressStop = function()
SendNUIMessage({
action = 'progressBarStop',
})
end
MSK.ProgressStop = progressStop
exports('ProgressStop', progressStop)
13 changes: 12 additions & 1 deletion common/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,18 @@ MSK.logging = function(code, ...)
end
end

exports('getConfig', function()
return Config
end)

logging = function(code, ...)
if not Config.Debug then return end
MSK.logging(code, ...)

if code == 'error' then
print("[^2msk_core^0]", '[^1ERROR^0]', ...)
elseif code == 'debug' then
print("[^2msk_core^0]", '[^3DEBUG^0]', ...)
elseif code == 'info' then
print("[^2msk_core^0]", '[^4Info^0]', ...)
end
end
5 changes: 3 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Config.showCoords = {
}
----------------------------------------------------------------
-- Set to 'native' for FiveM Native Notification
-- Set to 'nui' for NUI Notification
Config.Notification = 'nui'
-- Set to 'msk' for NUI Notification
-- Set to 'okok' for OKOK Notification
Config.Notification = 'msk'
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_core'
description 'Core functions for MSK Scripts'
version '1.8'
version '1.9'

lua54 'yes'

Expand Down
57 changes: 54 additions & 3 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ window.addEventListener('message', (event) => {
document.getElementById(input).placeholder = data.placeholder;
$(".msk-input-container").fadeIn()
$("#msk-input-title").text(data.header)
} else if (event.data.action == 'progressBarStart') {
progressBarStart(event.data);
} else if (event.data.action == 'progressBarStop') {
progressBarStop(event.data.id);
}
})

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

/* MSK Input */

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

document.onkeyup = function(data) {
document.onkeyup = (data) => {
if (data.which == 27) {
closeInputUI()
}
}

function input() {
$("#small-input").keydown((event) => {
if (event.keyCode == 13) {
event.preventDefault();
}
})

input = () => {
var textfield = '#small-input'
if (field) {textfield = '#big-input'}

$.post(`http://${GetParentResourceName()}/submitInput`, JSON.stringify({input: $(textfield).val()}));
$(textfield).val('');
closeInputUI(true)
}

/* MSK ProgressBar */

let activeBars = new Map(); // Using a Map to store active bars with their IDs as keys
let isProgressActive = false

progressBarStart = (data) => {
if (activeBars.has(data.id)) {
$.post(`https://${GetParentResourceName()}/notif`, JSON.stringify({ text: "Already doing an action." }));
return;
}

let progressBar = {
element: $('#progress'),
elementValue: $('#progress-value')
};

activeBars.set(data.id, progressBar);

progressBar.element.removeClass('hidden');
progressBar.elementValue.css("animation",`load ${data.time}s normal forwards`);
progressBar.element.css("animation",`glow ${data.time}s normal forwards`);

$('#progress-text').text(data.text);
document.body.style.setProperty('--mainColor', data.color);

setTimeout(() => {
stopProgress(data.id);
}, data.time);
}

progressBarStop = (id) => {
let progressBar = activeBars.get(id);

if (progressBar) {
progressBar.element.addClass('hidden');
progressBar.elementValue.css("animation",'');
progressBar.element.css("animation",'');
activeBars.delete(id);
}
}
Loading

0 comments on commit 8c6a4c9

Please sign in to comment.