forked from Simnation/Main
ed
This commit is contained in:
parent
08a306e1ff
commit
fbf0b6b47f
23 changed files with 1547 additions and 10408 deletions
|
@ -7,7 +7,6 @@ QBCore.UsableItems = {}
|
|||
-- Get your player first and then trigger a function on them
|
||||
-- ex: local player = QBCore.Functions.GetPlayer(source)
|
||||
-- ex: local example = player.Functions.functionname(parameter)
|
||||
|
||||
---Gets the coordinates of an entity
|
||||
---@param entity number
|
||||
---@return vector4
|
||||
|
@ -133,15 +132,21 @@ function QBCore.Functions.GetQBPlayers()
|
|||
return QBCore.Players
|
||||
end
|
||||
|
||||
---Gets a list of all on duty players of a specified job and the number
|
||||
---@param job string
|
||||
---@return table, number
|
||||
function QBCore.Functions.GetPlayersOnDuty(job)
|
||||
--- Gets a list of all online players of a specified job or job type and the number
|
||||
--- @param job string
|
||||
--- @param checkOnDuty boolean If true, only players on duty will be returned
|
||||
function QBCore.Functions.GetPlayersByJob(job, checkOnDuty)
|
||||
local players = {}
|
||||
local count = 0
|
||||
for src, Player in pairs(QBCore.Players) do
|
||||
if Player.PlayerData.job.name == job then
|
||||
if Player.PlayerData.job.onduty then
|
||||
local playerData = Player.PlayerData
|
||||
if playerData.job.name == job or playerData.job.type == job then
|
||||
if checkOnDuty then
|
||||
if playerData.job.onduty then
|
||||
players[#players + 1] = src
|
||||
count += 1
|
||||
end
|
||||
else
|
||||
players[#players + 1] = src
|
||||
count += 1
|
||||
end
|
||||
|
@ -150,18 +155,19 @@ function QBCore.Functions.GetPlayersOnDuty(job)
|
|||
return players, count
|
||||
end
|
||||
|
||||
---Gets a list of all on duty players of a specified job and the number
|
||||
---@param job string
|
||||
---@return table, number
|
||||
function QBCore.Functions.GetPlayersOnDuty(job)
|
||||
local players, count = QBCore.Functions.GetPlayersByJob(job, true)
|
||||
return players, count
|
||||
end
|
||||
|
||||
---Returns only the amount of players on duty for the specified job
|
||||
---@param job string
|
||||
---@return number
|
||||
function QBCore.Functions.GetDutyCount(job)
|
||||
local count = 0
|
||||
for _, Player in pairs(QBCore.Players) do
|
||||
if Player.PlayerData.job.name == job then
|
||||
if Player.PlayerData.job.onduty then
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
local _, count = QBCore.Functions.GetPlayersByJob(job, true)
|
||||
return count
|
||||
end
|
||||
|
||||
|
@ -395,33 +401,32 @@ function QBCore.Functions.CreateVehicle(source, model, vehtype, coords, warp)
|
|||
end
|
||||
|
||||
function PaycheckInterval()
|
||||
if next(QBCore.Players) then
|
||||
for _, Player in pairs(QBCore.Players) do
|
||||
if Player then
|
||||
local payment = Player.PlayerData.job.payment
|
||||
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
|
||||
if QBCore.Config.Money.PayCheckSociety then
|
||||
local account = exports['qb-management']:GetAccount(Player.PlayerData.job.name)
|
||||
if account ~= 0 then -- Checks if player is employed by a society
|
||||
if account < payment then -- Checks if company has enough money to pay society
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
|
||||
else
|
||||
Player.Functions.AddMoney('bank', payment)
|
||||
exports['qb-management']:RemoveMoney(Player.PlayerData.job.name, payment)
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
|
||||
TriggerEvent('okokBanking:AddTransferTransactionFromSocietyToP', payment, "salary", "Salary", Player.PlayerData.citizenid, Player.PlayerData.charinfo.firstname..' '..Player.PlayerData.charinfo.lastname)
|
||||
end
|
||||
else
|
||||
Player.Functions.AddMoney('bank', payment)
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
|
||||
TriggerEvent('okokBanking:AddTransferTransactionFromSocietyToP', payment, "salary", "Salary", Player.PlayerData.citizenid, Player.PlayerData.charinfo.firstname..' '..Player.PlayerData.charinfo.lastname)
|
||||
end
|
||||
if not next(QBCore.Players) then
|
||||
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval) -- Prevent paychecks from stopping forever once 0 players
|
||||
return
|
||||
end
|
||||
for _, Player in pairs(QBCore.Players) do
|
||||
if not Player then return end
|
||||
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
|
||||
if not payment then payment = Player.PlayerData.job.payment end
|
||||
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
|
||||
if QBCore.Config.Money.PayCheckSociety then
|
||||
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
||||
if account ~= 0 then
|
||||
if account < payment then
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
|
||||
else
|
||||
Player.Functions.AddMoney('bank', payment)
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
|
||||
TriggerEvent('okokBanking:AddTransferTransactionFromSocietyToP', payment, "salary", "Salary", Player.PlayerData.citizenid, Player.PlayerData.charinfo.firstname..' '..Player.PlayerData.charinfo.lastname)
|
||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||
end
|
||||
else
|
||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||
end
|
||||
else
|
||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -470,7 +475,26 @@ end
|
|||
---@param item string
|
||||
---@param data function
|
||||
function QBCore.Functions.CreateUseableItem(item, data)
|
||||
QBCore.UsableItems[item] = data
|
||||
local rawFunc = nil
|
||||
|
||||
if type(data) == 'table' then
|
||||
if rawget(data, '__cfx_functionReference') then
|
||||
rawFunc = data
|
||||
elseif data.cb and rawget(data.cb, '__cfx_functionReference') then
|
||||
rawFunc = data.cb
|
||||
elseif data.callback and rawget(data.callback, '__cfx_functionReference') then
|
||||
rawFunc = data.callback
|
||||
end
|
||||
elseif type(data) == 'function' then
|
||||
rawFunc = data
|
||||
end
|
||||
|
||||
if rawFunc then
|
||||
QBCore.UsableItems[item] = {
|
||||
func = rawFunc,
|
||||
resource = GetInvokingResource()
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
---Checks if the given item is usable
|
||||
|
@ -484,8 +508,8 @@ end
|
|||
---@param source any
|
||||
---@param item string
|
||||
function QBCore.Functions.UseItem(source, item)
|
||||
if GetResourceState('qs-inventory') == 'missing' then return end
|
||||
exports['qs-inventory']:UseItem(source, item)
|
||||
if GetResourceState('qb-inventory') == 'missing' then return end
|
||||
exports['qb-inventory']:UseItem(source, item)
|
||||
end
|
||||
|
||||
---Kick Player
|
||||
|
@ -681,8 +705,8 @@ end
|
|||
---@param amount number
|
||||
---@return boolean
|
||||
function QBCore.Functions.HasItem(source, items, amount)
|
||||
if GetResourceState('qs-inventory') == 'missing' then return end
|
||||
return exports['qs-inventory']:HasItem(source, items, amount)
|
||||
if GetResourceState('qb-inventory') == 'missing' then return end
|
||||
return exports['qb-inventory']:HasItem(source, items, amount)
|
||||
end
|
||||
|
||||
---Notify
|
||||
|
@ -716,6 +740,5 @@ for functionName, func in pairs(QBCore.Functions) do
|
|||
exports(functionName, func)
|
||||
end
|
||||
end
|
||||
|
||||
-- Access a specific function directly:
|
||||
-- exports['qb-core']:Notify(source, 'Hello Player!')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue