style(server/events): indentation and ocd

This commit is contained in:
BerkieBb
2022-02-18 14:34:40 +01:00
committed by GitHub
parent 4cca898395
commit 25007c1bf4
+45 -62
View File
@@ -20,200 +20,184 @@ function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, perm
end
function QBCore.Commands.Refresh(source)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local Player = QBCore.Functions.GetPlayer(source)
local suggestions = {}
if Player then
for command, info in pairs(QBCore.Commands.List) do
local isGod = QBCore.Functions.HasPermission(src, 'god')
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
local isPrincipal = IsPlayerAceAllowed(src, 'command')
if isGod or hasPerm or isPrincipal then
suggestions[#suggestions + 1] = {
name = '/' .. command,
help = info.help,
params = info.arguments
}
end
if not Player then return end
for command, info in pairs(QBCore.Commands.List) do
local isGod = QBCore.Functions.HasPermission(source, 'god')
local hasPerm = QBCore.Functions.HasPermission(source, QBCore.Commands.List[command].permission)
local isPrincipal = IsPlayerAceAllowed(source, 'command')
if isGod or hasPerm or isPrincipal then
suggestions[#suggestions + 1] = {
name = '/' .. command,
help = info.help,
params = info.arguments
}
end
TriggerClientEvent('chat:addSuggestions', tonumber(source), suggestions)
end
TriggerClientEvent('chat:addSuggestions', source, suggestions)
end
-- Teleport
QBCore.Commands.Add('tp', 'TP To Player or Coords (Admin Only)', { { name = 'id/x', help = 'ID of player or X position' }, { name = 'y', help = 'Y position' }, { name = 'z', help = 'Z position' } }, false, function(source, args)
local src = source
if args[1] and not args[2] and not args[3] then
local target = GetPlayerPed(tonumber(args[1]))
if target ~= 0 then
local coords = GetEntityCoords(target)
TriggerClientEvent('QBCore:Command:TeleportToPlayer', src, coords)
TriggerClientEvent('QBCore:Command:TeleportToPlayer', source, coords)
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
else
if args[1] and args[2] and args[3] then
local x = tonumber(args[1])
local y = tonumber(args[2])
local z = tonumber(args[3])
if (x ~= 0) and (y ~= 0) and (z ~= 0) then
TriggerClientEvent('QBCore:Command:TeleportToCoords', src, x, y, z)
if x ~= 0 and y ~= 0 and z ~= 0 then
TriggerClientEvent('QBCore:Command:TeleportToCoords', source, x, y, z)
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.wrong_format'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.wrong_format'), 'error')
end
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.missing_args'), 'error')
end
end
end, 'admin')
QBCore.Commands.Add('tpm', 'TP To Marker (Admin Only)', {}, false, function(source)
local src = source
TriggerClientEvent('QBCore:Command:GoToMarker', src)
TriggerClientEvent('QBCore:Command:GoToMarker', source)
end, 'admin')
QBCore.Commands.Add('togglepvp', 'Toggle PVP on the server (Admin Only)', {}, false, function(source)
local src = source
QBCore.Commands.Add('togglepvp', 'Toggle PVP on the server (Admin Only)', {}, false, function()
local pvp_state = QBConfig.Server.pvp
QBConfig.Server.pvp = not pvp_state
TriggerClientEvent('QBCore:Client:PvpHasToggled', -1, QBConfig.Server.pvp)
end, 'admin')
-- Permissions
QBCore.Commands.Add('addpermission', 'Give Player Permissions (God Only)', { { name = 'id', help = 'ID of player' }, { name = 'permission', help = 'Permission level' } }, true, function(source, args)
local src = source
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local permission = tostring(args[2]):lower()
if Player then
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
end, 'god')
QBCore.Commands.Add('removepermission', 'Remove Players Permissions (God Only)', { { name = 'id', help = 'ID of player' } }, true, function(source, args)
local src = source
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player then
QBCore.Functions.RemovePermission(Player.PlayerData.source)
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
end, 'god')
-- Vehicle
QBCore.Commands.Add('car', 'Spawn Vehicle (Admin Only)', { { name = 'model', help = 'Model name of the vehicle' } }, true, function(source, args)
local src = source
TriggerClientEvent('QBCore:Command:SpawnVehicle', src, args[1])
TriggerClientEvent('QBCore:Command:SpawnVehicle', source, args[1])
end, 'admin')
QBCore.Commands.Add('dv', 'Delete Vehicle (Admin Only)', {}, false, function(source)
local src = source
TriggerClientEvent('QBCore:Command:DeleteVehicle', src)
TriggerClientEvent('QBCore:Command:DeleteVehicle', source)
end, 'admin')
-- Money
QBCore.Commands.Add('givemoney', 'Give A Player Money (Admin Only)', { { name = 'id', help = 'Player ID' }, { name = 'moneytype', help = 'Type of money (cash, bank, crypto)' }, { name = 'amount', help = 'Amount of money' } }, true, function(source, args)
local src = source
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player then
Player.Functions.AddMoney(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
end, 'admin')
QBCore.Commands.Add('setmoney', 'Set Players Money Amount (Admin Only)', { { name = 'id', help = 'Player ID' }, { name = 'moneytype', help = 'Type of money (cash, bank, crypto)' }, { name = 'amount', help = 'Amount of money' } }, true, function(source, args)
local src = source
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player then
Player.Functions.SetMoney(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
end, 'admin')
-- Job
QBCore.Commands.Add('job', 'Check Your Job', {}, false, function(source)
local src = source
local PlayerJob = QBCore.Functions.GetPlayer(src).PlayerData.job
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.job_info', {value = PlayerJob.label, value2 = PlayerJob.grade.name, value3 = PlayerJob.onduty}))
local PlayerJob = QBCore.Functions.GetPlayer(source).PlayerData.job
TriggerClientEvent('QBCore:Notify', source, Lang:t('info.job_info', {value = PlayerJob.label, value2 = PlayerJob.grade.name, value3 = PlayerJob.onduty}))
end, 'user')
QBCore.Commands.Add('setjob', 'Set A Players Job (Admin Only)', { { name = 'id', help = 'Player ID' }, { name = 'job', help = 'Job name' }, { name = 'grade', help = 'Grade' } }, true, function(source, args)
local src = source
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player then
Player.Functions.SetJob(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
end, 'admin')
-- Gang
QBCore.Commands.Add('gang', 'Check Your Gang', {}, false, function(source)
local src = source
local PlayerGang = QBCore.Functions.GetPlayer(source).PlayerData.gang
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.gang_info', {value = PlayerGang.label, value2 = PlayerGang.grade.name}))
TriggerClientEvent('QBCore:Notify', source, Lang:t('info.gang_info', {value = PlayerGang.label, value2 = PlayerGang.grade.name}))
end, 'user')
QBCore.Commands.Add('setgang', 'Set A Players Gang (Admin Only)', { { name = 'id', help = 'Player ID' }, { name = 'gang', help = 'Name of a gang' }, { name = 'grade', help = 'Grade' } }, true, function(source, args)
local src = source
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player then
Player.Functions.SetGang(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
end, 'admin')
-- Inventory (should be in qb-inventory?)
QBCore.Commands.Add('clearinv', 'Clear Players Inventory (Admin Only)', { { name = 'id', help = 'Player ID' } }, false, function(source, args)
local src = source
local playerId = args[1] or src
local playerId = args[1] and args[1] ~= '' or source
local Player = QBCore.Functions.GetPlayer(tonumber(playerId))
if Player then
Player.Functions.ClearInventory()
else
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
end
end, 'admin')
-- Out of Character Chat
QBCore.Commands.Add('ooc', 'OOC Chat Message', {}, false, function(source, args)
local src = source
local message = table.concat(args, ' ')
local Players = QBCore.Functions.GetPlayers()
local Player = QBCore.Functions.GetPlayer(src)
local Player = QBCore.Functions.GetPlayer(source)
local playerCoords = GetEntityCoords(GetPlayerPed(source))
for k, v in pairs(Players) do
if v == src then
if v == source then
TriggerClientEvent('chat:addMessage', v, {
color = { 0, 0, 255},
multiline = true,
args = {'OOC | '.. GetPlayerName(src), message}
args = {'OOC | '.. GetPlayerName(source), message}
})
elseif #(GetEntityCoords(GetPlayerPed(src)) - GetEntityCoords(GetPlayerPed(v))) < 20.0 then
elseif #(playerCoords - GetEntityCoords(GetPlayerPed(v))) < 20.0 then
TriggerClientEvent('chat:addMessage', v, {
color = { 0, 0, 255},
multiline = true,
args = {'OOC | '.. GetPlayerName(src), message}
args = {'OOC | '.. GetPlayerName(source), message}
})
elseif QBCore.Functions.HasPermission(v, 'admin') then
if QBCore.Functions.IsOptin(v) then
TriggerClientEvent('chat:addMessage', v, {
color = { 0, 0, 255},
multiline = true,
args = {'Proxmity OOC | '.. GetPlayerName(src), message}
args = {'Proxmity OOC | '.. GetPlayerName(source), message}
})
TriggerEvent('qb-log:server:CreateLog', 'ooc', 'OOC', 'white', '**' .. GetPlayerName(src) .. '** (CitizenID: ' .. Player.PlayerData.citizenid .. ' | ID: ' .. src .. ') **Message:** ' .. message, false)
TriggerEvent('qb-log:server:CreateLog', 'ooc', 'OOC', 'white', '**' .. GetPlayerName(source) .. '** (CitizenID: ' .. Player.PlayerData.citizenid .. ' | ID: ' .. source .. ') **Message:** ' .. message, false)
end
end
end
@@ -222,8 +206,7 @@ end, 'user')
-- Me command
QBCore.Commands.Add('me', 'Show local message', {{name = 'message', help = 'Message to respond with'}}, false, function(source, args)
local src = source
local ped = GetPlayerPed(src)
local ped = GetPlayerPed(source)
local pCoords = GetEntityCoords(ped)
local msg = table.concat(args, ' ')
if msg == '' then return end
@@ -231,7 +214,7 @@ QBCore.Commands.Add('me', 'Show local message', {{name = 'message', help = 'Mess
local target = GetPlayerPed(v)
local tCoords = GetEntityCoords(target)
if #(pCoords - tCoords) < 20 then
TriggerClientEvent('QBCore:Command:ShowMe3D', v, src, msg)
TriggerClientEvent('QBCore:Command:ShowMe3D', v, source, msg)
end
end
end, 'user')