Skip to content

Commit

Permalink
V1.2 - separate config for server/client, more configurables
Browse files Browse the repository at this point in the history
  • Loading branch information
Gravxd committed Mar 16, 2024
1 parent 7335d47 commit c1628ca
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 45 deletions.
19 changes: 4 additions & 15 deletions chroma-enginesoundmenu/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ for k, v in pairs(Config.EngineSounds) do
DisplayLabels[#DisplayLabels + 1] = k
end

local function Notify(msg, type)
-- you can edit this to whatever you want, by default it uses ox_lib notifications
lib.notify({
title = 'chroma-enginesoundmenu',
description = msg,
type = type,
position = 'center-right',
})
end

local Index = 1
lib.registerMenu({
id = 'engine_sound_menu',
title = 'Engine Sound Menu',
position = 'bottom-right',
position = Config.MenuPosition,
onSideScroll = function(selected, scrollIndex, args)
Index = scrollIndex
end,
Expand All @@ -26,21 +16,21 @@ lib.registerMenu({
}
}, function(selected, scrollIndex, args)
if not cache.vehicle or cache.seat ~= -1 then
return Notify('You need to be driving a vehicle to use this!', 'error')
return Config.Notify('You need to be driving a vehicle to use this!', 'error')
end

TriggerServerEvent('Chroma:EngineSounds:ChangeEngineSound', {
net = VehToNet(cache.vehicle),
sound = Config.EngineSounds[DisplayLabels[scrollIndex]]
})

Notify(string.format('Engine sound changed to: %s', DisplayLabels[scrollIndex]), 'success')
Config.Notify(string.format('Engine sound changed to: %s', DisplayLabels[scrollIndex]), 'success')

end)

RegisterNetEvent("Chroma:EngineSounds:OpenMenu", function()
if not cache.vehicle or cache.seat ~= -1 then
return Notify('You need to be driving a vehicle to use this!', 'error')
return Config.Notify('You need to be driving a vehicle to use this!', 'error')
end

lib.setMenuOptions('engine_sound_menu', { label = 'Change Engine Sound', icon = 'arrows-up-down-left-right', values = DisplayLabels, defaultIndex = Index }, 1)
Expand All @@ -51,7 +41,6 @@ end)
AddStateBagChangeHandler("vehdata:sound", nil, function(bagName, key, value)
local entity = GetEntityFromStateBagName(bagName)
if entity == 0 then return end

ForceUseAudioGameObject(entity, value)
end)

Expand Down
17 changes: 17 additions & 0 deletions chroma-enginesoundmenu/client_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Config = {
Keybind = "", -- E.G F7 ---> https://docs.fivem.net/docs/game-references/controls/
MenuPosition = "bottom-right", -- bottom-right, bottom-left, top-right, top-left
Notify = function(msg, type)
-- customise this notification function to whatever you desire - by default it uses ox_lib but you can edit this
lib.notify({
title = 'chroma-enginesoundmenu',
description = msg,
type = type,
position = 'center-right',
})
end,
EngineSounds = {
-- Engine Sound Name/Label --> Hash of engine audio (what you'd normally put in vehicles.meta)
['BMW S63 4.4L V8'] = 's63b44',
},
}
7 changes: 0 additions & 7 deletions chroma-enginesoundmenu/config.lua

This file was deleted.

5 changes: 3 additions & 2 deletions chroma-enginesoundmenu/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ shared_script '@ox_lib/init.lua'
lua54 'yes'

client_scripts {
'config.lua',
'client_config.lua',
'client.lua',
}

server_scripts {
'server_config.lua',
'server.lua',
}

dependency 'ox_lib'

author 'Grav'
version '1.1'
version '1.2'
description 'Engine sound menu that syncs to other players'
47 changes: 27 additions & 20 deletions chroma-enginesoundmenu/server.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
local function HasPermission(src)
-- your permission function here - you can integrate your framework for jobs/perms etc
return IsPlayerAceAllowed(src, 'enginesoundmenu')
end

local function Notify(src, msg, type)
-- you can edit this to whatever you want, by default it uses ox_lib notifications
TriggerClientEvent("ox_lib:notify", src, {
description = msg,
title = 'chroma-enginesoundmenu',
type = type,
position = 'center-right',
})
end

RegisterCommand("enginesound", function(source, args, rawCommand)
if HasPermission(source) then
if Config.HasPermission(source) then
TriggerClientEvent("Chroma:EngineSounds:OpenMenu", source)
else
Notify(source, 'You do not have permission to use this command!', 'error')
Config.Notify(source, 'You do not have permission to use this command!', 'error')
end
end, false)

RegisterServerEvent("Chroma:EngineSounds:ChangeEngineSound", function(data)

local entity = NetworkGetEntityFromNetworkId(data.net)
if not DoesEntityExist(entity) then return end

Entity(entity).state['vehdata:sound'] = data.sound

end)

CreateThread(function()

if Config.CheckForUpdates then

-- https://github.com/Blumlaut/FiveM-Resource-Version-Check-Thing/
updatePath = "/Gravxd/fivem-enginesound-menu" -- your git user/repo path
resourceName = "^6chroma-enginesoundmenu" -- the resource name

local function checkVersion(err,responseText, headers)
curVersion = LoadResourceFile(GetCurrentResourceName(), "version.txt") -- make sure the "version" file actually exists in your resource root!
if curVersion ~= responseText and tonumber(curVersion) < tonumber(responseText) then
print("\n"..resourceName.." ^1is outdated, please update it from:\n^3https://github.com/Gravxd/fivem-enginesound-menu/releases/latest\n^1For support or issues, please visit ^3https://discord.gg/chromalabs^7")
else
print("\n"..resourceName.." ^2is up to date, and has been loaded - enjoy!\nFor support or issues, please visit ^3https://discord.gg/chromalabs^7")
end
end

PerformHttpRequest("https://raw.githubusercontent.com"..updatePath.."/main/chroma-enginesoundmenu/version.txt", checkVersion, "GET")

else
print("\n^6chroma-enginesoundmenu ^2has been loaded - enjoy! ^1[VERSION CHECK DISABLED]\n^2For support or issues, please visit ^3https://discord.gg/chromalabs^7")
end

end)
16 changes: 16 additions & 0 deletions chroma-enginesoundmenu/server_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Config = {
CheckForUpdates = true, -- will check github for updates (recommended)
HasPermission = function(src)
-- your permission function here - you can integrate your framework for jobs/perms etc
return IsPlayerAceAllowed(src, 'enginesoundmenu')
end,
Notify = function(src, msg, type)
-- you can edit this to whatever you want, by default it uses ox_lib notifications
TriggerClientEvent("ox_lib:notify", src, {
description = msg,
title = 'chroma-enginesoundmenu',
type = type,
position = 'center-right',
})
end,
}
2 changes: 1 addition & 1 deletion chroma-enginesoundmenu/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1
1.2

0 comments on commit c1628ca

Please sign in to comment.