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... outputChatBox ( "This vehicle already has a radio.", thePlayer, 255, 0, 0 ) else 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 end addCommandHandler ( "radio", attachradio ) This will check if the vehicle already has a radio, if so, output a message to the player. Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 thank you again snake work and who can i make a command to destroy attachElement from vehicle and destroy sound like /destoryradio ? and sorry for inconvenience again 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" carSounds = { } function playRadioCar ( car ) local x,y,z = getElementPosition ( car ) if ( isElement ( carSounds[ car ] ) ) then destroyElement ( carSounds[ car ] ) end carSounds[ car ] = playSound3D ( sounds, x, y, z, true ) attachElements ( carSounds[ car ], car ) end addEvent ( "playRadioCar", true ) addEventHandler( "playRadioCar", getRootElement(), playRadioCar ) addEvent ( "stopCarRadio", true ) addEventHandler ( "stopCarRadio", root, function ( car ) if ( isElement ( carSounds[ car ] ) ) then destroyElement ( carSounds[ car ] ) end end ) -- 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... outputChatBox ( "This vehicle already has a radio.", thePlayer, 255, 0, 0 ) else 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 end addCommandHandler ( "radio", attachradio ) addCommandHandler ( "stopradio", function ( thePlayer ) local car = getPedOccupiedVehicle ( thePlayer ) if ( car ) then if ( not isElement ( carRadios[ car ] ) ) then -- If the vehicle has no radio... outputChatBox ( "This vehicle has no radio.", thePlayer, 255, 0, 0 ) else triggerClientEvent ( "stopCarRadio", root, car ) destroyElement ( carRadios[ car ] ) end end end ) Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 thannnnnnnnk you snake but sound dont stop when i do /stopradio just speacker destory but music dont stop Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 try using this addEvent ( "stopCarRadio", true ) addEventHandler ( "stopCarRadio", root, function ( car ) if ( isElement ( carSounds[ car ] ) ) then stopSound ( carSounds[ car ] ) end end ) Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 thannnnnnnnk you snake but sound dont stop when i do /stopradio just speacker destory but music dont stop The sound is destroyed, it works fine here. Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 try using this addEvent ( "stopCarRadio", true ) addEventHandler ( "stopCarRadio", root, function ( car ) if ( isElement ( carSounds[ car ] ) ) then stopSound ( carSounds[ car ] ) end end ) it still work the sound The sound is destroyed, it works fine here. idk why dont work for me i tested it i do /radio and the sound start and when i do /stopradio the music still work just speaker destroy Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 addEvent ( "stopCarRadio", true ) addEventHandler ( "stopCarRadio", root, function ( car ) if ( isElement ( carSounds[ car ] ) ) then stopSound ( Sounds) end end ) Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 @X-SHADOW: Stop posting the same thing, that'll just stop the sound, it'll stay there still. @sckatchof: I've tested it with two vehicles, both times is destroyed. Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 soldSnake its not worng to help some one i want help him Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 Random codes won't help him. Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 thanks all for help but i will try to fix it idk why it dont work for me Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 i well try help you just 1 min wait me Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 thanks all for help but i will try to fix it idk why it dont work for me Are you sure you've copied my last code? Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 Are you sure you've copied my last code? Yes im sure if u want i will upload my resource Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 Try copying my last code again. Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 hope this work local s = false addCommandHandler ( "stopradio", function () if s then stopSound(carSounds[ car ]) s = false return end end) Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 Try copying my last code again. i copy your last code again, still dont stop Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 Please upload your resource to: http://mediafire.com/ Link to comment
X-SHADOW Posted March 30, 2012 Share Posted March 30, 2012 i found it on topic this topic lol https://forum.multitheftauto.com/viewtop ... 6&p=398145 Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 Please upload your resource to: http://mediafire.com/ Link : http://www.mediafire.com/?uxr856xtiiy6co3 Link to comment
sckatchof Posted March 30, 2012 Author Share Posted March 30, 2012 i found it on topic this topic lolhttps://forum.multitheftauto.com/viewtop ... 6&p=398145 @X-SHADOW : don't copy the code without check if he work Link to comment
drk Posted March 30, 2012 Share Posted March 30, 2012 X-SHADOW, your code is completely wrong. Link to comment
Castillo Posted March 30, 2012 Share Posted March 30, 2012 How could it ever work if you forgot to add this: addEvent ( "stopCarRadio", true ) addEventHandler ( "stopCarRadio", root, function ( car ) if ( isElement ( carSounds[ car ] ) ) then destroyElement ( carSounds[ car ] ) end end ) 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