Skip to content

Commit

Permalink
feat(config): Standarize Config files
Browse files Browse the repository at this point in the history
* feat(config): Standarize Config files

* Fix(linting): Use Config variable

* camalCase

* camalCase V2
  • Loading branch information
FjamZoo authored Nov 15, 2023
1 parent a7c3ff6 commit 169016f
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 269 deletions.
2 changes: 1 addition & 1 deletion bridge/qb/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local qbCoreCompat = {}
qbCoreCompat.PlayerData = QBX.PlayerData
qbCoreCompat.Config = Config
qbCoreCompat.Config = lib.table.merge(require 'config.client', require 'config.shared')
qbCoreCompat.Shared = require 'bridge.qb.shared.main'
qbCoreCompat.Functions = require 'bridge.qb.client.functions'

Expand Down
2 changes: 1 addition & 1 deletion bridge/qb/server/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local qbCoreCompat = {}

qbCoreCompat.Config = Config
qbCoreCompat.Config = lib.table.merge(require 'config.server', require 'config.shared')
qbCoreCompat.Shared = require 'bridge.qb.shared.main'
qbCoreCompat.Players = QBX.Players
qbCoreCompat.Player = require 'bridge.qb.server.player'
Expand Down
29 changes: 16 additions & 13 deletions client/character.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
if Config.Characters.UseExternalCharacters then return end
local config = require 'config.client'
local defaultSpawn = require 'config.shared'.DefaultSpawn

if config.Characters.UseExternalCharacters then return end

