forked from Simnation/Main
184 lines
5.3 KiB
Lua
184 lines
5.3 KiB
Lua
![]() |
if Config.Framework ~= 'standalone' then return end
|
||
|
|
||
|
PlayerJob = 'unemployed'
|
||
|
|
||
|
local RequestId = 0
|
||
|
local serverRequests = {}
|
||
|
|
||
|
local clientCallbacks = {}
|
||
|
|
||
|
---@param eventName string
|
||
|
---@param callback function
|
||
|
---@param ... any
|
||
|
TriggerServerCallback = function(eventName, callback, ...)
|
||
|
serverRequests[RequestId] = callback
|
||
|
|
||
|
TriggerServerEvent('weed:triggerServerCallback', eventName, RequestId, GetInvokingResource() or 'unknown', ...)
|
||
|
|
||
|
RequestId = RequestId + 1
|
||
|
end
|
||
|
|
||
|
exports('TriggerServerCallback', TriggerServerCallback)
|
||
|
|
||
|
RegisterNetEvent('weed:serverCallback', function(requestId, invoker, ...)
|
||
|
if not serverRequests[requestId] then
|
||
|
return print(('[^1ERROR^7] Server Callback with requestId ^5%s^7 Was Called by ^5%s^7 but does not exist.'):format(requestId, invoker))
|
||
|
end
|
||
|
|
||
|
serverRequests[requestId](...)
|
||
|
serverRequests[requestId] = nil
|
||
|
end)
|
||
|
|
||
|
---@param eventName string
|
||
|
---@param callback function
|
||
|
_RegisterClientCallback = function(eventName, callback)
|
||
|
clientCallbacks[eventName] = callback
|
||
|
end
|
||
|
|
||
|
RegisterNetEvent('weed:triggerClientCallback', function(eventName, requestId, invoker, ...)
|
||
|
if not clientCallbacks[eventName] then
|
||
|
return print(('[^1ERROR^7] Client Callback not registered, name: ^5%s^7, invoker resource: ^5%s^7'):format(eventName, invoker))
|
||
|
end
|
||
|
|
||
|
clientCallbacks[eventName](function(...)
|
||
|
TriggerServerEvent('weed:clientCallback', requestId, invoker, ...)
|
||
|
end, ...)
|
||
|
end)
|
||
|
|
||
|
function GetPlayerData()
|
||
|
ImplementError('You need to implement GetPlayerData()')
|
||
|
return {}
|
||
|
end
|
||
|
|
||
|
function GetJobName()
|
||
|
Error('GetJobName is used with standalone')
|
||
|
return Config.PoliceJobs
|
||
|
end
|
||
|
|
||
|
local texts = {}
|
||
|
if GetResourceState('qs-textui') == 'started' then
|
||
|
function DrawText3D(x, y, z, text, id, key)
|
||
|
local _id = id
|
||
|
if not texts[_id] then
|
||
|
CreateThread(function()
|
||
|
texts[_id] = 5
|
||
|
while texts[_id] > 0 do
|
||
|
texts[_id] = texts[_id] - 1
|
||
|
Wait(0)
|
||
|
end
|
||
|
texts[_id] = nil
|
||
|
exports['qs-textui']:DeleteDrawText3D(id)
|
||
|
Debug('Deleted text', id)
|
||
|
end)
|
||
|
TriggerEvent('textui:DrawText3D', x, y, z, text, id, key)
|
||
|
end
|
||
|
texts[_id] = 5
|
||
|
end
|
||
|
else
|
||
|
function DrawText3D(x, y, z, text)
|
||
|
SetTextScale(0.35, 0.35)
|
||
|
SetTextFont(4)
|
||
|
SetTextProportional(1)
|
||
|
SetTextColour(255, 255, 255, 215)
|
||
|
SetTextEntry('STRING')
|
||
|
SetTextCentre(true)
|
||
|
AddTextComponentString(text)
|
||
|
SetDrawOrigin(x, y, z, 0)
|
||
|
DrawText(0.0, 0.0)
|
||
|
local factor = text:len() / 370
|
||
|
DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
|
||
|
ClearDrawOrigin()
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function DrawText3Ds(x, y, z, text)
|
||
|
SetTextScale(0.35, 0.35)
|
||
|
SetTextFont(4)
|
||
|
SetTextProportional(1)
|
||
|
SetTextColour(255, 255, 255, 215)
|
||
|
SetTextEntry('STRING')
|
||
|
SetTextCentre(true)
|
||
|
AddTextComponentString(text)
|
||
|
SetDrawOrigin(x, y, z, 0)
|
||
|
DrawText(0.0, 0.0)
|
||
|
local factor = (string.len(text)) / 370
|
||
|
DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
|
||
|
ClearDrawOrigin()
|
||
|
end
|
||
|
|
||
|
function ProgressBar(name, label, duration, useWhileDead, canCancel, disableControls, animation, prop, propTwo, onFinish, onCancel)
|
||
|
if GetResourceState('qs-interface') == 'started' then
|
||
|
local success = exports['qs-interface']:ProgressBar({
|
||
|
duration = duration,
|
||
|
label = label,
|
||
|
position = 'bottom',
|
||
|
useWhileDead = useWhileDead,
|
||
|
canCancel = canCancel,
|
||
|
disable = disableControls,
|
||
|
anim = {
|
||
|
dict = animation.animDict,
|
||
|
clip = animation.anim,
|
||
|
flag = animation?.flags
|
||
|
},
|
||
|
prop = prop
|
||
|
})
|
||
|
if success then
|
||
|
onFinish()
|
||
|
else
|
||
|
onCancel()
|
||
|
end
|
||
|
return
|
||
|
end
|
||
|
if lib.progressCircle({
|
||
|
duration = duration,
|
||
|
label = label,
|
||
|
position = 'bottom',
|
||
|
useWhileDead = useWhileDead,
|
||
|
canCancel = canCancel,
|
||
|
disable = disableControls,
|
||
|
anim = {
|
||
|
dict = animation.animDict,
|
||
|
clip = animation.anim,
|
||
|
flag = animation?.flags
|
||
|
},
|
||
|
prop = prop
|
||
|
}) then
|
||
|
onFinish()
|
||
|
else
|
||
|
onCancel()
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function SendTextMessage(msg, type)
|
||
|
if GetResourceState('qs-interface') == 'started' then
|
||
|
if type == 'inform' then
|
||
|
exports['qs-interface']:AddNotify(msg, 'Inform', 2500, 'fas fa-file')
|
||
|
elseif type == 'error' then
|
||
|
exports['qs-interface']:AddNotify(msg, 'Error', 2500, 'fas fa-bug')
|
||
|
elseif type == 'success' then
|
||
|
exports['qs-interface']:AddNotify(msg, 'Success', 2500, 'fas fa-thumbs-up')
|
||
|
end
|
||
|
return
|
||
|
end
|
||
|
|
||
|
if type == 'inform' then
|
||
|
lib.notify({
|
||
|
title = 'Weed',
|
||
|
description = msg,
|
||
|
type = 'inform'
|
||
|
})
|
||
|
elseif type == 'error' then
|
||
|
lib.notify({
|
||
|
title = 'Weed',
|
||
|
description = msg,
|
||
|
type = 'error'
|
||
|
})
|
||
|
elseif type == 'success' then
|
||
|
lib.notify({
|
||
|
title = 'Weed',
|
||
|
description = msg,
|
||
|
type = 'success'
|
||
|
})
|
||
|
end
|
||
|
end
|