Skip to content

Commit

Permalink
Merge pull request #269 from AvarianKnight/dev
Browse files Browse the repository at this point in the history
fix(convars): fix calls/radios being too quiet
  • Loading branch information
AvarianKnight authored Feb 7, 2022
2 parents 907767d + 9b17d09 commit 3fe4022
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ All of the configs here are set using `setr [voice_configOption] [int]` OR `setr
| voice_enableUi | 1 | Enables the built in user interface | int |
| voice_enableProximityCycle | 1 | Enables the usage of the F11 proximity key, if disabled players are stuck on the first proximity | int |
| voice_defaultCycle | F11 | The default key to cycle the players proximity. You can find a list of valid keys [in the Cfx docs](https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/) | string |
| voice_defaultRadioVolume | 0.3 | The default volume to set the radio to (has to be between 0.0 and 1.0) *NOTE: Only new joins will have the new value, players that already joined will not.* | float |
| voice_defaultPhoneVolume | 0.6 | The default volume to set the phone to (has to be between 0.0 and 1.0) *NOTE: Only new joins will have the new value, players that already joined will not.* | float |
| voice_defaultRadioVolume | 30 | The default volume to set the radio to (has to be between 1 and 100) *NOTE: Only new joins will have the new value, players that already joined will not.* | float |
| voice_defaultPhoneVolume | 60 | The default volume to set the phone to (has to be between 1 and 100) *NOTE: Only new joins will have the new value, players that already joined will not.* | float |
| voice_defaultVoiceMode | 2 | Default proximity voice value when player joins server. (Voice Modes; 1:Whisper, 2:Normal, 3:Shouting) | int |

### Phone & Radio
Expand All @@ -64,7 +64,7 @@ All of the configs here are set using `setr [voice_configOption] [int]` OR `setr
|-------------------------|---------|--------------------------------------------------------------------|--------------|
| voice_enableRadios | 1 | Enables the radio sub-modules | int |
| voice_enablePhones | 1 | Enables the phone sub-modules | int |
| voice_enableSubmix | 0 | Enables the submix which adds a radio/phone style submix to their voice **NOTE: Submixs require native audio** | int |
| voice_enableSubmix | 1 | Enables the submix which adds a radio/phone style submix to their voice **NOTE: Submixs require native audio** | int |
| voice_enableRadioAnim | 0 | Enables (grab shoulder mic) animation while talking on the radio. | int |
| voice_defaultRadio | LALT | The default key to use the radio. You can find a list of valid keys [in the FiveM docs](https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/) | string |

Expand Down
16 changes: 8 additions & 8 deletions client/init/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ local mutedPlayers = {}
-- we can't use GetConvarInt because its not a integer, and theres no way to get a float... so use a hacky way it is!
local volumes = {
-- people are setting this to 1 instead of 1.0 and expecting it to work.
['radio'] = tonumber(GetConvar('voice_defaultRadioVolume', '0.3')) + 0.0,
['phone'] = tonumber(GetConvar('voice_defaultPhoneVolume', '0.6')) + 0.0,
['radio'] = GetConvarInt('voice_defaultRadioVolume', 30) / 100,
['phone'] = GetConvarInt('voice_defaultPhoneVolume', 60) / 100,
}

radioEnabled, radioPressed, mode = true, false, GetConvarInt('voice_defaultVoiceMode', 2)
Expand All @@ -17,8 +17,8 @@ callData = {}
---@param volumeType string the volume type (currently radio & call) to set the volume of (opt)
function setVolume(volume, volumeType)
type_check({volume, "number"})
local volume = volume
volume = volume / 100
local volume = volume / 100

