sckatchof Posted March 30, 2012 Share Posted March 30, 2012 hi guys i have problem when i do /radio the speaker attach to vehicle but only one player get the speaker when anther player do /radio the speaker change to his car and it removed from my vehicle this is my script carRadio = createObject(2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, 0, 2, 30) function attachradio(thePlayer) local car = getPedOccupiedVehicle(thePlayer) if(car) then local x, y, z = getElementRotation(car) setObjectRotation(carRadio, x, y, z) triggerClientEvent ( thePlayer, "playRadioCar", getRootElement(), car) attachElements(carRadio, car, 0, -4, 0.45) setObjectRotation(carRadio, x, y, z) outputChatBox("Here is the radio!", thePlayer) end end addCommandHandler("radio", attachradio) Link to comment
drk Posted March 30, 2012 Share Posted March 30, 2012 You need create the object every time a player types /radio and attach the created object to the vehicle. Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 You need create the object every time a player types /radio and attach the created object to the vehicle. but how to create it ? Link to comment
drk Posted March 30, 2012 Share Posted March 30, 2012 (edited) addCommandHandler ( 'radio', function ( player, command ) if ( getPedOccupiedVehicle ( player ) ) then local carRadio = createObject ( 2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, 0, 2, 30 ); local x, y, z = getElementRotation ( getPedOccupiedVehicle ( player ) ); triggerClientEvent ( 'playRadioCar', root, getPedOccupiedVehicle ( player ) ) attachElements ( carRadio, getPedOccupiedVehicle ( player ), 0, -4, 0.45 ); setObjectRotation ( carRadio, x, y, z ); outputChatBox ( 'Here is the radio!', player ); end end ) Edited March 30, 2012 by Guest Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 ty for help but still some probelm Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 Are you sure? Yes i tested it Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 Copy my code again. some problem Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 carRadio = createObject(2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, 0, 2, 30) function attachradio() local car = getPedOccupiedVehicle(source) if(car) then local x, y, z = getElementRotation(car) setObjectRotation(carRadio, x, y, z) triggerClientEvent ( source, "playRadioCar", car) attachElements(carRadio, car, 0, -4, 0.45) setObjectRotation(carRadio, x, y, z) outputChatBox("Here is the radio!", source) end end addCommandHandler("radio", attachradio) Link to comment
drk Posted March 30, 2012 Share Posted March 30, 2012 Where is 'source' defined X-SHADOW? Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 i dont get what you mean ? Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 and how to make it defined i see all functions in mta wiki all like this getPlayerPing = (source) just like me Link to comment
drk Posted March 30, 2012 Share Posted March 30, 2012 addCommandHandler has no source. You need define in function. Example: addCommandHandler ( 'blabla', function ( player, command ) -- something end ) Here, player is the source player. Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 local carRadios = { } -- Create a table. function attachradio ( thePlayer ) local car = getPedOccupiedVehicle ( thePlayer ) if ( car ) then if ( isElement ( carRadios[ car ] ) ) then -- If the vehicle already has a radio... destroyElement ( carRadios[ car ] ) -- Destroy it. end local x, y, z = getElementRotation ( car ) carRadios[ car ] = createObject ( 2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, x, y, z ) -- Create radio object for the vehicle. attachElements ( carRadios[ car ], car, 0, -4, 0.45 ) -- Attach the radio to the vehicle. triggerClientEvent ( thePlayer, "playRadioCar", getRootElement(), car ) outputChatBox ( "Here is the radio!", thePlayer ) end end addCommandHandler ( "radio", attachradio ) Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 (edited) Edit : work thank you sanke for help and darken.... Edited March 30, 2012 by Guest Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 The script creates the radio object, I've tested and it worked. Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 The script creates the radio object, I've tested and it worked. sorry i edit my post it work thank yooou but i have anther problem when i do /radio start music attach to my car it work but me can listen but anther players can't listen this is my script .. sounds = "http://www.181.fm/winamp.pls?station=181-power&style=mp3" function playRadioCar ( car ) local x,y,z = getElementPosition( car ) sound = playSound3D( sounds, x, y, z, true) attachElements ( sound, car) end addEvent( "playRadioCar", true ) addEventHandler("playRadioCar", getRootElement(), playRadioCar) Link to comment
drk Posted March 30, 2012 Share Posted March 30, 2012 playSound3D plays the sound only for localPlayer. Link to comment
Kenix Posted March 30, 2012 Share Posted March 30, 2012 You need trigger this event for all players. https://wiki.multitheftauto.com/wiki/TriggerClientEvent element sendTo=getRootElement() Link to comment
drk Posted March 30, 2012 Share Posted March 30, 2012 Like: triggerClientEvent ( 'playRadioCar', root ) Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 Like: triggerClientEvent ( 'playRadioCar', root ) i add that look to server side it work sound when i do /radio but just on player can lesten to music i want just players near to the car can listen to music Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 -- client side: sounds = "http://www.181.fm/winamp.pls?station=181-power&style=mp3" function playRadioCar ( car ) local x,y,z = getElementPosition ( car ) sound = playSound3D ( sounds, x, y, z, true ) attachElements ( sound, car ) end addEvent ( "playRadioCar", true ) addEventHandler( "playRadioCar", getRootElement(), playRadioCar ) -- server side: local carRadios = { } -- Create a table. function attachradio ( thePlayer ) local car = getPedOccupiedVehicle ( thePlayer ) if ( car ) then if ( isElement ( carRadios[ car ] ) ) then -- If the vehicle already has a radio... destroyElement ( carRadios[ car ] ) -- Destroy it. end local x, y, z = getElementRotation ( car ) carRadios[ car ] = createObject ( 2232, 1016.2437133789, -2473.1711425781, 7.6930656433105, x, y, z ) -- Create radio object for the vehicle. attachElements ( carRadios[ car ], car, 0, -4, 0.45 ) -- Attach the radio to the vehicle. triggerClientEvent ( "playRadioCar", root, car ) outputChatBox ( "Here is the radio!", thePlayer ) end end addCommandHandler ( "radio", attachradio ) Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 thank you snake for help work i have anther question how can i make if player do /radio and get to anther car and do /radio it radio remouve with music and create to his car or he have already the radio it show outputChatBox ( "tthe radio is already exists", thePlayer ) . Link to comment
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