Sziasztok!Itt van ez a script,a baj vele,hogy mikor az adott jármű nagy sebességgel bele csapódik valamibe(pl. egy object),akkor beragad és folyamatosan csak azt hallani,ahogy zakatol a beragadt engine.wav adott hangrészlete.Mi lehet a gond vele,tanácsok?
local engine_sound = \"files/engine.wav\"
local idle_soundfile = \"files/engine_idle.wav\"
local sound = nil
local idle_sound = nil
function getVehicleRPM(vehicle)
if (vehicle) then
if (isVehicleOnGround(vehicle)) then
if (getVehicleEngineState(vehicle) == true) then
if(getVehicleCurrentGear(vehicle) > 0) then
vehicleRPM = math.floor(((getElementSpeed(vehicle, \"kmh\")/getVehicleCurrentGear(vehicle))*220) + 0.5)
if (vehicleRPM < 650) then
vehicleRPM = math.random(650, 750)
elseif (vehicleRPM >= 9800) then
vehicleRPM = 9800
end
else
vehicleRPM = math.floor(((getElementSpeed(vehicle, \"kmh\")/1)*220) + 0.5)
if (vehicleRPM < 650) then
vehicleRPM = math.random(650, 750)
elseif (vehicleRPM >= 9800) then
vehicleRPM = 9800
end
end
else
vehicleRPM = 0
end
else
if (getVehicleEngineState(vehicle) == true) then
vehicleRPM = vehicleRPM - 150
if (vehicleRPM < 650) then
vehicleRPM = math.random(650, 750)
elseif (vehicleRPM >= 9800) then
vehicleRPM = 9800
end
else
vehicleRPM = 0
end
end
return tonumber(vehicleRPM)
else
return 0
end
end
function getElementSpeed(element,unit)
if (unit == nil) then unit = 0 end
if (isElement(element)) then
local x,y,z = getElementVelocity(element)
if (unit==\"mph\" or unit==1 or unit ==\'1\') then
return (x^2 + y^2 + z^2) ^ 0.5 * 100
else
return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100
end
else
outputDebugString(\"Not an element. Can\'t get speed\")
return false
end
end
function engine_func()
local veh = getPedOccupiedVehicle ( getLocalPlayer())
if veh then
if getElementModel ( veh ) == 411 then
if getVehicleEngineState ( veh ) == true then
if getElementSpeed ( veh, \"kmh\" ) > 10 then
if idle_sound then
destroyElement ( idle_sound )
idle_sound = nil
end
if sound == nil then
sound = playSound3D ( engine_sound, 0, 0, 0, true )
attachElements ( sound, veh )
end
setSoundSpeed ( sound, getVehicleRPM(veh)/10000 )
elseif getElementSpeed ( veh, \"kmh\" ) < 10 then
if idle_sound == nil then
idle_sound = playSound3D ( idle_soundfile, 0, 0, 0, true )
setSoundVolume ( idle_sound, 0.2 )
attachElements ( idle_sound, veh )
end
elseif getElementSpeed ( veh, \"kmh\" ) == 0 then
if sound then
destroyElement ( sound )
sound = nil
end
end
else
if sound then
destroyElement ( sound )
sound = nil
end
if idle_sound then
destroyElement ( idle_sound )
idle_sound = nil
end
end
end
end
end
addEventHandler ( \"onClientVehicleEnter\", getRootElement(), function()
if getElementModel ( source ) == 411 then
setWorldSoundEnabled( 40, false )
addEventHandler ( \"onClientRender\", getRootElement(), engine_func )
end
end)
addEventHandler ( \"onClientVehicleExit\", getRootElement(), function()
setWorldSoundEnabled( 40, true )
removeEventHandler ( \"onClientRender\", getRootElement(), engine_func )
end)