if volumeType then
local volumeTbl = volumes[volumeType]
if volumeTbl then
Expand Down Expand Up @@ -94,7 +94,7 @@ function toggleVoice(plySource, enabled, moduleType)
logger.verbose('[main] Updating %s to talking: %s with submix %s', plySource, enabled, moduleType)
if enabled then
MumbleSetVolumeOverrideByServerId(plySource, enabled and volumes[moduleType])
if GetConvarInt('voice_enableSubmix', 0) == 1 and gameVersion == 'fivem' then
if GetConvarInt('voice_enableSubmix', 1) == 1 and gameVersion == 'fivem' then
if moduleType then
disableSubmixReset[plySource] = true
submixFunctions[moduleType](plySource)
Expand All @@ -103,7 +103,7 @@ function toggleVoice(plySource, enabled, moduleType)
end
end
else
if GetConvarInt('voice_enableSubmix', 0) == 1 and gameVersion == 'fivem' then
if GetConvarInt('voice_enableSubmix', 1) == 1 and gameVersion == 'fivem' then
-- garbage collect it
disableSubmixReset[plySource] = nil
SetTimeout(250, function()
Expand Down Expand Up @@ -147,10 +147,10 @@ end
---plays the mic click if the player has them enabled.
---@param clickType boolean whether to play the 'on' or 'off' click.
function playMicClicks(clickType)
if micClicks ~= 'true' then return end
if micClicks ~= 'true' then return logger.verbose("Not playing mic clicks because client has them disabled") end
sendUIMessage({
sound = (clickType and "audio_on" or "audio_off"),
volume = (clickType and (volumes["radio"]) or 0.05)
volume = (clickType and volumes["radio"] or 0.05)
})
end

Expand Down
6 changes: 3 additions & 3 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ convar_category 'PMA-Voice' {
{ "Enable UI", "$voice_enableUi", "CV_INT", "1" },
{ "Enable F11 proximity key", "$voice_enableProximityCycle", "CV_INT", "1" },
{ "Proximity cycle key", "$voice_defaultCycle", "CV_STRING", "F11" },
{ "Voice radio volume", "$voice_defaultRadioVolume", "CV_STRING", "0.3" },
{ "Voice phone volume", "$voice_defaultPhoneVolume", "CV_STRING", "0.6" },
{ "Voice radio volume", "$voice_defaultRadioVolume", "CV_INT", "30" },
{ "Voice phone volume", "$voice_defaultPhoneVolume", "CV_INT", "60" },
{ "Enable radios", "$voice_enableRadios", "CV_INT", "1" },
{ "Enable phones", "$voice_enablePhones", "CV_INT", "1" },
{ "Enable sublix", "$voice_enableSubmix", "CV_INT", "0" },
{ "Enable sublix", "$voice_enableSubmix", "CV_INT", "1" },
{ "Enable radio animation", "$voice_enableRadioAnim", "CV_INT", "0" },
{ "Radio key", "$voice_defaultRadio", "CV_STRING", "LALT" },
{ "UI refresh rate", "$voice_uiRefreshRate", "CV_INT", "200" },
Expand Down
23 changes: 19 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ end
function handleStateBagInitilization(source)
local plyState = Player(source).state
if not plyState.pmaVoiceInit then
plyState:set('radio', tonumber(GetConvar('voice_defaultRadioVolume', '0.3')), true)
plyState:set('phone', tonumber(GetConvar('voice_defaultPhoneVolume', '0.6')), true)
plyState:set('radio', GetConvarInt('voice_defaultRadioVolume', 30), true)
plyState:set('phone', GetConvarInt('voice_defaultPhoneVolume', 60), true)
plyState:set('proximity', {}, true)
plyState:set('callChannel', 0, true)
plyState:set('radioChannel', 0, true)
Expand All @@ -26,8 +26,7 @@ function handleStateBagInitilization(source)
end
end

-- temp fix before an actual fix is added
Citizen.CreateThreadNow(function()
Citizen.CreateThread(function()

local plyTbl = GetPlayers()
for i = 1, #plyTbl do
Expand Down Expand Up @@ -73,6 +72,22 @@ Citizen.CreateThreadNow(function()
SetConvarReplicated('voice_use3dAudio', 'true')
end
end

local radioVolume = GetConvarInt("voice_defaultRadioVolume", 30)
local phoneVolume = GetConvarInt("voice_defaultPhoneVolume", 60)

-- When casted to an integer these get set to 0 or 1, so warn on these values that they don't work
if
radioVolume == 0 or radioVolume == 1 or
phoneVolume == 0 or phoneVolume == 1
then
SetConvarReplicated("voice_defaultRadioVolume", 30)
SetConvarReplicated("voice_defaultPhoneVolume", 60)
for i = 1, 5 do
Wait(5000)
logger.warn("`voice_defaultRadioVolume` or `voice_defaultPhoneVolume` have their value set as a float, this is going to automatically be fixed but please update your convars.")
end
end
end)

AddEventHandler('playerJoining', function()
Expand Down

0 comments on commit 3fe4022

Please sign in to comment.