Jump to content

Звуки авто


Recommended Posts

Ребята, видел уже систему звуков на авто, нашел на этом сайте на инфернус, но там luaC файл.. Пожалуйста если есть бесплатный может кто поделиться? Я начинающий в lua, не сочтите за тупость, но не додумаюсь через переменную написать пока скрипт, знаю знаю учись и еще раз учись, ну пожалуйста :cry::cry::cry:

Link to comment
  • 2 weeks later...
Ребята, видел уже систему звуков на авто, нашел на этом сайте на инфернус, но там luaC файл.. Пожалуйста если есть бесплатный может кто поделиться? Я начинающий в lua, не сочтите за тупость, но не додумаюсь через переменную написать пока скрипт, знаю знаю учись и еще раз учись, ну пожалуйста :cry::cry::cry:

Держи :) звук надеюсь найдешь)

    function updateEngineSound() 
        -- We get a table of all vehicles on the server: 
        local allVehicles = getElementsByType("vehicle") 
        -- we then do a loop that will iterate over that table: 
        for index, veh in ipairs (allVehicles) do --It's like saying: "For each vehicle, do this" 
            -- we get the model of the vehicle 
            local model = getElementModel(veh) 
            -- if the model is equal to 411 then do this 
            if model == 411 then 
                -- if the engine is on 
                if getVehicleEngineState(veh) then 
                    -- we get the position of that vehicle 
                    local x, y, z = getElementPosition(veh) 
      
                    -- we then try to get the sound we maybe created and stored as an element data 
                    -- for that vehicle. If we didn't yet, then it will return false. 
                    local sound = getElementData(veh, "engineSound") 
      
                    -- if the inverse of sound is true (same as: if sound is equal to false) 
                    -- Note that "not false" will give true 
                    if not sound then 
                        -- we create the sound at the veh position and loop it 
                        sound = playSound3D("sounds/song.mp3", x, y, z, true) 
                        -- we store that sound in an element data I decided to call "engineSound" 
                        setElementData(veh, "engineSound", sound) 
                    end 
      
                    -- if the sound is paused (because the engine was off) then 
                    if isSoundPaused(veh) then 
                        -- we "unpause" the sound 
                        setSoundPaused(sound, false) 
                    end 
      
                    -- we then need to get the speed 
                    local velocityX, velocityY, velocityZ = getElementVelocity(veh) 
                    -- calculate the global speed in mph from the 3 velocities: 
                    -- use pythagorean theorem to get actual velocity 
                    -- raising something to the exponent of 0.5 is the same thing as taking a square root. 
                    local actualspeed = (velocityX^2 + velocityY^2 + velocityZ^2)^(0.5) 
                    -- multiply by 50 to obtain the speed in meters per second and 
                    -- then by 111.847 to obtain the speed in meters per hour 
                    local mph = actualspeed * 50 * 111.847 
      
                    -- we try to calculate the sound speed according to the mph 
                    -- I guess 80mph is the speed that the original sound sounds like and 
                    -- I also guess 0.25 is the min speed that the sound can be at to still sounds like an engine. 
                    -- I added 80/minSoundSpeed to 80 to compensate the minSoundSpeed we added 
                    local minSoundSpeed = 0.25 
                    local soundSpeed = mph/(80+80/minSoundSpeed) + minSoundSpeed 
                    -- and then we apply it to the sound 
                    setSoundSpeed (sound, soundSpeed) 
      
                    -- and finally update the sound position to follow the vehicle 
                    setElementPosition(sound, x, y, z) 
      
                else -- otherwise (so if the engine is off) 
                    -- we pause the sound 
                    setSoundPaused(sound, true) 
                end -- close the "if engine was on" 
            end -- close the "if model was 411" 
        end -- end of the loop 
    end 
    setTimer(updateEngineSound, 50, 0) --repeat that function every 50 ms 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...