myonlake Posted February 5, 2012 Posted February 5, 2012 (edited) 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 May 30, 2019 by myonlake If I helped you, please click the like button on the right Thanks!
Kenix Posted February 5, 2012 Posted February 5, 2012 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. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
myonlake Posted February 5, 2012 Author Posted February 5, 2012 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 ) If I helped you, please click the like button on the right Thanks!
Kenix Posted February 5, 2012 Posted February 5, 2012 No problem dude. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
myonlake Posted February 5, 2012 Author Posted February 5, 2012 Hold on, it doesn't work I just tested it and it didn't work on others. If I helped you, please click the like button on the right Thanks!
Kenix Posted February 5, 2012 Posted February 5, 2012 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 ) http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now