Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2021-03-10, 20:45


lego15







Wiek: 26
Na forum: 2097 dni
Posty: 21
Nick w MP: popoq

Piwa: 10

Respekt: 50

Witam mam problem odno?nie paczki VectoryRPG do dzia?ania licznika potrzebne s? 3 skrypty wczym jeden od zmiany d?wi?ku silnika i chcia?bym usun?? ten d?wi?k i kt?r? linijk? mam usun?c daje 3 kody zawarte w skrypcie beengines

--[[
    ##########################################################
    # @project: bengines
    # @author: brzys <[email protected]>
    # @filename: utils_s.lua
    # @description: utils to calculate proper engines for vehicles
    # All rights reserved.
    ##########################################################
--]]

VEHICLES_TYPES = {
    ["Bus"] = {431437},
    ["Truck"] = {403406407408413414427432433443444455456,
                 498499514515524531544556557573578601609},
    ["Sport"] = {411415424429451477480494495502503504506541555558559560,
                         562565568587602598},
    ["Casual"] = {400401404405410416418420421422,
                          426436438440445458459470,
                          478479482489490491492496500505507516517518,
                          526527528529533540543546547549550551,
                          554561566579580585589597596599600604605,
                          536575534567535576412},
    ["Muscle"] = {474545466467439542603475419402},
    ["Plane"] = {592577511548512593425520417487553488497563476447519460469513},
    ["Boat"] = {472473493595484430453452446454},
    ["Motorbike"] = {481462521463522461448468586471581}
}

CLASSES = {
    [{0200}] = "E",
    [{200400}] = "D",
    [{400600}] = "C",
    [{600800}] = "B",
    [{8001000000000}] = "A",
}

MAX_VELOCITY = {
    [400] = 150,
    [401] = 140,
    [402] = 178,
    [404] = 126,
    [405] = 156,
    [409] = 150,
    [410] = 123,
    [411] = 210,
    [412] = 161,
    [415] = 182,
    [418] = 110,
    [419] = 142,
    [421] = 246,
    [422] = 134,
    [424] = 128,
    [426] = 165,
    [429] = 192,
    [434] = 159,
    [436] = 142,
    [439] = 160,
    [445] = 156,
    [451] = 182,
    [458] = 150,
    [461] = 153,
    [463] = 138,
    [466] = 140,
    [467] = 134,
    [468] = 138,
    [471] = 102,
    [474] = 142,
    [475] = 165,
    [477] = 178,
    [478] = 112,
    [479] = 133,
    [480] = 178,
    [482] = 149,
    [483] = 118,
    [489] = 133,
    [491] = 142,
    [492] = 134,
    [495] = 168,
    [496] = 155,
    [500] = 134,
    [506] = 170,
    [507] = 158,
    [508] = 102,
    [516] = 150,
    [517] = 150,
    [518] = 158,
    [521] = 154,
    [526] = 150,
    [527] = 142,
    [529] = 142,
    [533] = 159,
    [534] = 161,
    [535] = 150,
    [536] = 165,
    [540] = 142,
    [541] = 192,
    [542] = 156,
    [543] = 144,
    [545] = 140,
    [546] = 142,
    [547] = 136,
    [549] = 146,
    [550] = 138,
    [551] = 150,
    [554] = 137,
    [555] = 150,
    [558] = 162,
    [559] = 169,
    [560] = 169,
    [561] = 146,
    [562] = 173,
    [565] = 165,
    [566] = 152,
    [567] = 165,
    [575] = 150,
    [576] = 150,
    [579] = 150,
    [580] = 145,
    [581] = 145,
    [585] = 145,
    [586] = 138,
    [587] = 157,
    [589] = 155,
    [600] = 144,
    [602] = 169,
    [603] = 163,
    [522] = 210,
}
function getVehicleMaxVelocity(model)
    return MAX_VELOCITY[model] or 0
end 

function getVehicleTypeByModel(model)
    for typemodels in pairs(VEHICLES_TYPES) do 
        for _mdl in pairs(models) do 
            if mdl == model then 
                return type
            end
        end
    end 
    
    return "Casual"
end

function calculateVehicleClass(vehicle)
    local handling nil
    local v_type nil
    if type(vehicle) == "number" then 
        handling getOriginalHandling(vehicle)
        v_type getVehicleTypeByModel(vehicle)
    else 
        handling getVehicleHandling(vehicle)
        v_type getElementData(vehicle"vehicle:type")
    end
    
    -- engine
    local acc handling.engineAcceleration 
    local vel handling.maxVelocity
    local drag handling.dragCoeff
    local c = (acc drag vel)
    if v_type == "Casual" then 
        c c-0.010
    elseif v_type == "Sport" then 
        c =c-0.005
    elseif v_type == "Muscle" then 
        c c-0.02
    elseif v_type == "Truck" then 
        c =c+0.01
    end
    
    -- steering
    local turnMass handling.turnMass 
    local mass handling.mass 
    local traction handling.tractionLoss
    c - (turnMass/mass/traction)*0.001 
    
    return math.ceil(c*(10^4.54))
end

