Skip to content

Commit

Permalink
feat(config): Standarize Config files
Browse files Browse the repository at this point in the history
  • Loading branch information
FjamZoo committed Nov 15, 2023
1 parent a7c3ff6 commit 9e528c4
Show file tree
Hide file tree
Showing 22 changed files with 309 additions and 238 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
7 changes: 5 additions & 2 deletions client/character.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
local Config = require 'config.client'
local DefaultSpawn = require 'config.shared'.DefaultSpawn

if Config.Characters.UseExternalCharacters then return end

local previewCam = nil
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 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('qbox_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)
175 changes: 0 additions & 175 deletions config.lua

This file was deleted.

68 changes: 68 additions & 0 deletions config/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
return {
StatusInterval = 5, -- how often to check hunger/thirst status in minutes
LoadingModelsTimeout = 10000, -- Waiting time for ox_lib to load the models before throws an error, for low specs pc

PauseMapText = 'Powered by Qbox', -- Text shown above the map when ESC is pressed. If left empty 'FiveM' will appear

Characters = {
UseExternalCharacters = false, -- Whether you have an external character management resource. (If true, disables the character management inside the core)
EnableDeleteButton = true, -- Whether players should be able to delete characters themselves.
StartingApartment = true, -- If set to false, skips apartment choice in the beginning (requires qbx_spawn if true)

ProfanityWords = {
['bad word'] = true
},

Locations = { -- Spawn locations for multichar, these are chosen randomly
{
pedCoords = vec4(969.25, 72.61, 116.18, 276.55),
camCoords = vec4(972.2, 72.9, 116.68, 97.27),
},
{
pedCoords = vec4(1104.49, 195.9, -49.44, 44.22),
camCoords = vec4(1102.29, 198.14, -48.86, 225.07),
},
{
pedCoords = vec4(-2163.87, 1134.51, -24.37, 310.05),
camCoords = vec4(-2161.7, 1136.4, -23.77, 131.52),
},
{
pedCoords = vec4(-996.71, -68.07, -99.0, 57.61),
camCoords = vec4(-999.90, -66.30, -98.45, 241.68),
},
{
pedCoords = vec4(-1023.45, -418.42, 67.66, 205.69),
camCoords = vec4(-1021.8, -421.7, 68.14, 27.11),
},
{
pedCoords = vec4(2265.27, 2925.02, -84.8, 267.77),
camCoords = vec4(2268.24, 2925.02, -84.36, 90.88),
}
},

},

Discord = {
AppId = '', -- This is the Application ID (Replace this with you own)

LargeIcon = { -- To set this up, visit https://forum.cfx.re/t/how-to-updated-discord-rich-presence-custom-image/157686
icon = 'logo_name', -- Here you will have to put the image name for the 'large' icon.
text = 'This is a large icon with text', -- Here you can add hover text for the 'large' icon.
},

SmallIcon = {
icon = 'logo_name', -- Here you will have to put the image name for the 'small' icon.
text = 'This is a small icon with text', -- Here you can add hover text for the 'small' icon.
},

FirstButton = {
text = 'First Button!',
link = 'fivem://connect/localhost:30120',
},

SecondButton = {
text = 'Second Button!',
link = 'fivem://connect/localhost:30120',
}
}
}
Loading

0 comments on commit 9e528c4

Please sign in to comment.