mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 16:23:21 +00:00
chore(styling): ensure consistent indentation & define editorconfig
This commit is contained in:
+160
-154
@@ -1,40 +1,40 @@
|
||||
-- Event Handler
|
||||
|
||||
AddEventHandler('playerDropped', function()
|
||||
local src = source
|
||||
if QBCore.Players[src] then
|
||||
local Player = QBCore.Players[src]
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**'.. GetPlayerName(src) .. '** ('..Player.PlayerData.license..') left..')
|
||||
Player.Functions.Save()
|
||||
QBCore.Players[src] = nil
|
||||
end
|
||||
local src = source
|
||||
if QBCore.Players[src] then
|
||||
local Player = QBCore.Players[src]
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..')
|
||||
Player.Functions.Save()
|
||||
QBCore.Players[src] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler('chatMessage', function(source, n, message)
|
||||
local src = source
|
||||
if string.sub(message, 1, 1) == '/' then
|
||||
local args = QBCore.Shared.SplitStr(message, ' ')
|
||||
local command = string.gsub(args[1]:lower(), '/', '')
|
||||
CancelEvent()
|
||||
if QBCore.Commands.List[command] then
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local isGod = QBCore.Functions.HasPermission(src, 'god')
|
||||
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
|
||||
local isPrincipal = IsPlayerAceAllowed(src, 'command')
|
||||
table.remove(args, 1)
|
||||
if isGod or hasPerm or isPrincipal then
|
||||
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'All arguments must be filled out!', 'error')
|
||||
else
|
||||
QBCore.Commands.List[command].callback(src, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'No Access To This Command', 'error')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local src = source
|
||||
if string.sub(message, 1, 1) == '/' then
|
||||
local args = QBCore.Shared.SplitStr(message, ' ')
|
||||
local command = string.gsub(args[1]:lower(), '/', '')
|
||||
CancelEvent()
|
||||
if QBCore.Commands.List[command] then
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local isGod = QBCore.Functions.HasPermission(src, 'god')
|
||||
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
|
||||
local isPrincipal = IsPlayerAceAllowed(src, 'command')
|
||||
table.remove(args, 1)
|
||||
if isGod or hasPerm or isPrincipal then
|
||||
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'All arguments must be filled out!', 'error')
|
||||
else
|
||||
QBCore.Commands.List[command].callback(src, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'No Access To This Command', 'error')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Player Connecting
|
||||
@@ -72,7 +72,7 @@ local function OnPlayerConnecting(name, setKickReason, deferrals)
|
||||
if not license then
|
||||
deferrals.done('No Valid Rockstar License Found')
|
||||
elseif isBanned then
|
||||
deferrals.done(Reason)
|
||||
deferrals.done(Reason)
|
||||
elseif isLicenseAlreadyInUse then
|
||||
deferrals.done('Duplicate Rockstar License Found')
|
||||
else
|
||||
@@ -88,19 +88,19 @@ AddEventHandler('playerConnecting', OnPlayerConnecting)
|
||||
-- Open & Close Server (prevents players from joining)
|
||||
|
||||
RegisterNetEvent('QBCore:server:CloseServer', function(reason)
|
||||
local src = source
|
||||
local src = source
|
||||
if QBCore.Functions.HasPermission(src, 'admin') or QBCore.Functions.HasPermission(src, 'god') then
|
||||
local reason = reason or 'No reason specified'
|
||||
QBCore.Config.Server.closed = true
|
||||
QBCore.Config.Server.closedReason = reason
|
||||
TriggerClientEvent('qbadmin:client:SetServerStatus', -1, true)
|
||||
else
|
||||
QBCore.Functions.Kick(src, 'You don\'t have permissions for this..', nil, nil)
|
||||
else
|
||||
QBCore.Functions.Kick(src, 'You don\'t have permissions for this..', nil, nil)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:server:OpenServer', function()
|
||||
local src = source
|
||||
local src = source
|
||||
if QBCore.Functions.HasPermission(src, 'admin') or QBCore.Functions.HasPermission(src, 'god') then
|
||||
QBCore.Config.Server.closed = false
|
||||
TriggerClientEvent('qbadmin:client:SetServerStatus', -1, false)
|
||||
@@ -112,159 +112,165 @@ end)
|
||||
-- Callbacks
|
||||
|
||||
RegisterNetEvent('QBCore:Server:TriggerCallback', function(name, ...)
|
||||
local src = source
|
||||
QBCore.Functions.TriggerCallback(name, src, function(...)
|
||||
TriggerClientEvent('QBCore:Client:TriggerCallback', src, name, ...)
|
||||
end, ...)
|
||||
local src = source
|
||||
QBCore.Functions.TriggerCallback(name, src, function(...)
|
||||
TriggerClientEvent('QBCore:Client:TriggerCallback', src, name, ...)
|
||||
end, ...)
|
||||
end)
|
||||
|
||||
-- Player
|
||||
|
||||
RegisterNetEvent('QBCore:UpdatePlayer', function()
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local newHunger = Player.PlayerData.metadata['hunger'] - QBCore.Config.Player.HungerRate
|
||||
local newThirst = Player.PlayerData.metadata['thirst'] - QBCore.Config.Player.ThirstRate
|
||||
if newHunger <= 0 then newHunger = 0 end
|
||||
if newThirst <= 0 then newThirst = 0 end
|
||||
Player.Functions.SetMetaData('thirst', newThirst)
|
||||
Player.Functions.SetMetaData('hunger', newHunger)
|
||||
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, newThirst)
|
||||
Player.Functions.Save()
|
||||
end
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local newHunger = Player.PlayerData.metadata['hunger'] - QBCore.Config.Player.HungerRate
|
||||
local newThirst = Player.PlayerData.metadata['thirst'] - QBCore.Config.Player.ThirstRate
|
||||
if newHunger <= 0 then
|
||||
newHunger = 0
|
||||
end
|
||||
if newThirst <= 0 then
|
||||
newThirst = 0
|
||||
end
|
||||
Player.Functions.SetMetaData('thirst', newThirst)
|
||||
Player.Functions.SetMetaData('hunger', newHunger)
|
||||
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, newThirst)
|
||||
Player.Functions.Save()
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Server:SetMetaData', function(meta, data)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if meta == 'hunger' or meta == 'thirst' then
|
||||
if data > 100 then
|
||||
data = 100
|
||||
end
|
||||
end
|
||||
if Player then
|
||||
Player.Functions.SetMetaData(meta, data)
|
||||
end
|
||||
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata['hunger'], Player.PlayerData.metadata['thirst'])
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if meta == 'hunger' or meta == 'thirst' then
|
||||
if data > 100 then
|
||||
data = 100
|
||||
end
|
||||
end
|
||||
if Player then
|
||||
Player.Functions.SetMetaData(meta, data)
|
||||
end
|
||||
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata['hunger'], Player.PlayerData.metadata['thirst'])
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:ToggleDuty', function()
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player.PlayerData.job.onduty then
|
||||
Player.Functions.SetJobDuty(false)
|
||||
TriggerClientEvent('QBCore:Notify', src, 'You are now off duty!')
|
||||
else
|
||||
Player.Functions.SetJobDuty(true)
|
||||
TriggerClientEvent('QBCore:Notify', src, 'You are now on duty!')
|
||||
end
|
||||
TriggerClientEvent('QBCore:Client:SetDuty', src, Player.PlayerData.job.onduty)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player.PlayerData.job.onduty then
|
||||
Player.Functions.SetJobDuty(false)
|
||||
TriggerClientEvent('QBCore:Notify', src, 'You are now off duty!')
|
||||
else
|
||||
Player.Functions.SetJobDuty(true)
|
||||
TriggerClientEvent('QBCore:Notify', src, 'You are now on duty!')
|
||||
end
|
||||
TriggerClientEvent('QBCore:Client:SetDuty', src, Player.PlayerData.job.onduty)
|
||||
end)
|
||||
|
||||
-- Items
|
||||
|
||||
RegisterNetEvent('QBCore:Server:UseItem', function(item)
|
||||
local src = source
|
||||
if item and item.amount > 0 then
|
||||
if QBCore.Functions.CanUseItem(item.name) then
|
||||
QBCore.Functions.UseItem(src, item)
|
||||
end
|
||||
end
|
||||
local src = source
|
||||
if item and item.amount > 0 then
|
||||
if QBCore.Functions.CanUseItem(item.name) then
|
||||
QBCore.Functions.UseItem(src, item)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Server:RemoveItem', function(itemName, amount, slot)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
Player.Functions.RemoveItem(itemName, amount, slot)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
Player.Functions.RemoveItem(itemName, amount, slot)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Server:AddItem', function(itemName, amount, slot, info)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
Player.Functions.AddItem(itemName, amount, slot, info)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
Player.Functions.AddItem(itemName, amount, slot, info)
|
||||
end)
|
||||
|
||||
-- Non-Chat Command Calling (ex: qb-adminmenu)
|
||||
|
||||
RegisterNetEvent('QBCore:CallCommand', function(command, args)
|
||||
local src = source
|
||||
if QBCore.Commands.List[command] then
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local isGod = QBCore.Functions.HasPermission(src, 'god')
|
||||
local src = source
|
||||
if QBCore.Commands.List[command] then
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local isGod = QBCore.Functions.HasPermission(src, 'god')
|
||||
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
|
||||
local isPrincipal = IsPlayerAceAllowed(src, 'command')
|
||||
if (QBCore.Commands.List[command].permission == Player.PlayerData.job.name) or isGod or hasPerm or isPrincipal then
|
||||
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'All arguments must be filled out!', 'error')
|
||||
else
|
||||
QBCore.Commands.List[command].callback(src, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'No Access To This Command', 'error')
|
||||
end
|
||||
end
|
||||
end
|
||||
if (QBCore.Commands.List[command].permission == Player.PlayerData.job.name) or isGod or hasPerm or isPrincipal then
|
||||
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'All arguments must be filled out!', 'error')
|
||||
else
|
||||
QBCore.Commands.List[command].callback(src, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'No Access To This Command', 'error')
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Has Item Callback (can also use client function - QBCore.Functions.HasItem(item))
|
||||
|
||||
QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, amount)
|
||||
local src = source
|
||||
local retval = false
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
if type(items) == 'table' then
|
||||
local count = 0
|
||||
local src = source
|
||||
local retval = false
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
if type(items) == 'table' then
|
||||
local count = 0
|
||||
local finalcount = 0
|
||||
for k, v in pairs(items) do
|
||||
if type(k) == 'string' then
|
||||
finalcount = 0
|
||||
for i, _ in pairs(items) do
|
||||
if i then finalcount = finalcount + 1 end
|
||||
end
|
||||
local item = Player.Functions.GetItemByName(k)
|
||||
if item then
|
||||
if item.amount >= v then
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for k, v in pairs(items) do
|
||||
if type(k) == 'string' then
|
||||
finalcount = 0
|
||||
for i, _ in pairs(items) do
|
||||
if i then
|
||||
finalcount = finalcount + 1
|
||||
end
|
||||
end
|
||||
local item = Player.Functions.GetItemByName(k)
|
||||
if item then
|
||||
if item.amount >= v then
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
finalcount = #items
|
||||
local item = Player.Functions.GetItemByName(v)
|
||||
if item then
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
else
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local item = Player.Functions.GetItemByName(items)
|
||||
if item then
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
retval = true
|
||||
end
|
||||
else
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
cb(retval)
|
||||
local item = Player.Functions.GetItemByName(v)
|
||||
if item then
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
else
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local item = Player.Functions.GetItemByName(items)
|
||||
if item then
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
retval = true
|
||||
end
|
||||
else
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
cb(retval)
|
||||
end)
|
||||
Reference in New Issue
Block a user