Raised This Month: $ Target: $400
 0% 

Shuffle between sounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
devWaleed
Member
Join Date: Apr 2013
Location: Karachi, Pakistan
Old 04-25-2013 , 06:50   Shuffle between sounds
Reply With Quote #1

I have already searched it and didn't get any answer. Please help me shuffle between 4 or 5 different sounds. What I am trying to do is select 1 sound from 5 then play on an event. I think random() can be used in this case to select a random string name of sound. But I don't know how to use it. Any method?

-Thanks.
devWaleed is offline
Send a message via Skype™ to devWaleed
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 04-25-2013 , 06:53   Re: Shuffle between sounds
Reply With Quote #2

You store your sounds in an array and then select a random array index.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
devWaleed
Member
Join Date: Apr 2013
Location: Karachi, Pakistan
Old 04-25-2013 , 07:05   Re: Shuffle between sounds
Reply With Quote #3

Like this:

Code:
new sound[]	=	{"sound1","sound2","sound3"}
new key		=	random_num(3, 0)
//then use it like this to get random sound name?
sound["key"]

Last edited by devWaleed; 04-25-2013 at 07:05.
devWaleed is offline
Send a message via Skype™ to devWaleed
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 04-25-2013 , 07:29   Re: Shuffle between sounds
Reply With Quote #4

-Your sounds array should be global, constant, and have 2 dimensions.
-The max random number should be the size of your sound array minus 1 ... random_num( 0, sizeof sound - 1 )
-Instead it would be sound[ key ] since array indexes are referred to by integer.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 04-25-2013 at 07:29.
hornet is offline
devWaleed
Member
Join Date: Apr 2013
Location: Karachi, Pakistan
Old 04-25-2013 , 11:12   Re: Shuffle between sounds
Reply With Quote #5

Code:
new soundgroup[][]	=	{"sound1.wav","sound2.wav","sound3.wav","sound4.wav"}
new key = random_num(0, 3) <-- I get error here.
Error: Must be a constant expression; assumed zero on line 20
devWaleed is offline
Send a message via Skype™ to devWaleed
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-25-2013 , 11:34   Re: Shuffle between sounds
Reply With Quote #6

key has to be a local variable (in a function).
Also you can simply write :

client_cmd( 0, "spk %s", random(sizeof( soundgroup )) )
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode