sckatchof Posted March 30, 2012 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)
drk Posted March 30, 2012 Posted March 30, 2012 You need create the object every time a player types /radio and attach the created object to the vehicle. EPT Team Server Development: 0% Learning C++ | C++ is amazing
sckatchof Posted March 30, 2012 Author 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 ?
drk Posted March 30, 2012 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 EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted March 30, 2012 Posted March 30, 2012 Are you sure? EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted March 30, 2012 Posted March 30, 2012 Copy my code again. EPT Team Server Development: 0% Learning C++ | C++ is amazing
X-SHADOW Posted March 30, 2012 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) My ingame nickname : Ops! -DeathMatch GameMode By Ops! : 5%
drk Posted March 30, 2012 Posted March 30, 2012 Where is 'source' defined X-SHADOW? EPT Team Server Development: 0% Learning C++ | C++ is amazing
X-SHADOW Posted March 30, 2012 Posted March 30, 2012 i dont get what you mean ? My ingame nickname : Ops! -DeathMatch GameMode By Ops! : 5%
drk Posted March 30, 2012 Posted March 30, 2012 source = nil. EPT Team Server Development: 0% Learning C++ | C++ is amazing
X-SHADOW Posted March 30, 2012 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 My ingame nickname : Ops! -DeathMatch GameMode By Ops! : 5%
drk Posted March 30, 2012 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. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Castillo Posted March 30, 2012 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 ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
sckatchof Posted March 30, 2012 Author Posted March 30, 2012 (edited) Edit : work thank you sanke for help and darken.... Edited March 30, 2012 by Guest
Castillo Posted March 30, 2012 Posted March 30, 2012 The script creates the radio object, I've tested and it worked. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
sckatchof Posted March 30, 2012 Author 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)
drk Posted March 30, 2012 Posted March 30, 2012 playSound3D plays the sound only for localPlayer. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted March 30, 2012 Posted March 30, 2012 You need trigger this event for all players. https://wiki.multitheftauto.com/wiki/TriggerClientEvent element sendTo=getRootElement() http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
drk Posted March 30, 2012 Posted March 30, 2012 Like: triggerClientEvent ( 'playRadioCar', root ) EPT Team Server Development: 0% Learning C++ | C++ is amazing
sckatchof Posted March 30, 2012 Author 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
Castillo Posted March 30, 2012 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 ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
sckatchof Posted March 30, 2012 Author 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 ) .
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