myonlake Posted January 3, 2012 Posted January 3, 2012 (edited) Hello there, I was thinking of a random sound fetching from a table with math.random function and decided to try it. However, instead of playing the songs, it gives me an error about that attachElements, which could be relative to the table stuff, something wrong there? By the way, this is not the whole script and it wouldn't help much even if I did give you that. It's somewhere here. I have everything in meta.xml and in the server side. local soundtable = { "images/mmmp.mp3", "images/cv.mp3", "images/rr.wav", "images/mn.mp3", "images/wwd.mp3" } function musicpod(source) local x, y, z = getElementPosition(source) local m3d = playSound3D(math.random(#soundtable), x, y, z, false) setSoundVolume(m3d, 0.5) setSoundMaxDistance(m3d, 50) attachElements(m3d, source) end addEvent("onPodClick", true) addEventHandler("onPodClick", getRootElement(), musicpod) Edited May 30, 2019 by myonlake If I helped you, please click the like button on the right Thanks!
Kenix Posted January 3, 2012 Posted January 3, 2012 Try local soundtable = { "images/mmmp.mp3", "images/cv.mp3", "images/rr.wav", "images/mn.mp3", "images/wwd.mp3" } function musicpod( ) local x, y, z = getElementPosition( source ) local m3d = playSound3D( math.random( 1,#soundtable ), x, y, z, false ) setSoundVolume( m3d, 0.5) setSoundMaxDistance( m3d, 50 ) attachElements( m3d, source ) end addEvent("onPodClick", true) addEventHandler("onPodClick", root, musicpod) If it not work please show how you trigger event "onPodClick" http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
myonlake Posted January 3, 2012 Author Posted January 3, 2012 Doesn't work. triggerClientEvent("onPodClick", source, source) If I helped you, please click the like button on the right Thanks!
Kenix Posted January 3, 2012 Posted January 3, 2012 (edited) Full code please how you trigger P.S why you trigger source to argument function ? source is variable in event and not need add to argument to function Correct triggerClientEvent("onPodClick", source) https://wiki.multitheftauto.com/wiki/Event Edited January 3, 2012 by Guest http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
myonlake Posted January 3, 2012 Author Posted January 3, 2012 Not going to give you my full code, it has too much details. I am not a newbie here, so why should you think that my source on the script is wrong? I know it's the right one. If I helped you, please click the like button on the right Thanks!
Kenix Posted January 3, 2012 Posted January 3, 2012 This is not a bug just why send 2 times if you pass, and so. Read https://wiki.multitheftauto.com/wiki/TriggerClientEvent where theElement How i fixed problem if idk how you trigger event. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
myonlake Posted January 3, 2012 Author Posted January 3, 2012 I removed the attachElements, didn't play the song. So, it's a problem with the table or so. If I helped you, please click the like button on the right Thanks!
Kenix Posted January 3, 2012 Posted January 3, 2012 Give me full code i fix it http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
DiSaMe Posted January 3, 2012 Posted January 3, 2012 local m3d = playSound3D(math.random(#soundtable), x, y, z, false) The error is here. You get the random number, but instead of using it as a table index, you're passing it directly to the function. You need to write soundtable[math.random(#soundtable)] as the first argument. -
Kenix Posted January 3, 2012 Posted January 3, 2012 Yeah my error This should work: local soundtable = { "images/mmmp.mp3", "images/cv.mp3", "images/rr.wav", "images/mn.mp3", "images/wwd.mp3" } function musicpod( ) local x, y, z = getElementPosition( source ) local m3d = playSound3D( soundtable[ math.random( 1,#soundtable ) ], x, y, z, false ) setSoundVolume( m3d, 0.5) setSoundMaxDistance( m3d, 50 ) attachElements( m3d, source ) end addEvent("onPodClick", true) addEventHandler("onPodClick", root, musicpod) http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
myonlake Posted January 3, 2012 Author Posted January 3, 2012 Thanks to both of you Works now. If I helped you, please click the like button on the right Thanks!
Kenix Posted January 3, 2012 Posted January 3, 2012 No problem 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