AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Sound File (https://forums.alliedmods.net/showthread.php?t=209733)

Erdener 03-01-2013 06:41

Sound File
 
How can i run sound files?

PHP Code:

Slayaim(id)
{
    new 
playerbody;
    new 
szPlayerName[32];
    
get_user_aiming(idplayerbody);
    
get_user_name(playerszPlayerName32);

    if (
get_user_flags(id) & ADMIN_BAN)
    {
        if (
is_user_alive(player) && get_user_flags(player) & ADMIN_IMMUNITY)
        {
            
client_print(id"You cant slay some one with Immunity!");
        }
        else
        if (
is_user_alive(player))
        {
            
user_kill(player);
            
client_print(player"You have been Slayed!");
            
client_print(id"You just Slayed %s!"szPlayerName);
            
client_cmd(0"spk %s"sounds[random_num(0charsmax(sounds))]);
        }
    }



xfirestorm 03-01-2013 06:53

Re: Sound File
 
precache_sound("path/to/sound/file.wav);

client_cmd(0,... change to: client_cmd(<id_of_player_to_play_sound_on>,.. .

Erdener 03-01-2013 07:06

Re: Sound File
 
Yes, i know i add precache_sound();

but, i would like to use a random sound.

EDIT:

PHP Code:

new sounds[][] =
{
    
"filename/xxx.wav",
    
"filename/yyy.wav"
}; 


xfirestorm 03-01-2013 07:21

Re: Sound File
 
Don't think you can precache the whole array at once, you'd probably need to precache each sound, one by one.
Then in random instead of charsmax(sounds) use sizeof(sounds)

hornet 03-01-2013 07:38

Re: Sound File
 
Quote:

Originally Posted by xfirestorm (Post 1904328)
Don't think you can precache the whole array at once, you'd probably need to precache each sound, one by one.
Then in random instead of charsmax(sounds) use sizeof(sounds)

An array can be precached using a loop.
And there's nothing wrong with using charsmax, apart from readability reasons, since:

PHP Code:

#define charsmax(%1) (sizeof(%1)-1) 

@Erdener what exactly is your question?

YamiKaitou 03-01-2013 07:44

Re: Sound File
 
Quote:

Originally Posted by hornet (Post 1904344)
And there's nothing wrong with using charsmax, apart from readability reasons

In this case, it is wrong to use charsmax since if used you will never get the last sound file when you precache it or attempt to randomly play it

hornet 03-01-2013 07:48

Re: Sound File
 
Quote:

Originally Posted by YamiKaitou (Post 1904346)
In this case, it is wrong to use charsmax since if used you will never get the last sound file when you precache it or attempt to randomly play it

Oh whoops my bad soz :\
lol think before say ay.

xfirestorm 03-01-2013 07:50

Re: Sound File
 
Quote:

Originally Posted by hornet (Post 1904344)
An array can be precached using a loop.

This is still precached one-by-one, since you can't pass the whole array into precache_sound.
You just don't type the same code over and over again...

Backstabnoob 03-01-2013 08:57

Re: Sound File
 
Code:
new const c_SoundsToPlay[ ][ ] = {     "sound/sound1.wav",     "sound/sound2.wav",     "sound/sound3.wav" } public plugin_precache( ) {     for( new iCnt; iCnt < sizeof c_SoundsToPlay; iCnt ++ )         precache_generic( c_SoundsToPlay[ iCnt ] ) } client_cmd( 0, "spk %s", c_SoundsToPlay[ random( sizeof c_SoundsToPlay ) ] )

Erdener 03-01-2013 12:15

Re: Sound File
 
hmmm, nice thnx


All times are GMT -4. The time now is 21:36.

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