Jump to content

[HELP] Car radio


AndyAndreiH

Recommended Posts

Hello! First of all, I'm sorry if I'm requesting help on something that has already been answered, but I can't seem to find that answer anywhere. I'm trying to make a car radio system for my RP server, but I can't seem to get it to work. My problem is that the radio needs to go with playSound when in a vehicle and playSound3D when outside the vehicle. Also, the radio needs to be synced and if for some reason a car with it's radio on comes near a player, that player needs to hear that sound in 3D. Does anyone know a good example/resource I could learn from? Any help is appreciated! :D

Although my code won't help at all, I'm gonna post it anyway:

  
local sound = nil 
local veh = nil 
  
function onPlayerEnterCar(player) 
    if player == getLocalPlayer() then 
        if (sound) then 
            destroyElement(sound) 
            local int = getElementInterior(source) 
            local dim = getElementDimension(source) 
            sound = playSound("http://82.201.100.10:8000/WEB11", true) 
            setElementDimension(sound, dim) 
            setElementInterior(sound, int) 
            veh = getPedOccupiedVehicle(getLocalPlayer()) 
            attachElements(sound, veh) 
            setSoundVolume(sound, 1.0) 
        end 
    end 
end 
addEventHandler("onClientVehicleEnter", getRootElement(), onPlayerEnterCar) 
  
function onPlayerExitCar(player) 
    if player == getLocalPlayer() then 
        if (sound) then 
            destroyElement(sound) 
            local x, y, z = getElementPosition(source) 
            local int = getElementInterior(source) 
            local dim = getElementDimension(source) 
            local px, py, pz = getElementPosition(getLocalPlayer()) 
            if (getElementdata 
            if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then 
                sound = playSound3D("http://82.201.100.10:8000/WEB11", x, y, z, true) 
                setSoundMaxDistance(sound, 20) 
                setElementDimension(sound, dim) 
                setElementInterior(sound, int) 
            end 
            attachElements(sound, veh) 
            setSoundVolume(sound, 1.0) 
        end 
    end 
end 
addEventHandler("onClientVehicleExit", getRootElement(), onPlayerExitCar) 
  

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...