Jump to content

Other players are unable to hear the music


myonlake

Recommended Posts

Hello,

I have created a script that attaches a radio channel to a vehicle, and when I do a specific command, the car gets attached to me, with z + 5.

However, the music stays in the original position on all other connected clients, they cannot hear the music when we're away from the original position, and the song is connected to me, and only I am able to hear the music, but they can't.

What's the problem?

/electro - teleports the vehicle to you

/attachelectro - attaches the vehicle to you

/detachelectro - detaches the vehicle from you

-- Miniatures 
local url = "http://electroradio.ch/stream.m3u" 
local px, py, pz = 1296, -1411, 14 
local volume = 1.0 
local distance = 70 
local model = 495 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        -- Vehicle Configuration 
        vehicle = createVehicle(tonumber(model), tonumber(px), tonumber(py), tonumber(pz)) 
        setVehicleColor(vehicle, 126, 126, 0, 0) 
        setVehicleLocked(vehicle, true) 
        setVehicleDoorsUndamageable(vehicle, false) 
        setVehicleDamageProof(vehicle, true) 
        setElementRotation(vehicle, 0, 0, 90) 
        setElementFrozen(vehicle, true) 
        setElementAlpha(vehicle, 0) 
         
        -- Stream Configuration 
        sound = playSound3D(tostring(url), tonumber(px), tonumber(py), tonumber(pz), false) 
        setSoundVolume(sound, tonumber(volume)) 
        setSoundMaxDistance(sound, tonumber(distance)) 
        attachElements(sound, vehicle, 0, 0, 5) 
    end 
) 
  
addCommandHandler("electro", 
    function(cmd) 
        local x, y, z = getElementPosition(localPlayer) 
        setElementPosition(vehicle, x, y, z + 5) 
    end 
) 
  
addCommandHandler("attachelectro", 
    function(cmd) 
        attachElements(vehicle, localPlayer, 0, 0, 5) 
    end 
) 
  
addCommandHandler("detachelectro", 
    function(cmd) 
        detachElements(vehicle, localPlayer) 
    end 
) 
 
Edited by myonlake
Link to comment

Try

local vehicle2 = createVehicle( 495, 1296, -1411, 14 ) 
setVehicleColor( vehicle2, 126, 126, 0, 0 ) 
setVehicleLocked( vehicle2, true ) 
setVehicleDoorsUndamageable( vehicle2, false ) 
setVehicleDamageProof( vehicle2, true ) 
setElementFrozen( vehicle2, true ) 
setElementAlpha( vehicle2, 0 ) 
  
r2 = playSound3D("http://electroradio.ch/stream.m3u", x,y ,z, false) 
setSoundVolume( r2, 1.0 ) 
setSoundMaxDistance( r2, 70 ) 
         
setTimer( 
    function( ) 
        local x,y,z = getElementPosition( vehicle2 ) 
        setElementPosition( r2,x,y,z ) 
    end, 
100, 
0 )  
  
function warpinelectro( ) 
    local x, y, z = getElementPosition(localPlayer) 
    setElementPosition(vehicle2, x, y, z + 5) 
end 
addCommandHandler("electro", warpinelectro) 
  
function attachelectro( ) 
    attachElements(vehicle2, localPlayer, 0, 0, 5) 
end 
addCommandHandler("attachelectro", attachelectro) 
  
function detachelectro( ) 
    detachElements( vehicle2 ) 
end 
  
--/electro - teleports the vehicle to you 
--/attachelectro - attaches the vehicle to you 
--/detachelectro - detaches the vehicle from you 
addCommandHandler( "detachelectro", detachelectro ) 

Code updated.

It should work.

Link to comment

Works just fine, thanks ;)

If someone is interested, feel free to use the following code.

-- Miniatures 
local url = "http://electroradio.ch/stream.m3u" 
local px, py, pz = 1296, -1411, 14 
local volume = 1.0 
local distance = 70 
local model = 495 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        -- Vehicle Configuration 
        vehicle = createVehicle(tonumber(model), tonumber(px), tonumber(py), tonumber(pz)) 
        setVehicleColor(vehicle, 126, 126, 0, 0) 
        setVehicleLocked(vehicle, true) 
        setVehicleDoorsUndamageable(vehicle, false) 
        setVehicleDamageProof(vehicle, true) 
        setElementRotation(vehicle, 0, 0, 90) 
        setElementFrozen(vehicle, true) 
        setElementAlpha(vehicle, 0) 
         
        -- Stream Configuration 
        sound = playSound3D(tostring(url), tonumber(px), tonumber(py), tonumber(pz), false) 
        setSoundVolume(sound, tonumber(volume)) 
        setSoundMaxDistance(sound, tonumber(distance)) 
        attachElements(sound, vehicle, 0, 0, 5) 
    end 
) 
  
function updatePosition() 
    local x, y, z = getElementPosition(vehicle) 
    setElementPosition(sound, x, y, z) 
end 
  
setTimer(updatePosition, 100, 0) 
  
addCommandHandler("electro", 
    function(cmd) 
        local x, y, z = getElementPosition(localPlayer) 
        setElementPosition(vehicle, x, y, z + 5) 
    end 
) 
  
addCommandHandler("attachelectro", 
    function(cmd) 
        attachElements(vehicle, localPlayer, 0, 0, 5) 
    end 
) 
  
addCommandHandler("detachelectro", 
    function(cmd) 
        detachElements(vehicle, localPlayer) 
    end 
) 

Link to comment

Server

local tTimer 
  
addEventHandler( 'onResourceStart',resourceRoot, 
    function( ) 
        if isTimer( tTimer ) then killTimer( tTimer ) end 
        tTimer = setTimer( 
            function( ) 
                triggerClientEvent( 'updateSoundPosition',root ) 
            end, 
        1000, 
        0 )  
    end 
) 

Client

addEvent( 'updateSoundPosition',true )  
     
-- Miniatures 
local url = "http://electroradio.ch/stream.m3u" 
local px, py, pz = 1296, -1411, 14 
local volume = 1.0 
local distance = 70 
local model = 495 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function( ) 
        vehicle = createVehicle( tonumber( model ), tonumber( px ), tonumber( py ), tonumber( pz ) ) 
        setVehicleColor( vehicle, 126, 126, 0, 0 ) 
        setVehicleLocked( vehicle, true ) 
        setVehicleDoorsUndamageable( vehicle, false ) 
        setVehicleDamageProof( vehicle, true ) 
        setElementRotation( vehicle, 0, 0, 90 ) 
        setElementFrozen( vehicle, true ) 
        setElementAlpha( vehicle, 0 ) 
         
        -- Stream Configuration 
        sound = playSound3D( tostring( url ), tonumber( px ), tonumber( py ), tonumber( pz ), false ) 
        setSoundVolume( sound, tonumber( volume ) ) 
        setSoundMaxDistance( sound, tonumber( distance ) ) 
    end 
) 
  
addEventHandler( 'updateSoundPosition',root, 
    function( ) 
        if sound then 
            local x,y,z = getElementPosition( vehicle ) 
            setElementPosition( source,x,y,z ) 
        end 
    end 
)    
  
addCommandHandler("electro", 
    function(cmd) 
        local x, y, z = getElementPosition(localPlayer) 
        setElementPosition(vehicle, x, y, z + 5) 
    end 
) 
  
addCommandHandler("attachelectro", 
    function(cmd) 
        attachElements(vehicle, localPlayer, 0, 0, 5) 
    end 
) 
  
addCommandHandler("detachelectro", 
    function(cmd) 
        detachElements(vehicle, localPlayer) 
    end 
) 

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