kevin11 Posted June 17, 2010 Share Posted June 17, 2010 how can i set this to random like it picks 1 of the 3 sounds on death function soundOnWasted() local sound = playSound("server/wasted.wav",false) end addEventHandler ( "onClientPlayerWasted", getRootElement(), soundOnWasted ) function soundOnWasted() local sound = playSound("server/wasted1.wav",false) end addEventHandler ( "onClientPlayerWasted", getRootElement(), soundOnWasted ) function soundOnWasted() local sound = playSound("server/wasted2.wav",false) end addEventHandler ( "onClientPlayerWasted", getRootElement(), soundOnWasted ) Link to comment
50p Posted June 17, 2010 Share Posted June 17, 2010 To make something random, you usually have to make a table containing the data that you want to load randomly, or in this case, you can name your files with numbers and use a random number to load specific file. -- Lets say you have these 3 files: -- server/wasted1.wav, server/wasted2.wav, server/wasted3 local sound = playSound( "server/wasted" .. tostring( math.random( 1, 3 ) ) .. ".wav", false ); Link to comment
kevin11 Posted June 17, 2010 Author Share Posted June 17, 2010 To make something random, you usually have to make a table containing the data that you want to load randomly, or in this case, you can name your files with numbers and use a random number to load specific file. -- Lets say you have these 3 files: -- server/wasted1.wav, server/wasted2.wav, server/wasted3 local sound = playSound( "server/wasted" .. tostring( math.random( 1, 3 ) ) .. ".wav", false ); i tried this and renamed 2 of my sounds to 1.wav 2.wav but its not working function soundOnWasted() local sound = playSound( "server/wasted" .. tostring( math.random( 1, 2 ) ) .. ".wav", false ) end addEventHandler ( "onClientPlayerWasted", getRootElement(), soundOnWasted ) Link to comment
50p Posted June 17, 2010 Share Posted June 17, 2010 I hate it when people don't read carefully and I have to reply again saying the same thing... ... -- Lets say you have these 3 files: -- server/wasted1.wav, server/wasted2.wav, server/wasted3 ... If you name them 1.wav, 2.wav and 3.wav it will never work... Look at the string that is passed to the playSound in my code... does it lead to 1.wav? No, it leads to wasted1.wav. 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