function getVehicleClass(vehicle)
    local class = calculateVehicleClass(vehicle)
    for requiredname in pairs (CLASSES) do 
        if class >= required[1] and class <= required[2then 
            return name
        end
    end
    
    return "E"
end 

if getModelHandling then
    for namemodels in pairs(VEHICLES_TYPES) do 
        table.sort(models, function(ab)
            return calculateVehicleClass(a) > calculateVehicleClass(b)
        end)    
    end

    --[[
    for namemodels in pairs(VEHICLES_TYPES) do 
        outputChatBox("Najgorszy z "..name..": "..models[#models])
        outputChatBox("Najlepszy z "..name..": "..models[1])
    end 
    --]]
    
    function getBestVehicleClassByType(type)
        if type then 
            return VEHICLES_TYPES[type][1]
        end
    end     
end














--[[
    ##########################################################
    # @project: bengines
    # @author: brzys <[email protected]>
    # @filename: engine_c.lua
    # @description: new engine sounds & RPM simulation
    # All rights reserved.
    ##########################################################
--]]
ENGINE_ENABLED true
ENGINE_VOLUME_MASTER 0.15 -- volume multiplier
ENGINE_VOLUME_THROTTLE_BOOST 2.5     -- boosting engine volume if we use throttle
ENGINE_SOUND_FADE_DIMENSION 6969 -- dimension for unloading sounds
ENGINE_SOUND_DISTANCE 80 -- max distance

DEBUG false

-- offsets of exhaust flames
local als = { 
    [411] = { 
        {0.3, -2.5, -0.45},
        {-0.3, -2.5, -0.45},
    },
    
    [451] = { 
        {0, -2.5, -0.35},
    },
}

local streamedVehicles = {}
local pi math.pi 

function calculateGearRatios(vehiclemaxRPMstartRatio)
    local ratios = {}
    local handling getVehicleHandling(vehicle)
    
    local gears math.max(4handling.numberOfGears)
    local maxVelocity handling.maxVelocity
    local acc handling.engineAcceleration 
    local drag handling.dragCoeff
    --local c = ((acc*maxVelocity) / maxRPM)*(maxRPM*0.00175)
    --local c startRatio or ((acc drag maxVelocity) * pi) * 20
    
    local curGearcurRatio 10
    local mRPM maxVelocity 100
    mRPM = ((maxRPM*gears)/mRPM)*maxRPM
    
    repeat 
        if mRPM/curGear maxRPM*curRatio then 
            curRatio curRatio+0.1/curGear
        else 
            ratios[curGear] = curRatio*0.95
            curGear curGear+1
            curRatio 0
        end
    until #ratios == gears 

    ratios[0] = 0 
    ratios[-1] = ratios[1] 
    
    --[[
    ratios[0] = 0
    for gear=1gears do
        if gear 1 then 
            c c*(gear*0.02)
        end 
        
        ratios[gear] = (gear)
    end
    ratios[-1] = ratios[1]
    --]]
    
    return ratios
end 

function updateEngines(dt)
    if not ENGINE_ENABLED then return end 
    
    local myVehicle getPedOccupiedVehicle(localPlayer)
    if myVehicle and getVehicleController(myVehicle) ~= localPlayer then 
        myVehicle false
    end 
    
    local cxcycz getCameraMatrix()
    local now getTickCount()
    
    for vehicledata in pairs(streamedVehicles) do 
        if isElement(vehiclethen
            local engine getElementData(vehicle"vehicle:engine")
            if engine then
                local xygetElementPosition(vehicle)
                local rxryrz getElementRotation (vehicle)
                local distance getDistanceBetweenPoints3D(xyzcxcycz)
                
                if getVehicleEngineState(vehicle) == true and distance ENGINE_SOUND_DISTANCE*2 then
                    local model getElementModel(vehicle)
                    local handling getVehicleHandling(vehicle)
                    local velocityVec Vector3(getElementVelocity(vehicle))
                    local velocity velocityVec.length 180
                    local controller getVehicleController(vehicle)
                    
                    local upgrades getElementData(vehicle"vehicle:upgrades") or {} 

                    engine.gear engine.gear or 1
                    engine.turbo upgrades.turbo
                    engine.turbo_shifts upgrades.turbo
                    engine.volMult engine.volMult or 1 
                    engine.shiftUpRPM engine.shiftUpRPM or engine.maxRPM*0.91
                    engine.shiftDownRPM engine.shiftDownRPM or (engine.idleRPM+engine.maxRPM)/2.5
                    

                    data.prevThrottle data.throttle
                    data.throttle controller and (getPedControlState(controller"accelerate"))
                    
                    if not data.reverse and velocity 10 then
                        data.reverse controller and (getPedAnalogControlState(controller"brake_reverse") > 0.5)or false
                    elseif data.throttle and velocity 50 then 
                        data.reverse false
                    end
                    
                    local isSkidding controller and ( ( getPedControlState(controller"accelerate") and getPedControlState(controller"brake_reverse") or getPedControlState(controller"handbrake") ) and velocity 40 ) or false
                    data.forceNeutral isSkidding -- or handbrake without movingneutral gear
                                or (isLineOfSightClear(xyzxyz-(getElementDistanceFromCentreOfMassToBaseOfModel(vehicle)*1.25), truefalsefalsetruetruefalsefalsevehicle) and data.throttle) -- vehicle in airneutral gear
                                or isElementFrozen(vehicle) or isElementInWater(vehicle) -- frozen in waterneutral gear
                                or (( rx 110 ) and ( rx 250 )) -- on roofneutral gear
                                
                    data.groundRPM data.groundRPM or 0
                    data.throttlingRPM data.throttlingRPM or 0
                    data.previousGear data.previousGear or engine.gear
                    data.gear data.gear or 1
                    data.currentGear data.currentGear or 1
                    data.changingGear type(data.changingGear) == "number" and data.changingGear or false
                    data.changingRPM data.changingRPM or 0
                    data.changingTargetRPM data.changingTargetRPM or 0 
                    data.turboValue data.turboValue or 0
                    data.prevTurboValue data.turboValue
                    data.als upgrades.als or false
                    data.effects data.effects or {} 
                    
                    local changedGear false 
                    
                    local gearRatios calculateGearRatios(vehicleengine.maxRPMengine.startRatio or 1)
                    local wheel_rpm velocity*100
                    
                    local rpm wheel_rpm -- engine rpm
                    
                    --if data.reverse then 
                        --data.currentGear = -1
                    --end
                    
                    -- calculating rpm neutral gear
                    if getVehicleController(vehiclethen
                        rpm rpm*gearRatios[data.gear]
                    else 
                        rpm engine.idleRPM 
                    end 
                    
                    if not data.forceNeutral then
                        data.throttlingRPM math.max(0data.throttlingRPM - (engine.maxRPM*0.0012)*dt)
                    else 
                        if data.throttle then 
                            data.throttlingRPM data.throttlingRPM + (engine.maxRPM*0.0012)*dt
                        else 
                            data.throttlingRPM math.max(0data.throttlingRPM - (engine.maxRPM*0.0012)*dt)
                        end 
                        data.throttlingRPM math.min(data.throttlingRPMengine.maxRPM)
                    end             
                    rpm rpm+data.throttlingRPM
                    
                    -- smooth rpm change
                    rpm rpm+data.changingRPM
                    if data.changingGear then
                        local progress = (now-data.changingTargetRPM.time) / 300 -- how long
                        data.changingRPM interpolateBetween(data.changingTargetRPM.target00000progress"InQuad")
                        
                        if progress >= 1 then
                            data.changingGear false
                            data.changingGearDirection false
                            data.changingRPM 0
                            data.changingTargetRPM false
                        end
                    end 
                    
                    if data.previousGear ~= data.currentGear then 
                        changedGear = (data.currentGear data.previousGear) and "down" or "up"
                                                
                        data.changingGear data.currentGear
                        data.changingGearDirection changedGear 
                        
                        local nextrpm engine.maxRPM
                        if gearRatios[data.changingGearthen
                            nextrpm wheel_rpm*gearRatios[data.changingGear]
                        end
                        data.changingRPM rpm-nextrpm
                        data.changingTargetRPM = {target=data.changingRPMtime=now}
                        
                        data.gear data.currentGear
                        data.turboValue 0
                    end 
                    
                    -- prev gear update
                    data.previousGear data.currentGear 
                    
                    -- change gears
                    if not data.changingGear and data.throttlingRPM == and wheel_rpm 200 then
                        if rpm engine.shiftUpRPM and data.throttle then 
                            data.currentGear math.min(data.currentGear+1math.max(4getVehicleHandling(vehicle).numberOfGears))
                        elseif rpm engine.shiftDownRPM then
                            data.currentGear math.max(1data.currentGear-1)
                        end 
                    end 
                    
                    -- rev limiter
                    if rpm engine.idleRPM then 
                        rpm engine.idleRPM+math.random(0,100)
                    elseif rpm engine.maxRPM then 
                        rpm engine.maxRPM-math.random(0,100)
                        data.wasRevLimited true
                    end
                    
                    -- ALS
                    if data.wasRevLimited then -- when using throttle
                        if (data.rpm or 0) < engine.maxRPM*0.98 then 
                            data.wasRevLimited false
                            if data.als then 
                                data.activeALS true
                            end
                        end
                    else 
                        if changedGear == "up" and math.random(14) == 1 then -- randomly with gear change
                            if data.als then 
                                data.activeALS true
                            end
                        elseif data.prevThrottle and not data.throttle and data.rpm engine.maxRPM*0.5 and math.random(12) == 1 then 
                            if data.als then 
                                data.activeALS true
                            end
                        end
                    end 
                    
                    -- save rpm
                    data.rpm rpm 
                    
                    -- turbo 
                    if engine.turbo then
                        if data.throttle and rpm engine.maxRPM/2 then 
                            data.turboValue math.min(0.5data.turboValue0.0008*dt)
                        else 
                            data.turboValue math.max(0data.turboValue 0.0005*dt)
                        end 
                    end 
                    
                    
                    -- sounds
                    local svol = {}
                    if not data.sounds then 
                        data.sounds = {} 
                        data.sounds[1] = playSound3D("sounds/"..soundPack.."/1.wav"xyztrue)
                        data.sounds[2] = playSound3D("sounds/"..soundPack.."/2.wav"xyztrue)
                        data.sounds[3] = playSound3D("sounds/"..soundPack.."/3.wav"xyztrue)
                        data.sounds[4] = playSound3D("sounds/turbo.wav"xyztrue)
                        
                        for i=1do 
                            setSoundEffectEnabled(data.sounds[i], "compressor"true)
                        end 
                    else             
                        -- engine
                        local minMidProgress math.min(1, (rpm+500)/(engine.maxRPM/2))
                        local maxMidProgress minMidProgress - ((engine.maxRPM/2)/rpm)
                        
                        local highProgress = (rpm-(engine.maxRPM/2.2))/(engine.maxRPM/2.2)
                        
                        svol[1] = 2^(rpm/(engine.idleRPM*1.5) - 2)
                        svol[2] =  minMidProgress and interpolateBetween(0000.800minMidProgress"InQuad") or interpolateBetween(0.800000maxMidProgress"OutQuad")
                        svol[3] =  interpolateBetween(000100highProgress"OutQuad")
                        
                        
                        local vol svol[1]
                        vol vol*ENGINE_VOLUME_MASTER*engine.volMult
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end 
                        
                        setSoundVolume(data.sounds[1], math.max(0vol))
                        setSoundSpeed(data.sounds[2], rpm/(engine.idleRPM*2))
                        
                        local vol svol[2]
                        vol vol*ENGINE_VOLUME_MASTER*engine.volMult
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end 
                        
                        if data.changingGearDirection == "up" and vol 0.1 then 
                            vol vol/2
                        end
                        
                        setSoundVolume(data.sounds[2], math.max(0vol))
                        setSoundSpeed(data.sounds[2], rpm/(engine.maxRPM*0.6))

                        local vol svol[3]
                        vol vol*ENGINE_VOLUME_MASTER*engine.volMult
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end 
                        
                        if data.changingGearDirection == "up" and vol 0.1 then 
                            vol vol/2
                        end
                        
                        setSoundVolume(data.sounds[3], math.max(0vol))
                        setSoundSpeed(data.sounds[3], rpm/(engine.maxRPM*0.925))
                    
                        svol[4] = data.turboValue
                            
                        local vol svol[4]*ENGINE_VOLUME_MASTER
                            
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end
                            
                        setSoundVolume(data.sounds[4], math.max(0vol*0.9))
                        setSoundSpeed(data.sounds[4], svol[4]+0.8)
                        
                        if ((changedGear == "up" and data.prevTurboValue 0.2) or (not data.throttle and data.prevTurboValue 0.2)) and engine.turbo_shifts then
                            local sound 1 
                            if changedGear then 
                                sound changedGear and changedGear == "up" and tostring(2) or tostring(1)
                            end 
                            
                            data.sounds[5] = playSound3D("sounds/turbo_shift"..sound..".wav"xyzfalse)
                            setSoundVolume(data.sounds[5], 0.6*ENGINE_VOLUME_MASTER)
                            
                            if not data.throttle then 
                                data.turboValue 0
                            end
                        end
                        
                        if data.activeALS and not isElement(data.sounds[6]) then 
                            data.sounds[6] = playSound3D("sounds/als"..math.random(113)..".wav"xyzfalse)
                            setSoundVolume(data.sounds[6], 0.8)
                            setSoundSpeed(data.sounds[6], 1.1)
                            --setSoundEffectEnabled(data.sounds[6], "reverb"true)
                            setSoundEffectEnabled(data.sounds[6], "echo"true)
                            setSoundEffectEnabled(data.sounds[6], "compressor"true)
                            
                            for _offset in ipairs((als[model] or {})) do
                                local ef createEffect("gunflash"xyz000) 
                                setEffectSpeed(ef0.25) 
                                setEffectDensity(ef2)
                                data.effects[ef] = {offset[1], offset[2], offset[3], 900180} 
                                setTimer(function()
                                    data.effects[ef] = nil
                                    destroyElement(ef)
                                end10001)
                            end 
                            
                            data.activeALS false
                        end
                        
                        for i=1#data.sounds do
                            local v data.sounds[i] 
                            if isElement(vthen
                                setElementPosition(vxyz)
                                setElementDimension(v, (svol[i] or 1) > and getElementDimension(vehicle) or ENGINE_SOUND_FADE_DIMENSION)

                                if vehicle == getPedOccupiedVehicle(localPlayerthen 
                                    setSoundMaxDistance(vENGINE_SOUND_DISTANCE*2)
                                else 
                                    setSoundMaxDistance(vENGINE_SOUND_DISTANCE)
                                end
                            end
                        end
                        
                        local rxryrz getElementRotation(vehicle)
                        for efoffset in pairs(data.effects) do 
                            if isElement(efthen 
                                local oxoyoz getPositionFromElementOffset(vehicleoffset[1], offset[2], offset[3])
                                setElementPosition(efoxoyoz)
                                setElementRotation(efoffset[4]-rxoffset[5]-ryoffset[6]-rz)
                            end
                        end 
                    end 
                                        
                    if DEBUG and vehicle == myVehicle then
                        dxDrawText("Silnik\nTyp: "..tostring(engine.name).."\nRPM: "..tostring(rpm).."\nVol1: "..tostring(svol[1]).."\nVol2: "..tostring(svol[2]).."\nVol3: "..tostring(svol[3]).."\nTurboVol: "..tostring(svol[4]), 300300)
                        
                        local t "Biegi\nBieg: "..tostring(data.gear).."/"..tostring(#gearRatios).."\n"
                        for kv in ipairs(gearRatios) do 
                            t.."Ratio "..tostring(k)..": "..v.."\n"
                        end
                        dxDrawText(t300440)
                        
                    end
                else 
                    if data.sounds then 
                        for kv in ipairs(data.sounds) do 
                            if isElement(vthen 
                                destroyElement(v)
                            end
                        end
                        data.sounds false
                    end
                    
                    data.rpm 0
                    data.gear 1
                    data.previousGear 0
                end
            end
        end
    end
end 
addEventHandler("onClientPreRender"rootupdateEngines)

function streamInVehicle(vehicle)
    if not streamedVehicles[vehiclethen
        if isElement(vehicle) and getElementData(vehicle"vehicle:engine"then 
            streamedVehicles[vehicle] = {}
            addEventHandler("onClientElementDestroy"vehicle, function()
                streamOutVehicle(source)
            end)
        end
    end
end

function streamOutVehicle(vehicle)
    if streamedVehicles[vehiclethen 
        if streamedVehicles[vehicle].sounds then 
            for kv in ipairs(streamedVehicles[vehicle].sounds) do 
                if isElement(vthen 
                    destroyElement(v)
                end
            end
        end 
        
        streamedVehicles[vehicle] = nil
    end
end

function toggleGTAEngineSounds(bool)
    setWorldSoundEnabled(7bool)
    setWorldSoundEnabled(8bool)
    setWorldSoundEnabled(9bool)
    setWorldSoundEnabled(10bool)
    setWorldSoundEnabled(11bool)
    setWorldSoundEnabled(12bool)
    setWorldSoundEnabled(13bool)
    setWorldSoundEnabled(14bool)
    setWorldSoundEnabled(15bool)
    setWorldSoundEnabled(16bool)
    setWorldSoundEnabled(40bool)
end 

function getGTARPM(vehicle) 
    if (vehiclethen   
        local velocityVec Vector3(getElementVelocity(vehicle))
        local velocity velocityVec.length 180
                    
        if (isVehicleOnGround(vehicle)) then
            if (getVehicleEngineState(vehicle) == truethen
                if(getVehicleCurrentGear(vehicle) > 0then
                    vehicleRPM math.floor(((velocity/getVehicleCurrentGear(vehicle))*150) + 0.5)
                    if (vehicleRPM 650then
                        vehicleRPM math.random(650750)
                    elseif (vehicleRPM >= 8000then
                        vehicleRPM 8000
                    end
                else
                    vehicleRPM math.floor(((velocity/1)*220) + 0.5)
                    if (vehicleRPM 650then
                        vehicleRPM math.random(650750)
                    elseif (vehicleRPM >= 8000then
                        vehicleRPM 8000
                    end
                end
            else
                vehicleRPM 0
            end
        else   
            if (getVehicleEngineState(vehicle) == truethen
                vehicleRPM vehicleRPM 150
                if (vehicleRPM 650then
                    vehicleRPM math.random(650750)
                elseif (vehicleRPM >= 8000then
                    vehicleRPM 8000
                end
            else
                vehicleRPM 0
            end
        end
        return tonumber(vehicleRPM)
    else
        return 0
    end
end

-- EKSPORT 
function getVehicleRPM(vehicle)
    if streamedVehicles[vehiclethen 
        return streamedVehicles[vehicle].rpm or getGTARPM(vehicle)
    else 
        return getGTARPM(vehicle)
    end
end 

function getVehicleGear(vehicle)
    if streamedVehicles[vehiclethen 
        return streamedVehicles[vehicle].gear or getVehicleCurrentGear(vehicle)
    else 
        return getVehicleCurrentGear(vehicle)
    end
end

function toggleEngines(bool)
    ENGINE_ENABLED bool
    toggleGTAEngineSounds(not ENGINE_ENABLED)
    
    if bool == true then
        for kv in ipairs(getElementsByType("vehicle"roottrue)) do 
            streamInVehicle(v)
        end
    else
        for vehicledata in pairs(streamedVehicles) do 
            streamOutVehicle(vehicle)
        end
        streamedVehicles = {}
    end
end

addEvent("onClientRefreshEngineSounds"true)
addEventHandler("onClientRefreshEngineSounds"root, function()
    for _v in pairs(streamedVehicles) do 
        for _sound in pairs(v.sounds or {}) do 
            if isElement(soundthen 
                stopSound(sound)
            end
        end
        v.sounds nil
    end
end)

addEventHandler("onClientElementStreamIn"root, 
    function()
        if getElementType(source) == "vehicle" then 
            streamInVehicle(source)
        end
    end
)

addEventHandler("onClientElementStreamOut"root, 
    function()
        streamOutVehicle(source)
    end
)

addEventHandler("onClientVehicleEnter"root, function(playerseat)
    if seat == 0 then 
        setTimer(streamInVehicle2001source)
    end
end)

addEventHandler("onClientResourceStart"resourceRoot, function()
    toggleEngines(true)
end)

addEventHandler("onClientResourceStop"resourceRoot, function()
    for kv in pairs(streamedVehicles) do 
        if v.sounds and #v.sounds > 0 then 
            for _sound in pairs(v.sounds) do 
                if isElement(soundthen 
                    destroyElement(sound)
                end
            end
        end
    end
    
    toggleGTAEngineSounds(true)
end)

function getPositionFromElementOffset(element,offX,offY,offZ)
    local m getElementMatrix element )  -- Get the matrix
    local x offX m[1][1] + offY m[2][1] + offZ m[3][1] + m[4][1]  -- Apply transform
    local y offX m[1][2] + offY m[2][2] + offZ m[3][2] + m[4][2]
    local z offX m[1][3] + offY m[2][3] + offZ m[3][3] + m[4][3]
    return xyz                               -- Return the transformed point
end


















<meta>
    <file src="sounds/casual1/1.wav" type="client" download="true" />
    <file src="sounds/casual1/2.wav" type="client" download="true" />
    <file src="sounds/casual1/3.wav" type="client" download="true" />
    <file src="sounds/casual2/1.wav" type="client" download="true" />
    <file src="sounds/casual2/2.wav" type="client" download="true" />
    <file src="sounds/casual2/3.wav" type="client" download="true" />
    <file src="sounds/casual3/1.wav" type="client" download="true" />
    <file src="sounds/casual3/2.wav" type="client" download="true" />
    <file src="sounds/casual3/3.wav" type="client" download="true" />
    <file src="sounds/casual4/1.wav" type="client" download="true" />
    <file src="sounds/casual4/2.wav" type="client" download="true" />
    <file src="sounds/casual4/3.wav" type="client" download="true" />
    <file src="sounds/casual5/1.wav" type="client" download="true" />
    <file src="sounds/casual5/2.wav" type="client" download="true" />
    <file src="sounds/casual5/3.wav" type="client" download="true" />
    <file src="sounds/casual6/1.wav" type="client" download="true" />
    <file src="sounds/casual6/2.wav" type="client" download="true" />
    <file src="sounds/casual6/3.wav" type="client" download="true" />
    <file src="sounds/casual7/1.wav" type="client" download="true" />
    <file src="sounds/casual7/2.wav" type="client" download="true" />
    <file src="sounds/casual7/3.wav" type="client" download="true" />
    <file src="sounds/muscle1/1.wav" type="client" download="true" />
    <file src="sounds/muscle1/2.wav" type="client" download="true" />
    <file src="sounds/muscle1/3.wav" type="client" download="true" />
    <file src="sounds/muscle2/1.wav" type="client" download="true" />
    <file src="sounds/muscle2/2.wav" type="client" download="true" />
    <file src="sounds/muscle2/3.wav" type="client" download="true" />
    <file src="sounds/muscle3/1.wav" type="client" download="true" />
    <file src="sounds/muscle3/2.wav" type="client" download="true" />
    <file src="sounds/muscle3/3.wav" type="client" download="true" />
    <file src="sounds/muscle4/1.wav" type="client" download="true" />
    <file src="sounds/muscle4/2.wav" type="client" download="true" />
    <file src="sounds/muscle4/3.wav" type="client" download="true" />
    <file src="sounds/bus1/1.wav" type="client" download="true" />
    <file src="sounds/bus1/2.wav" type="client" download="true" />
    <file src="sounds/bus1/3.wav" type="client" download="true" />
    <file src="sounds/bus2/1.wav" type="client" download="true" />
    <file src="sounds/bus2/2.wav" type="client" download="true" />
    <file src="sounds/bus2/3.wav" type="client" download="true" />
    <file src="sounds/sport1/1.wav" type="client" download="true" />
    <file src="sounds/sport1/2.wav" type="client" download="true" />
    <file src="sounds/sport1/3.wav" type="client" download="true" />
    <file src="sounds/sport2/1.wav" type="client" download="true" />
    <file src="sounds/sport2/2.wav" type="client" download="true" />
    <file src="sounds/sport2/3.wav" type="client" download="true" />
    <file src="sounds/sport3/1.wav" type="client" download="true" />
    <file src="sounds/sport3/2.wav" type="client" download="true" />
    <file src="sounds/sport3/3.wav" type="client" download="true" />
    <file src="sounds/sport4/1.wav" type="client" download="true" />
    <file src="sounds/sport4/2.wav" type="client" download="true" />
    <file src="sounds/sport4/3.wav" type="client" download="true" />
    <file src="sounds/sport5/1.wav" type="client" download="true" />
    <file src="sounds/sport5/2.wav" type="client" download="true" />
    <file src="sounds/sport5/3.wav" type="client" download="true" />
    <file src="sounds/sport6/1.wav" type="client" download="true" />
    <file src="sounds/sport6/2.wav" type="client" download="true" />
    <file src="sounds/sport6/3.wav" type="client" download="true" />
    <file src="sounds/sport7/1.wav" type="client" download="true" />
    <file src="sounds/sport7/2.wav" type="client" download="true" />
    <file src="sounds/sport7/3.wav" type="client" download="true" />
    <file src="sounds/sport8/1.wav" type="client" download="true" />
    <file src="sounds/sport8/2.wav" type="client" download="true" />
    <file src="sounds/sport8/3.wav" type="client" download="true" />
    <file src="sounds/sport9/1.wav" type="client" download="true" />
    <file src="sounds/sport9/2.wav" type="client" download="true" />
    <file src="sounds/sport9/3.wav" type="client" download="true" />
    <file src="sounds/motorbike1/1.wav" type="client" download="true" />
    <file src="sounds/motorbike1/2.wav" type="client" download="true" />
    <file src="sounds/motorbike1/3.wav" type="client" download="true" />
    <file src="sounds/motorbike2/1.wav" type="client" download="true" />
    <file src="sounds/motorbike2/2.wav" type="client" download="true" />
    <file src="sounds/motorbike2/3.wav" type="client" download="true" />
    <file src="sounds/motorbike3/1.wav" type="client" download="true" />
    <file src="sounds/motorbike3/2.wav" type="client" download="true" />
    <file src="sounds/motorbike3/3.wav" type="client" download="true" />
    <file src="sounds/motorbike4/1.wav" type="client" download="true" />
    <file src="sounds/motorbike4/2.wav" type="client" download="true" />
    <file src="sounds/motorbike4/3.wav" type="client" download="true" />
    <file src="sounds/motorbike5/1.wav" type="client" download="true" />
    <file src="sounds/motorbike5/2.wav" type="client" download="true" />
    <file src="sounds/motorbike5/3.wav" type="client" download="true" />
    <file src="sounds/truck1/1.wav" type="client" download="true" />
    <file src="sounds/truck1/2.wav" type="client" download="true" />
    <file src="sounds/truck1/3.wav" type="client" download="true" />
    <file src="sounds/truck2/1.wav" type="client" download="true" />
    <file src="sounds/truck2/2.wav" type="client" download="true" />
    <file src="sounds/truck2/3.wav" type="client" download="true" />
    <file src="sounds/truck3/1.wav" type="client" download="true" />
    <file src="sounds/truck3/2.wav" type="client" download="true" />
    <file src="sounds/truck3/3.wav" type="client" download="true" />
    
    <file src="sounds/turbo.wav" type="client" download="true" />
    <file src="sounds/turbo_shift1.wav" type="client" download="true" />
    <file src="sounds/turbo_shift2.wav" type="client" download="true" />
    <file src="sounds/locked.mp3" type="client" download="true" />
    
    <file src="sounds/als1.wav" />
    <file src="sounds/als2.wav" />
    <file src="sounds/als3.wav" />
    <file src="sounds/als4.wav" />
    <file src="sounds/als5.wav" />
    <file src="sounds/als6.wav" />
    <file src="sounds/als7.wav" />
    <file src="sounds/als8.wav" />
    <file src="sounds/als9.wav" />
    <file src="sounds/als10.wav" />
    <file src="sounds/als11.wav" />
    <file src="sounds/als12.wav" />
    <file src="sounds/als13.wav" />
    
    <script src="utils_s.lua" type="server" />
    
    <script src="engine_c.lua" type="client" />
    
    <export function="getVehicleRPM" type="client" />
    <export function="getVehicleGear" type="client" />
    <export function="toggleEngines" type="client" />
</meta>


Ostatnio zmieniony przez Wilq 2021-03-10, 23:03, w całości zmieniany 2 razy  
Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Wysłany: 2021-03-11, 09:07


xyzzz^

A nic






Wiek: 18
Na forum: 1993 dni
Posty: 319
Nick w MP: Aspyk21

Piwa: 308

Respekt: 81

Ostrzeżeń: 100%
daj wszystkie kody...

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Wysłany: 2021-03-11, 09:43


lego15







Wiek: 26
Na forum: 2097 dni
Posty: 21
Nick w MP: popoq

Piwa: 10

Respekt: 50

--[[
    ##########################################################
    # @project: bengines
    # @author: brzys <[email protected]>
    # @filename: engine_c.lua
    # @description: new engine sounds & RPM simulation
    # All rights reserved.
    ##########################################################
--]]
ENGINE_ENABLED true
ENGINE_VOLUME_MASTER 0.15 -- volume multiplier
ENGINE_VOLUME_THROTTLE_BOOST 2.5     -- boosting engine volume if we use throttle
ENGINE_SOUND_FADE_DIMENSION 6969 -- dimension for unloading sounds
ENGINE_SOUND_DISTANCE 80 -- max distance

DEBUG false

-- offsets of exhaust flames
local als = { 
    [411] = { 
        {0.3, -2.5, -0.45},
        {-0.3, -2.5, -0.45},
    },
    
    [451] = { 
        {0, -2.5, -0.35},
    },
}

local streamedVehicles = {}
local pi math.pi 

function calculateGearRatios(vehiclemaxRPMstartRatio)
    local ratios = {}
    local handling getVehicleHandling(vehicle)
    
    local gears math.max(4handling.numberOfGears)
    local maxVelocity handling.maxVelocity
    local acc handling.engineAcceleration 
    local drag handling.dragCoeff
    --local c = ((acc*maxVelocity) / maxRPM)*(maxRPM*0.00175)
    --local c startRatio or ((acc drag maxVelocity) * pi) * 20
    
    local curGearcurRatio 10
    local mRPM maxVelocity 100
    mRPM = ((maxRPM*gears)/mRPM)*maxRPM
    
    repeat 
        if mRPM/curGear maxRPM*curRatio then 
            curRatio curRatio+0.1/curGear
        else 
            ratios[curGear] = curRatio*0.95
            curGear curGear+1
            curRatio 0
        end
    until #ratios == gears 

    ratios[0] = 0 
    ratios[-1] = ratios[1] 
    
    --[[
    ratios[0] = 0
    for gear=1gears do
        if gear 1 then 
            c c*(gear*0.02)
        end 
        
        ratios[gear] = (gear)
    end
    ratios[-1] = ratios[1]
    --]]
    
    return ratios
end 

function updateEngines(dt)
    if not ENGINE_ENABLED then return end 
    
    local myVehicle getPedOccupiedVehicle(localPlayer)
    if myVehicle and getVehicleController(myVehicle) ~= localPlayer then 
        myVehicle false
    end 
    
    local cxcycz getCameraMatrix()
    local now getTickCount()
    
    for vehicledata in pairs(streamedVehicles) do 
        if isElement(vehiclethen
            local engine getElementData(vehicle"vehicle:engine")
            if engine then
                local xygetElementPosition(vehicle)
                local rxryrz getElementRotation (vehicle)
                local distance getDistanceBetweenPoints3D(xyzcxcycz)
                
                if getVehicleEngineState(vehicle) == true and distance ENGINE_SOUND_DISTANCE*2 then
                    local model getElementModel(vehicle)
                    local handling getVehicleHandling(vehicle)
                    local velocityVec Vector3(getElementVelocity(vehicle))
                    local velocity velocityVec.length 180
                    local controller getVehicleController(vehicle)
                    
                    local upgrades getElementData(vehicle"vehicle:upgrades") or {} 

                    engine.gear engine.gear or 1
                    engine.turbo upgrades.turbo
                    engine.turbo_shifts upgrades.turbo
                    engine.volMult engine.volMult or 1 
                    engine.shiftUpRPM engine.shiftUpRPM or engine.maxRPM*0.91
                    engine.shiftDownRPM engine.shiftDownRPM or (engine.idleRPM+engine.maxRPM)/2.5
                    

                    data.prevThrottle data.throttle
                    data.throttle controller and (getPedControlState(controller"accelerate"))
                    
                    if not data.reverse and velocity 10 then
                        data.reverse controller and (getPedAnalogControlState(controller"brake_reverse") > 0.5)or false
                    elseif data.throttle and velocity 50 then 
                        data.reverse false
                    end
                    
                    local isSkidding controller and ( ( getPedControlState(controller"accelerate") and getPedControlState(controller"brake_reverse") or getPedControlState(controller"handbrake") ) and velocity 40 ) or false
                    data.forceNeutral isSkidding -- or handbrake without movingneutral gear
                                or (isLineOfSightClear(xyzxyz-(getElementDistanceFromCentreOfMassToBaseOfModel(vehicle)*1.25), truefalsefalsetruetruefalsefalsevehicle) and data.throttle) -- vehicle in airneutral gear
                                or isElementFrozen(vehicle) or isElementInWater(vehicle) -- frozen in waterneutral gear
                                or (( rx 110 ) and ( rx 250 )) -- on roofneutral gear
                                
                    data.groundRPM data.groundRPM or 0
                    data.throttlingRPM data.throttlingRPM or 0
                    data.previousGear data.previousGear or engine.gear
                    data.gear data.gear or 1
                    data.currentGear data.currentGear or 1
                    data.changingGear type(data.changingGear) == "number" and data.changingGear or false
                    data.changingRPM data.changingRPM or 0
                    data.changingTargetRPM data.changingTargetRPM or 0 
                    data.turboValue data.turboValue or 0
                    data.prevTurboValue data.turboValue
                    data.als upgrades.als or false
                    data.effects data.effects or {} 
                    
                    local changedGear false 
                    
                    local gearRatios calculateGearRatios(vehicleengine.maxRPMengine.startRatio or 1)
                    local wheel_rpm velocity*100
                    
                    local rpm wheel_rpm -- engine rpm
                    
                    --if data.reverse then 
                        --data.currentGear = -1
                    --end
                    
                    -- calculating rpm neutral gear
                    if getVehicleController(vehiclethen
                        rpm rpm*gearRatios[data.gear]
                    else 
                        rpm engine.idleRPM 
                    end 
                    
                    if not data.forceNeutral then
                        data.throttlingRPM math.max(0data.throttlingRPM - (engine.maxRPM*0.0012)*dt)
                    else 
                        if data.throttle then 
                            data.throttlingRPM data.throttlingRPM + (engine.maxRPM*0.0012)*dt
                        else 
                            data.throttlingRPM math.max(0data.throttlingRPM - (engine.maxRPM*0.0012)*dt)
                        end 
                        data.throttlingRPM math.min(data.throttlingRPMengine.maxRPM)
                    end             
                    rpm rpm+data.throttlingRPM
                    
                    -- smooth rpm change
                    rpm rpm+data.changingRPM
                    if data.changingGear then
                        local progress = (now-data.changingTargetRPM.time) / 300 -- how long
                        data.changingRPM interpolateBetween(data.changingTargetRPM.target00000progress"InQuad")
                        
                        if progress >= 1 then
                            data.changingGear false
                            data.changingGearDirection false
                            data.changingRPM 0
                            data.changingTargetRPM false
                        end
                    end 
                    
                    if data.previousGear ~= data.currentGear then 
                        changedGear = (data.currentGear data.previousGear) and "down" or "up"
                                                
                        data.changingGear data.currentGear
                        data.changingGearDirection changedGear 
                        
                        local nextrpm engine.maxRPM
                        if gearRatios[data.changingGearthen
                            nextrpm wheel_rpm*gearRatios[data.changingGear]
                        end
                        data.changingRPM rpm-nextrpm
                        data.changingTargetRPM = {target=data.changingRPMtime=now}
                        
                        data.gear data.currentGear
                        data.turboValue 0
                    end 
                    
                    -- prev gear update
                    data.previousGear data.currentGear 
                    
                    -- change gears
                    if not data.changingGear and data.throttlingRPM == and wheel_rpm 200 then
                        if rpm engine.shiftUpRPM and data.throttle then 
                            data.currentGear math.min(data.currentGear+1math.max(4getVehicleHandling(vehicle).numberOfGears))
                        elseif rpm engine.shiftDownRPM then
                            data.currentGear math.max(1data.currentGear-1)
                        end 
                    end 
                    
                    -- rev limiter
                    if rpm engine.idleRPM then 
                        rpm engine.idleRPM+math.random(0,100)
                    elseif rpm engine.maxRPM then 
                        rpm engine.maxRPM-math.random(0,100)
                        data.wasRevLimited true
                    end
                    
                    -- ALS
                    if data.wasRevLimited then -- when using throttle
                        if (data.rpm or 0) < engine.maxRPM*0.98 then 
                            data.wasRevLimited false
                            if data.als then 
                                data.activeALS true
                            end
                        end
                    else 
                        if changedGear == "up" and math.random(14) == 1 then -- randomly with gear change
                            if data.als then 
                                data.activeALS true
                            end
                        elseif data.prevThrottle and not data.throttle and data.rpm engine.maxRPM*0.5 and math.random(12) == 1 then 
                            if data.als then 
                                data.activeALS true
                            end
                        end
                    end 
                    
                    -- save rpm
                    data.rpm rpm 
                    
                    -- turbo 
                    if engine.turbo then
                        if data.throttle and rpm engine.maxRPM/2 then 
                            data.turboValue math.min(0.5data.turboValue0.0008*dt)
                        else 
                            data.turboValue math.max(0data.turboValue 0.0005*dt)
                        end 
                    end 
                    
                    
                    -- sounds
                    local svol = {}
                    if not data.sounds then 
                        data.sounds = {} 
                        data.sounds[1] = playSound3D("sounds/"..soundPack.."/1.wav"xyztrue)
                        data.sounds[2] = playSound3D("sounds/"..soundPack.."/2.wav"xyztrue)
                        data.sounds[3] = playSound3D("sounds/"..soundPack.."/3.wav"xyztrue)
                        data.sounds[4] = playSound3D("sounds/turbo.wav"xyztrue)
                        
                        for i=1do 
                            setSoundEffectEnabled(data.sounds[i], "compressor"true)
                        end 
                    else             
                        -- engine
                        local minMidProgress math.min(1, (rpm+500)/(engine.maxRPM/2))
                        local maxMidProgress minMidProgress - ((engine.maxRPM/2)/rpm)
                        
                        local highProgress = (rpm-(engine.maxRPM/2.2))/(engine.maxRPM/2.2)
                        
                        svol[1] = 2^(rpm/(engine.idleRPM*1.5) - 2)
                        svol[2] =  minMidProgress and interpolateBetween(0000.800minMidProgress"InQuad") or interpolateBetween(0.800000maxMidProgress"OutQuad")
                        svol[3] =  interpolateBetween(000100highProgress"OutQuad")
                        
                        
                        local vol svol[1]
                        vol vol*ENGINE_VOLUME_MASTER*engine.volMult
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end 
                        
                        setSoundVolume(data.sounds[1], math.max(0vol))
                        setSoundSpeed(data.sounds[2], rpm/(engine.idleRPM*2))
                        
                        local vol svol[2]
                        vol vol*ENGINE_VOLUME_MASTER*engine.volMult
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end 
                        
                        if data.changingGearDirection == "up" and vol 0.1 then 
                            vol vol/2
                        end
                        
                        setSoundVolume(data.sounds[2], math.max(0vol))
                        setSoundSpeed(data.sounds[2], rpm/(engine.maxRPM*0.6))

                        local vol svol[3]
                        vol vol*ENGINE_VOLUME_MASTER*engine.volMult
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end 
                        
                        if data.changingGearDirection == "up" and vol 0.1 then 
                            vol vol/2
                        end
                        
                        setSoundVolume(data.sounds[3], math.max(0vol))
                        setSoundSpeed(data.sounds[3], rpm/(engine.maxRPM*0.925))
                    
                        svol[4] = data.turboValue
                            
                        local vol svol[4]*ENGINE_VOLUME_MASTER
                            
                        if data.throttle then 
                            vol vol*ENGINE_VOLUME_THROTTLE_BOOST
                        end
                            
                        setSoundVolume(data.sounds[4], math.max(0vol*0.9))
                        setSoundSpeed(data.sounds[4], svol[4]+0.8)
                        
                        if ((changedGear == "up" and data.prevTurboValue 0.2) or (not data.throttle and data.prevTurboValue 0.2)) and engine.turbo_shifts then
                            local sound 1 
                            if changedGear then 
                                sound changedGear and changedGear == "up" and tostring(2) or tostring(1)
                            end 
                            
                            data.sounds[5] = playSound3D("sounds/turbo_shift"..sound..".wav"xyzfalse)
                            setSoundVolume(data.sounds[5], 0.6*ENGINE_VOLUME_MASTER)
                            
                            if not data.throttle then 
                                data.turboValue 0
                            end
                        end
                        
                        if data.activeALS and not isElement(data.sounds[6]) then 
                            data.sounds[6] = playSound3D("sounds/als"..math.random(113)..".wav"xyzfalse)
                            setSoundVolume(data.sounds[6], 0.8)
                            setSoundSpeed(data.sounds[6], 1.1)
                            --setSoundEffectEnabled(data.sounds[6], "reverb"true)
                            setSoundEffectEnabled(data.sounds[6], "echo"true)
                            setSoundEffectEnabled(data.sounds[6], "compressor"true)
                            
                            for _offset in ipairs((als[model] or {})) do
                                local ef createEffect("gunflash"xyz000) 
                                setEffectSpeed(ef0.25) 
                                setEffectDensity(ef2)
                                data.effects[ef] = {offset[1], offset[2], offset[3], 900180} 
                                setTimer(function()
                                    data.effects[ef] = nil
                                    destroyElement(ef)
                                end10001)
                            end 
                            
                            data.activeALS false
                        end
                        
                        for i=1#data.sounds do
                            local v data.sounds[i] 
                            if isElement(vthen
                                setElementPosition(vxyz)
                                setElementDimension(v, (svol[i] or 1) > and getElementDimension(vehicle) or ENGINE_SOUND_FADE_DIMENSION)

                                if vehicle == getPedOccupiedVehicle(localPlayerthen 
                                    setSoundMaxDistance(vENGINE_SOUND_DISTANCE*2)
                                else 
                                    setSoundMaxDistance(vENGINE_SOUND_DISTANCE)
                                end
                            end
                        end
                        
                        local rxryrz getElementRotation(vehicle)
                        for efoffset in pairs(data.effects) do 
                            if isElement(efthen 
                                local oxoyoz getPositionFromElementOffset(vehicleoffset[1], offset[2], offset[3])
                                setElementPosition(efoxoyoz)
                                setElementRotation(efoffset[4]-rxoffset[5]-ryoffset[6]-rz)
                            end
                        end 
                    end 
                                        
                    if DEBUG and vehicle == myVehicle then
                        dxDrawText("Silnik\nTyp: "..tostring(engine.name).."\nRPM: "..tostring(rpm).."\nVol1: "..tostring(svol[1]).."\nVol2: "..tostring(svol[2]).."\nVol3: "..tostring(svol[3]).."\nTurboVol: "..tostring(svol[4]), 300300)
                        
                        local t "Biegi\nBieg: "..tostring(data.gear).."/"..tostring(#gearRatios).."\n"
                        for kv in ipairs(gearRatios) do 
                            t.."Ratio "..tostring(k)..": "..v.."\n"
                        end
                        dxDrawText(t300440)
                        
                    end
                else 
                    if data.sounds then 
                        for kv in ipairs(data.sounds) do 
                            if isElement(vthen 
                                destroyElement(v)
                            end
                        end
                        data.sounds false
                    end
                    
                    data.rpm 0
                    data.gear 1
                    data.previousGear 0
                end
            end
        end
    end
end 
addEventHandler("onClientPreRender"rootupdateEngines)

function streamInVehicle(vehicle)
    if not streamedVehicles[vehiclethen
        if isElement(vehicle) and getElementData(vehicle"vehicle:engine"then 
            streamedVehicles[vehicle] = {}
            addEventHandler("onClientElementDestroy"vehicle, function()
                streamOutVehicle(source)
            end)
        end
    end
end

function streamOutVehicle(vehicle)
    if streamedVehicles[vehiclethen 
        if streamedVehicles[vehicle].sounds then 
            for kv in ipairs(streamedVehicles[vehicle].sounds) do 
                if isElement(vthen 
                    destroyElement(v)
                end
            end
        end 
        
        streamedVehicles[vehicle] = nil
    end
end

function toggleGTAEngineSounds(bool)
    setWorldSoundEnabled(7bool)
    setWorldSoundEnabled(8bool)
    setWorldSoundEnabled(9bool)
    setWorldSoundEnabled(10bool)
    setWorldSoundEnabled(11bool)
    setWorldSoundEnabled(12bool)
    setWorldSoundEnabled(13bool)
    setWorldSoundEnabled(14bool)
    setWorldSoundEnabled(15bool)
    setWorldSoundEnabled(16bool)
    setWorldSoundEnabled(40bool)
end 

function getGTARPM(vehicle) 
    if (vehiclethen   
        local velocityVec Vector3(getElementVelocity(vehicle))
        local velocity velocityVec.length 180
                    
        if (isVehicleOnGround(vehicle)) then
            if (getVehicleEngineState(vehicle) == truethen
                if(getVehicleCurrentGear(vehicle) > 0then
                    vehicleRPM math.floor(((velocity/getVehicleCurrentGear(vehicle))*150) + 0.5)
                    if (vehicleRPM 650then
                        vehicleRPM math.random(650750)
                    elseif (vehicleRPM >= 8000then
                        vehicleRPM 8000
                    end
                else
                    vehicleRPM math.floor(((velocity/1)*220) + 0.5)
                    if (vehicleRPM 650then
                        vehicleRPM math.random(650750)
                    elseif (vehicleRPM >= 8000then
                        vehicleRPM 8000
                    end
                end
            else
                vehicleRPM 0
            end
        else   
            if (getVehicleEngineState(vehicle) == truethen
                vehicleRPM vehicleRPM 150
                if (vehicleRPM 650then
                    vehicleRPM math.random(650750)
                elseif (vehicleRPM >= 8000then
                    vehicleRPM 8000
                end
            else
                vehicleRPM 0
            end
        end
        return tonumber(vehicleRPM)
    else
        return 0
    end
end

-- EKSPORT 
function getVehicleRPM(vehicle)
    if streamedVehicles[vehiclethen 
        return streamedVehicles[vehicle].rpm or getGTARPM(vehicle)
    else 
        return getGTARPM(vehicle)
    end
end 

function getVehicleGear(vehicle)
    if streamedVehicles[vehiclethen 
        return streamedVehicles[vehicle].gear or getVehicleCurrentGear(vehicle)
    else 
        return getVehicleCurrentGear(vehicle)
    end
end

function toggleEngines(bool)
    ENGINE_ENABLED bool
    toggleGTAEngineSounds(not ENGINE_ENABLED)
    
    if bool == true then
        for kv in ipairs(getElementsByType("vehicle"roottrue)) do 
            streamInVehicle(v)
        end
    else
        for vehicledata in pairs(streamedVehicles) do 
            streamOutVehicle(vehicle)
        end
        streamedVehicles = {}
    end
end

addEvent("onClientRefreshEngineSounds"true)
addEventHandler("onClientRefreshEngineSounds"root, function()
    for _v in pairs(streamedVehicles) do 
        for _sound in pairs(v.sounds or {}) do 
            if isElement(soundthen 
                stopSound(sound)
            end
        end
        v.sounds nil
    end
end)

addEventHandler("onClientElementStreamIn"root, 
    function()
        if getElementType(source) == "vehicle" then 
            streamInVehicle(source)
        end
    end
)

addEventHandler("onClientElementStreamOut"root, 
    function()
        streamOutVehicle(source)
    end
)

addEventHandler("onClientVehicleEnter"root, function(playerseat)
    if seat == 0 then 
        setTimer(streamInVehicle2001source)
    end
end)

addEventHandler("onClientResourceStart"resourceRoot, function()
    toggleEngines(true)
end)

addEventHandler("onClientResourceStop"resourceRoot, function()
    for kv in pairs(streamedVehicles) do 
        if v.sounds and #v.sounds > 0 then 
            for _sound in pairs(v.sounds) do 
                if isElement(soundthen 
                    destroyElement(sound)
                end
            end
        end
    end
    
    toggleGTAEngineSounds(true)
end)

function getPositionFromElementOffset(element,offX,offY,offZ)
    local m getElementMatrix element )  -- Get the matrix
    local x offX m[1][1] + offY m[2][1] + offZ m[3][1] + m[4][1]  -- Apply transform
    local y offX m[1][2] + offY m[2][2] + offZ m[3][2] + m[4][2]
    local z offX m[1][3] + offY m[2][3] + offZ m[3][3] + m[4][3]
    return xyz                               -- Return the transformed point
end 

Dodano2021-03-1109:44
--[[
    ##########################################################
    # @project: bengines
    # @author: brzys <[email protected]>
    # @filename: utils_s.lua
    # @description: utils to calculate proper engines for vehicles
    # All rights reserved.
    ##########################################################
--]]

VEHICLES_TYPES = {
    ["Bus"] = {431437},
    ["Truck"] = {403406407408413414427432433443444455456,
                 498499514515524531544556557573578601609},
    ["Sport"] = {411415424429451477480494495502503504506541555558559560,
                         562565568587602598},
    ["Casual"] = {400401404405410416418420421422,
                          426436438440445458459470,
                          478479482489490491492496500505507516517518,
                          526527528529533540543546547549550551,
                          554561566579580585589597596599600604605,
                          536575534567535576412},
    ["Muscle"] = {474545466467439542603475419402},
    ["Plane"] = {592577511548512593425520417487553488497563476447519460469513},
    ["Boat"] = {472473493595484430453452446454},
    ["Motorbike"] = {481462521463522461448468586471581}
}

CLASSES = {
    [{0200}] = "E",
    [{200400}] = "D",
    [{400600}] = "C",
    [{600800}] = "B",
    [{8001000000000}] = "A",
}

MAX_VELOCITY = {
    [400] = 150,
    [401] = 140,
    [402] = 178,
    [404] = 126,
    [405] = 156,
    [409] = 150,
    [410] = 123,
    [411] = 210,
    [412] = 161,
    [415] = 182,
    [418] = 110,
    [419] = 142,
    [421] = 246,
    [422] = 134,
    [424] = 128,
    [426] = 165,
    [429] = 192,
    [434] = 159,
    [436] = 142,
    [439] = 160,
    [445] = 156,
    [451] = 182,
    [458] = 150,
    [461] = 153,
    [463] = 138,
    [466] = 140,
    [467] = 134,
    [468] = 138,
    [471] = 102,
    [474] = 142,
    [475] = 165,
    [477] = 178,
    [478] = 112,
    [479] = 133,
    [480] = 178,
    [482] = 149,
    [483] = 118,
    [489] = 133,
    [491] = 142,
    [492] = 134,
    [495] = 168,
    [496] = 155,
    [500] = 134,
    [506] = 170,
    [507] = 158,
    [508] = 102,
    [516] = 150,
    [517] = 150,
    [518] = 158,
    [521] = 154,
    [526] = 150,
    [527] = 142,
    [529] = 142,
    [533] = 159,
    [534] = 161,
    [535] = 150,
    [536] = 165,
    [540] = 142,
    [541] = 192,
    [542] = 156,
    [543] = 144,
    [545] = 140,
    [546] = 142,
    [547] = 136,
    [549] = 146,
    [550] = 138,
    [551] = 150,
    [554] = 137,
    [555] = 150,
    [558] = 162,
    [559] = 169,
    [560] = 169,
    [561] = 146,
    [562] = 173,
    [565] = 165,
    [566] = 152,
    [567] = 165,
    [575] = 150,
    [576] = 150,
    [579] = 150,
    [580] = 145,
    [581] = 145,
    [585] = 145,
    [586] = 138,
    [587] = 157,
    [589] = 155,
    [600] = 144,
    [602] = 169,
    [603] = 163,
    [522] = 210,
}
function getVehicleMaxVelocity(model)
    return MAX_VELOCITY[model] or 0
end 

function getVehicleTypeByModel(model)
    for typemodels in pairs(VEHICLES_TYPES) do 
        for _mdl in pairs(models) do 
            if mdl == model then 
                return type
            end
        end
    end 
    
    return "Casual"
end

function calculateVehicleClass(vehicle)
    local handling nil
    local v_type nil
    if type(vehicle) == "number" then 
        handling getOriginalHandling(vehicle)
        v_type getVehicleTypeByModel(vehicle)
    else 
        handling getVehicleHandling(vehicle)
        v_type getElementData(vehicle"vehicle:type")
    end
    
    -- engine
    local acc handling.engineAcceleration 
    local vel handling.maxVelocity
    local drag handling.dragCoeff
    local c = (acc drag vel)
    if v_type == "Casual" then 
        c c-0.010
    elseif v_type == "Sport" then 
        c =c-0.005
    elseif v_type == "Muscle" then 
        c c-0.02
    elseif v_type == "Truck" then 
        c =c+0.01
    end
    
    -- steering
    local turnMass handling.turnMass 
    local mass handling.mass 
    local traction handling.tractionLoss
    c - (turnMass/mass/traction)*0.001 
    
    return math.ceil(c*(10^4.54))
end

function getVehicleClass(vehicle)
    local class = calculateVehicleClass(vehicle)
    for requiredname in pairs (CLASSES) do 
        if class >= required[1] and class <= required[2then 
            return name
        end
    end
    
    return "E"
end 

if getModelHandling then
    for namemodels in pairs(VEHICLES_TYPES) do 
        table.sort(models, function(ab)
            return calculateVehicleClass(a) > calculateVehicleClass(b)
        end)    
    end

    --[[
    for namemodels in pairs(VEHICLES_TYPES) do 
        outputChatBox("Najgorszy z "..name..": "..models[#models])
        outputChatBox("Najlepszy z "..name..": "..models[1])
    end 
    --]]
    
    function getBestVehicleClassByType(type)
        if type then 
            return VEHICLES_TYPES[type][1]
        end
    end     
end


Komentarz Wilq dodany 2021-03-11, 09:50Dodawaj tagi [LUA] do postów.
Ostatnio zmieniony przez Wilq 2021-03-11, 09:50, w całości zmieniany 1 raz  
Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Wysłany: 2021-03-11, 10:36


_jvneczek







Wiek: 22
Na forum: 4326 dni
Posty: 1513
Nick w MP: _jvneczek

Piwa: 3949

Respekt: 337,5
Respekt: 337,5Respekt: 337,5Respekt: 337,5

Bez sens zmienia? to w bengines, w liczniku musisz usun?? RPM'y pobierane z bengines i wtedy nie b?dzie ci bengines do tego potrzebne.

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Wysłany: 2021-03-11, 12:30


lego15







Wiek: 26
Na forum: 2097 dni
Posty: 21
Nick w MP: popoq

Piwa: 10

Respekt: 50

a pomo?esz mi z tym i w kt?rym kodzie mam to skasowa?

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Tagi: zlikwidowanie :: dzwieku
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » zlikwidowanie dzwieku Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku