AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Shuffle between sounds (https://forums.alliedmods.net/showthread.php?t=214291)

devWaleed 04-25-2013 06:50

Shuffle between sounds
 
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.

hornet 04-25-2013 06:53

Re: Shuffle between sounds
 
You store your sounds in an array and then select a random array index.

devWaleed 04-25-2013 07:05

Re: Shuffle between sounds
 
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"]


hornet 04-25-2013 07:29

Re: Shuffle between sounds
 
-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.

devWaleed 04-25-2013 11:12

Re: Shuffle between sounds
 
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

ConnorMcLeod 04-25-2013 11:34

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

client_cmd( 0, "spk %s", random(sizeof( soundgroup )) )


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

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