SetVehicleModelAudioSetting
Jump to navigation
Jump to search
Syntax
bool setVehicleModelAudioSetting ( int modelID, string property, float value )
Required Arguments
- modelID: The vehicle model ID to modify audio settings for
- property: The audio property to set. Valid properties are:
- "doorSound" - Door sound effects
- "engineOffSoundBankID" - Engine off sound bank ID (0-410)
- "engineOnSoundBankID" - Engine on sound bank ID (0-410)
- "hornHigh" - Horn high frequency
- "hornTon" - Horn tone
- "hornVolumeDelta" - Horn volume delta
- "radioNum" - Radio number
- "radioType" - Radio type
- value: The numerical value to set for the specified property
Returns
Returns true if the audio setting was successfully applied, false otherwise.
Examples
Example 1: Basic Engine Sound Modification
-- Modify the engine sound for Infernus (model 411) local success = setVehicleModelAudioSetting(411, "engineOnSoundBankID", 150) if success then outputChatBox("Infernus engine sound modified successfully!") else outputChatBox("Failed to modify engine sound.") end -- Create an Infernus to hear the new sound local vehicle = createVehicle(411, 0, 0, 3)
Example 2: Custom Horn Settings
-- Customize horn settings for Sultan (model 560) local modelID = 560 -- Set horn properties setVehicleModelAudioSetting(modelID, "hornHigh", 1.5) setVehicleModelAudioSetting(modelID, "hornTon", 0.8) setVehicleModelAudioSetting(modelID, "hornVolumeDelta", 2.0) outputChatBox("Sultan horn settings customized!") -- Spawn a Sultan to test the new horn local testVehicle = createVehicle(modelID, 100, 100, 3)
Example 3: Radio and Door Sound Configuration
-- Configure radio and door sounds for Elegy (model 562) local elegytModel = 562 -- Set radio properties local radioSuccess = setVehicleModelAudioSetting(elegytModel, "radioNum", 5) local radioTypeSuccess = setVehicleModelAudioSetting(elegytModel, "radioType", 2) -- Set door sound local doorSuccess = setVehicleModelAudioSetting(elegytModel, "doorSound", 1.2) if radioSuccess and radioTypeSuccess and doorSuccess then outputChatBox("Elegy audio settings configured successfully!") -- Create vehicle to test settings local elegy = createVehicle(elegytModel, 200, 200, 3) else outputChatBox("Some audio settings failed to apply.") end
Example 4: Batch Audio Modification
-- Function to apply custom audio profile to multiple vehicles function applyCustomAudioProfile(models, profile) local successCount = 0 for _, modelID in ipairs(models) do local modelSuccess = true for property, value in pairs(profile) do if not setVehicleModelAudioSetting(modelID, property, value) then modelSuccess = false outputChatBox("Failed to set " .. property .. " for model " .. modelID) end end if modelSuccess then successCount = successCount + 1 outputChatBox("Audio profile applied to model " .. modelID) end end return successCount end -- Define custom audio profile local sportCarProfile = { ["engineOnSoundBankID"] = 200, ["engineOffSoundBankID"] = 180, ["hornHigh"] = 1.8, ["hornVolumeDelta"] = 1.5, ["radioType"] = 3 } -- Apply to multiple sports cars local sportsCars = {411, 506, 451, 602} -- Infernus, Super GT, Turismo, Alpha local modifiedCount = applyCustomAudioProfile(sportsCars, sportCarProfile) outputChatBox("Modified audio for " .. modifiedCount .. " vehicle models")
Example 5: Engine Sound Bank Validation
-- Function to safely set engine sound with validation function setEngineSound(modelID, bankID, isEngineOn) -- Validate sound bank ID (must be <= 410) if bankID > 410 then outputChatBox("Error: Sound bank ID must be 410 or lower") return false end local property = isEngineOn and "engineOnSoundBankID" or "engineOffSoundBankID" local success = setVehicleModelAudioSetting(modelID, property, bankID) if success then local stateText = isEngineOn and "on" or "off" outputChatBox("Engine " .. stateText .. " sound set to bank " .. bankID .. " for model " .. modelID) else outputChatBox("Failed to set engine sound for model " .. modelID) end return success end -- Example usage setEngineSound(411, 250, true) -- Set engine on sound setEngineSound(411, 230, false) -- Set engine off sound setEngineSound(411, 450, true) -- This will fail due to validation
See Also
- getVehicleModelAudioSettings
- resetVehicleModelAudioSettings
- setVehicleAudioSetting
- getVehicleAudioSettings
- resetVehicleAudioSettings
author: Mohab