SetVehicleModelAudioSetting

From Multi Theft Auto: Wiki
Revision as of 18:01, 25 July 2025 by Mohab (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

ADDED/UPDATED IN VERSION 1.6.0 r23140:
This function sets audio properties for a specific vehicle model. It allows customization of various vehicle sound settings such as engine sounds, horn characteristics, door sounds, and radio settings.

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.

[[{{{image}}}|link=|]] Note: Sound bank IDs for engine sounds must be 410 or lower. Values above this limit will be rejected. Changes only affect newly created vehicles. Existing vehicles will retain their original audio settings. This function only works with standard vehicle models and cannot modify audio settings for vehicles that are already spawned.
[[{{{image}}}|link=|]] Tip: This function modifies the audio settings for a specific vehicle model, affecting all newly created vehicles of that model. In contrast, setVehicleAudioSetting modifies the audio settings for a specific vehicle instance. Changes made with this function do not affect vehicles that are already spawned.


Examples

Example 1: Basic Engine Sound Modification

-- Modify the engine sound for Infernus (model 411)
setVehicleModelAudioSetting(411, "engineOnSoundBankID", 150)
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")


See Also