local previewCam = nil
local randomLocation = Config.Characters.Locations[math.random(1, #Config.Characters.Locations)]
local randomLocation = config.Characters.Locations[math.random(1, #config.Characters.Locations)]

local randomPedModels = {
`a_m_o_soucent_02`,
Expand Down Expand Up @@ -50,19 +53,19 @@ end
local function previewPed(citizenId)
if not citizenId then
local model = randomPedModels[math.random(1, #randomPedModels)]
lib.requestModel(model, Config.LoadingModelsTimeout)
lib.requestModel(model, config.LoadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
return
end

local clothing, model = lib.callback.await('qbx_core:server:getPreviewPedData', false, citizenId)
if model and clothing then
lib.requestModel(model, Config.LoadingModelsTimeout)
lib.requestModel(model, config.LoadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
pcall(function() exports['illenium-appearance']:setPedAppearance(PlayerPedId(), json.decode(clothing)) end)
else
model = randomPedModels[math.random(1, #randomPedModels)]
lib.requestModel(model, Config.LoadingModelsTimeout)
lib.requestModel(model, config.LoadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
end
end
Expand Down Expand Up @@ -133,14 +136,14 @@ end
---@return boolean
local function checkStrings(dialog, input)
local str = dialog[input]
if Config.Characters.ProfanityWords[str:lower()] then return false end
if config.Characters.ProfanityWords[str:lower()] then return false end

local split = {string.strsplit(' ', str)}
if #split > 5 then return false end

for i = 1, #split do
local word = split[i]
if Config.Characters.ProfanityWords[word:lower()] then return false end
if config.Characters.ProfanityWords[word:lower()] then return false end
end

return true
Expand Down Expand Up @@ -235,7 +238,7 @@ local function createCharacter(cid)
spawnDefault()
TriggerEvent('qb-clothes:client:CreateFirstCharacter')
else
if Config.Characters.StartingApartment then
if config.Characters.StartingApartment then
TriggerEvent('apartments:client:setupSpawnUI', newData)
else
TriggerEvent('qbx_core:client:spawnNoApartments')
Expand All @@ -247,7 +250,7 @@ local function createCharacter(cid)
end

local function chooseCharacter()
randomLocation = Config.Characters.Locations[math.random(1, #Config.Characters.Locations)]
randomLocation = config.Characters.Locations[math.random(1, #config.Characters.Locations)]

DoScreenFadeOut(500)

Expand Down Expand Up @@ -325,7 +328,7 @@ local function chooseCharacter()
destroyPreviewCam()
end
},
Config.Characters.EnableDeleteButton and {
config.Characters.EnableDeleteButton and {
title = Lang:t('info.delete_character'),
description = Lang:t('info.delete_character_description', { playerName = name }),
icon = 'trash',
Expand Down Expand Up @@ -364,8 +367,8 @@ end
RegisterNetEvent('qbx_core:client:spawnNoApartments', function() -- This event is only for no starting apartments
DoScreenFadeOut(500)
Wait(2000)
SetEntityCoords(cache.ped, Config.DefaultSpawn.x, Config.DefaultSpawn.y, Config.DefaultSpawn.z, false, false, false, false)
SetEntityHeading(cache.ped, Config.DefaultSpawn.w)
SetEntityCoords(cache.ped, defaultSpawn.x, defaultSpawn.y, defaultSpawn.z, false, false, false, false)
SetEntityHeading(cache.ped, defaultSpawn.w)
Wait(500)
destroyPreviewCam()
SetEntityVisible(cache.ped, true, false)
Expand All @@ -391,7 +394,7 @@ CreateThread(function()
if NetworkIsSessionStarted() then
pcall(function() exports.spawnmanager:setAutoSpawn(false) end)
Wait(250)
lib.requestModel(model, Config.LoadingModelsTimeout)
lib.requestModel(model, config.LoadingModelsTimeout)
SetPlayerModel(cache.playerId, model)
chooseCharacter()
break
Expand Down
24 changes: 14 additions & 10 deletions client/discord.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
local maxPlayers = GlobalState.MaxPlayers
local discord = require 'config.client'.Discord

AddStateBagChangeHandler('PlayerCount', nil, function(bagName, _, value)
if bagName ~= 'global' or not value then return end
local players = 'Players %s/' .. Config.MaxPlayers
SetRichPresence((players):format(value))
if bagName == 'global' and value then
local players = 'Players %s/' .. maxPlayers
SetRichPresence((players):format(value))
end
end)

SetDiscordAppId(Config.Discord.AppId)
SetDiscordRichPresenceAsset(Config.Discord.LargeIcon.icon)
SetDiscordRichPresenceAssetText(Config.Discord.LargeIcon.text)
SetDiscordRichPresenceAssetSmall(Config.Discord.SmallIcon.icon)
SetDiscordRichPresenceAssetSmallText(Config.Discord.SmallIcon.text)
SetDiscordRichPresenceAction(0, Config.Discord.FirstButton.text, Config.Discord.FirstButton.link)
SetDiscordRichPresenceAction(1, Config.Discord.SecondButton.text, Config.Discord.SecondButton.link)
SetDiscordAppId(discord.AppId)
SetDiscordRichPresenceAsset(discord.LargeIcon.icon)
SetDiscordRichPresenceAssetText(discord.LargeIcon.text)
SetDiscordRichPresenceAssetSmall(discord.SmallIcon.icon)
SetDiscordRichPresenceAssetSmallText(discord.SmallIcon.text)
SetDiscordRichPresenceAction(0, discord.FirstButton.text, discord.FirstButton.link)
SetDiscordRichPresenceAction(1, discord.SecondButton.text, discord.SecondButton.link)
36 changes: 15 additions & 21 deletions client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
ShutdownLoadingScreenNui()
LocalPlayer.state:set('isLoggedIn', true, false)
QBX.IsLoggedIn = true
if not Config.Server.PVP then return end
SetCanAttackFriendly(cache.ped, true, false)
NetworkSetFriendlyFireOption(true)

if GlobalState.PVPEnabled then
SetCanAttackFriendly(cache.ped, true, false)
NetworkSetFriendlyFireOption(true)
end
end)

---@param val PlayerData
Expand All @@ -19,10 +21,12 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
QBX.IsLoggedIn = false
end)

---@param pvp_state boolean
RegisterNetEvent('QBCore:Client:PvpHasToggled', function(pvp_state)
SetCanAttackFriendly(cache.ped, pvp_state, false)
NetworkSetFriendlyFireOption(pvp_state)
---@param value boolean
AddStateBagChangeHandler('PVPEnabled', nil, function(bagName, _, value)
if bagName == 'global' then
SetCanAttackFriendly(cache.ped, value, false)
NetworkSetFriendlyFireOption(value)
end
end)

-- Teleport Commands
Expand Down Expand Up @@ -141,20 +145,10 @@ RegisterNetEvent('qbx_core:client:vehicleSpawned', function(netId, props)
end
end)

RegisterNetEvent('QBCore:Command:DeleteVehicle', function()
if cache.vehicle then
SetEntityAsMissionEntity(cache.vehicle, true, true)
DeleteVehicle(cache.vehicle)
else
local pcoords = GetEntityCoords(cache.ped)
local vehicles = GetGamePool('CVehicle')
for _, v in pairs(vehicles) do
if #(pcoords - GetEntityCoords(v)) <= 5.0 then
SetEntityAsMissionEntity(v, true, true)
DeleteVehicle(v)
end
end
end
lib.callback.register('qbx_core:client:getNearestVehicle', function()
local vehicle = lib.getClosestVehicle(GetEntityCoords(cache.ped), 5)

return vehicle and VehToNet(vehicle)
end)

-- Other stuff
Expand Down
4 changes: 3 additions & 1 deletion client/functions.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local NotifyPosition = require 'config.shared'.NotifyPosition

---Text box popup for player which dissappears after a set time.
---@param text table|string text of the notification
---@param notifyType? NotificationType informs default styling. Defaults to 'inform'
Expand All @@ -18,7 +20,7 @@ function Notify(text, notifyType, duration, subTitle, notifyPosition, notifyStyl
else
description = text
end
local position = notifyPosition or Config.NotifyPosition
local position = notifyPosition or NotifyPosition

lib.notify({
id = title,
Expand Down
4 changes: 3 additions & 1 deletion client/loops.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local StatusInterval = require 'config.client'.StatusInterval

CreateThread(function()
local timeout = 60000 * Config.StatusInterval
local timeout = 60000 * StatusInterval
while true do
Wait(timeout)

Expand Down
2 changes: 1 addition & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ lib.callback.register('qbx_core:client:setHealth', function(health)
SetEntityHealth(cache.ped, health)
end)

local mapText = Config.Server.PauseMapText
local mapText = require 'config.client'.PauseMapText
if mapText == '' or type(mapText) ~= 'string' then mapText = 'FiveM' end
AddTextEntry('FE_THDR_GTAO', mapText)
Loading

0 comments on commit 169016f

Please sign in to comment.