Jump to content

[REL] Reversing Beep


Stopper

Recommended Posts

This resource warns other players about the maneuver you are performing with BEEPS.

The resource has a server-side, The beep is not just for you, it will look for players who are close and who are near will hear the BEEP from the vehicle.

The default vehicles are the commercial and heavy vehicles.

Edited by Stopper
video added / myth added
  • Like 3
Link to comment

Optimized the whole code for you, Fixed some bugs etc ... ( I think you need to release the next version :P)

  • Client side
local beepTimer = {}
local vehiclesBeep = {
    [485] = true,[431] = true,[437] = true,[574] = true,[525] = true,[408] = true,[552] = true,[416] = true,[433] = true,[427] = true,[407] = true,[544] = true,[428] = true,[499] = true,[609] = true,
    [498] = true,[524] = true,[532] = true,[578] = true,[486] = true,[406] = true,[573] = true,[455] = true,[588] = true,[403] = true,[423] = true,[414] = true,[443] = true,[515] = true,[514] = true,
    [456] = true
}

function TruckReverseSound(position)
    local x,y,z = unpack(fromJSON(position))
    local sfx = playSound3D("sfx/SFX_REVERSE_BEEP_2.mp3", x, y, z, false) 
    setSoundMaxDistance( sfx, 30 )
end
addEvent ( "doReverseBeep", true )
addEventHandler ( "doReverseBeep", root, TruckReverseSound )

function detectDirection ()
    local theVehicle = getPedOccupiedVehicle (localPlayer)
    if theVehicle then
        local matrix = getElementMatrix ( theVehicle )
        local velocity = Vector3(getElementVelocity(theVehicle))
        local DirectionVector = (velocity.x * matrix[2][1]) + (velocity.y * matrix[2][2]) + (velocity.z * matrix[2][3]) 
        if (DirectionVector < 0) then
            triggerServerEvent ( "onReverseBeep", resourceRoot,theVehicle)
        end
    end 
end


function truckSound(thePlayer, seat)
    if thePlayer == localPlayer then
        if(seat == 0) then
            if eventName =="onClientVehicleEnter" then 
                local model = getElementModel(source)
                if vehiclesBeep[model] then
                    beepTimer[source] = setTimer ( detectDirection, 1000, 0 )
                end
            elseif eventName =="onClientVehicleExit" then 
                if isTimer(beepTimer[source]) then 
                    killTimer (beepTimer[source])
                    beepTimer[source] = nil
                end
            end 
        end
    end
end
addEventHandler("onClientVehicleEnter", root,truckSound)
addEventHandler("onClientVehicleExit",root,truckSound)
  • Server side
function doBeepNextToPlayers (theVehicle)
    if theVehicle then 
        local vehicleX, vehicleY, vehicleZ = getElementPosition (theVehicle)
        local position = toJSON({vehicleX, vehicleY, vehicleZ})
        triggerClientEvent ( root, "doReverseBeep", root, position)
    end 
end
addEvent( "onReverseBeep", true )
addEventHandler( "onReverseBeep", resourceRoot, doBeepNextToPlayers )

 

Edited by Walid
  • Like 1
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...