AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   prechacing and emiting sounds (https://forums.alliedmods.net/showthread.php?t=105631)

StormZone 10-06-2009 14:46

prechacing and emiting sounds
 
is there a better way of prechacing a sound and emiting it instead of these?
PHP Code:

if ( file_exists "sound/warcraft3/impalehit.wav" ) )
    {
        
precache_sound "warcraft3/impalehit.wav" );
    } 

PHP Code:

//impale
            
if ( file_exists"sound/warcraft3/impalehit.wav" ) == )
            {
                
emit_soundenemyCHAN_ITEM"warcraft3/impalehit.wav"1.0ATTN_NORM0PITCH_NORM );
            } 

Thanks.

Arkshine 10-06-2009 14:55

Re: prechacing and emiting sounds
 
What you show precache and emit. I don't understand what's your problem. ( Though checking a second time if the file exists would not be necessary )

StormZone 10-06-2009 15:34

Re: prechacing and emiting sounds
 
thats want y want to know.
Y want to make the code more eficient.
So how should y make this code to be more better?

xPaw 10-06-2009 15:36

Re: prechacing and emiting sounds
 
Just remove file_exists lines

Arkshine 10-06-2009 15:37

Re: prechacing and emiting sounds
 
Without or with the both checks doesn't matter, it's not here you will improve your code. Though I would remove the both check, it's not really needed.

StormZone 10-06-2009 15:43

Re: prechacing and emiting sounds
 
ok thanks to all of you.
This is not my code.Is from Yaurs version of UWC3 and y am helping him to clean up the code.

If y encounter eny more question can y post here?

edit:
instead of using this
PHP Code:

if( Util_Should_Msg_Client(enemy) )
        {
            
client_printenemyprint_chat"%L"enemy"IMPALE3"MODname1 );

            
//impale
            
if ( file_exists"sound/warcraft3/impalehit.wav" ) == )
            {
                
emit_soundenemyCHAN_ITEM"warcraft3/impalehit.wav"1.0ATTN_NORM0PITCH_NORM );
            }
        } 

it should be this yes?
PHP Code:

        if( Util_Should_Msg_Client(enemy) )
        {
            
client_printenemyprint_chat"%L"enemy"IMPALE3"MODname1 );
            
//impale
            
emit_soundenemyCHAN_ITEM"warcraft3/impalehit.wav"1.0ATTN_NORM0PITCH_NORM );
        } 


Emp` 10-06-2009 17:01

Re: prechacing and emiting sounds
 
Quote:

Originally Posted by Arkshine (Post 954225)
What you show precache and emit. I don't understand what's your problem. ( Though checking a second time if the file exists would not be necessary )

It would be necessary because if the file doesn't exist, it would still try to emit it (even though it wasn't precached).

A better way IMO, is store the sound(s) in a global, also have whether or not it existed.
Code:

enum _:SOUNDS{
    SOUND_1,
    SOUND_2,
    SOUND_3,
}

new Sounds[SOUNDS][] = {
    "my_sound.wav",
    "my_sound2.wav",
    "my_sound3.wav"
}

new SoundExist[SOUNDS]

public plugin_precache()
{
    for( new i; i<SOUNDS; i++ )
    {
          if ( (SoundExist[i] = file_exists ( Sounds[i] ) ) )
          {
              precache_sound ( Sounds[i] )
          }
    }
}

OtherFunction(enemy)
{
    if( SoundExist[ SOUND_1 ] )
          emit_sound( enemy, CHAN_ITEM, Sounds[SOUND_1], 1.0, ATTN_NORM, 0, PITCH_NORM );
}


vitorrd 10-06-2009 17:11

Re: prechacing and emiting sounds
 
I had the same idea, but Emp already posted it, so...

Arkshine 10-06-2009 17:13

Re: prechacing and emiting sounds
 
Well, it's true, you're right. I was just thought in this case sounds are already provided -by default-, that's why these checks are not really worth. I would check only if it's custom sounds provided by the client from a file for example.

vitorrd 10-06-2009 17:18

Re: prechacing and emiting sounds
 
Quote:

Originally Posted by Arkshine (Post 954329)
Well, it's true, you're right. I was just thought in this case sounds are already provided -by default-, that's why these checks are not really worth. I would check only if it's custom sounds provided by the client from a file for example.

You have a point there.
If you use the plugin then having the sounds is kinda the least you should do, haha.


All times are GMT -4. The time now is 22:33.

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