214 lines
5.0 KiB
Lua
214 lines
5.0 KiB
Lua
if Config.Framework ~= "standalone" then
|
|
return
|
|
end
|
|
|
|
local nameCache = {}
|
|
Core = {
|
|
CoreReady = false,
|
|
JobbyJobs = {},
|
|
JobbyJobsReady = true,
|
|
}
|
|
Core.__index = Core
|
|
Core.Functions = {}
|
|
|
|
|
|
local databaseReady = false
|
|
AddEventHandler('codem-phone:database:ready', function()
|
|
databaseReady = true
|
|
end)
|
|
|
|
local function CheckQBCoreStatus()
|
|
local resourceState = GetResourceState('qbx_core')
|
|
return resourceState == "started" or resourceState == "starting"
|
|
end
|
|
|
|
|
|
Core.CoreReady = true
|
|
|
|
Citizen.CreateThread(function()
|
|
local timeout = 0
|
|
while not databaseReady and timeout < 60000 do
|
|
Wait(100)
|
|
timeout = timeout + 100
|
|
end
|
|
|
|
if not databaseReady then
|
|
print('^1[CODEM-PHONE] Framework ERROR: Database initialization timeout!^7')
|
|
return
|
|
end
|
|
end)
|
|
|
|
|
|
function GetHighestGrade(job)
|
|
local AllFrameworkJobs = Core.JobbyJobs or {}
|
|
if AllFrameworkJobs[job] then
|
|
local AllGrades = AllFrameworkJobs[job].grades
|
|
local highestGrade = -1
|
|
for key, _ in pairs(AllGrades) do
|
|
local gradeNum = tonumber(key)
|
|
if gradeNum and gradeNum > highestGrade then
|
|
highestGrade = gradeNum
|
|
end
|
|
end
|
|
return highestGrade
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
function IsBoss(job, gradeLevel)
|
|
local highestGrade = GetHighestGrade(job)
|
|
return highestGrade and gradeLevel >= highestGrade
|
|
end
|
|
|
|
Core.Functions.GetPlayer = function(playerid)
|
|
if not playerid then
|
|
print('Error: playerId is required')
|
|
return nil
|
|
end
|
|
return {
|
|
source = playerid,
|
|
identifier = Core.Functions.GetIdentifier(playerid)
|
|
}
|
|
end
|
|
|
|
Core.Functions.GetIdentifier = function(playerId)
|
|
if not playerId then
|
|
print('Error: playerId is required')
|
|
return nil
|
|
end
|
|
|
|
return GetPlayerIdentifierByType(playerId, "license")
|
|
end
|
|
|
|
Core.Functions.GetSourceFromIdentifier = function(identifier)
|
|
local players = GetPlayers()
|
|
for i = 1, #players do
|
|
if GetPlayerIdentifierByType(players[i], "license") == identifier then
|
|
return players[i]
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
-- Example job data structure from QBCore:
|
|
--[[
|
|
{
|
|
"payment": 150,
|
|
"grade": {
|
|
"payment": 150,
|
|
"name": "Chief",
|
|
"isboss": true,
|
|
"level": 4
|
|
},
|
|
"type": "leo",
|
|
"name": "police",
|
|
"label": "Law Enforcement",
|
|
"isboss": true,
|
|
"onduty": true
|
|
}
|
|
]]
|
|
Core.Functions.GetPlayerJob = function(playerId)
|
|
if not playerId then
|
|
print('Error: playerId is required')
|
|
return nil
|
|
end
|
|
|
|
|
|
return {
|
|
name = 'unemployed',
|
|
label = 'Unemployed',
|
|
onduty = false,
|
|
grade_name = 'unemployed',
|
|
grade_level = 0,
|
|
isboss = false
|
|
}
|
|
end
|
|
|
|
|
|
Core.Functions.IsPlayerAdmin = function(playerId)
|
|
if not playerId then
|
|
print('Error: playerId is required')
|
|
return false
|
|
end
|
|
|
|
return IsPlayerAceAllowed(playerId, "command.codemphone_admin") == 1
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
Core.Functions.GetName = function(playerId, nameType)
|
|
if not playerId then
|
|
print('Error: playerId is required')
|
|
return 'Unknown'
|
|
end
|
|
return GetPlayerName(playerId), ""
|
|
end
|
|
|
|
Core.Functions.GetMoney = function(playerId, moneyType)
|
|
if not playerId then
|
|
print('Error: playerId is required')
|
|
return 0
|
|
end
|
|
return {
|
|
success = true,
|
|
money = 0
|
|
}
|
|
end
|
|
|
|
Core.Functions.RemoveMoney = function(playerId, amount, moneyType)
|
|
if not playerId then
|
|
print('Error: playerId is required')
|
|
return false
|
|
end
|
|
if not amount or amount <= 0 then
|
|
print('Error: amount must be a positive number')
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
Core.Functions.AddMoney = function(playerId, amount, moneyType)
|
|
if not playerId then
|
|
print('Error: playerId is required')
|
|
return false
|
|
end
|
|
if not amount or amount <= 0 then
|
|
print('Error: amount must be a positive number')
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
|
|
|
|
Core.Functions.AddMoneyOffline = function(citizenid, amount, moneyType)
|
|
if not citizenid then
|
|
return { success = false, message = "Citizen ID is required." }
|
|
end
|
|
if not amount or amount <= 0 then
|
|
return { success = false, message = "Invalid amount." }
|
|
end
|
|
moneyType = moneyType or 'bank'
|
|
return { success = true }
|
|
end
|
|
|
|
|
|
Core.Functions.SetPlayerJob = function(playerid, jobname, grade)
|
|
return true
|
|
end
|
|
|
|
|
|
Core.Functions.CreateUseableItem = function(itemName, callback)
|
|
if not itemName or type(itemName) ~= 'string' then
|
|
print('Error: itemName must be a valid string')
|
|
return
|
|
end
|
|
if not callback or type(callback) ~= 'function' then
|
|
print('Error: callback must be a valid function')
|
|
return
|
|
end
|
|
end
|