Raised This Month: $ Target: $400
 0% 

prechacing and emiting sounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
StormZone
BANNED
Join Date: Nov 2008
Location: [RO]Hunedoara/Petrosani
Old 10-06-2009 , 14:46   prechacing and emiting sounds
Reply With Quote #1

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.
StormZone is offline
Send a message via Yahoo to StormZone Send a message via Skype™ to StormZone
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-06-2009 , 14:55   Re: prechacing and emiting sounds
Reply With Quote #2

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 )
__________________
Arkshine is offline
StormZone
BANNED
Join Date: Nov 2008
Location: [RO]Hunedoara/Petrosani
Old 10-06-2009 , 15:34   Re: prechacing and emiting sounds
Reply With Quote #3

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?
StormZone is offline
Send a message via Yahoo to StormZone Send a message via Skype™ to StormZone
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 10-06-2009 , 15:36   Re: prechacing and emiting sounds
Reply With Quote #4

Just remove file_exists lines
__________________
xPaw is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-06-2009 , 15:37   Re: prechacing and emiting sounds
Reply With Quote #5

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.
__________________
Arkshine is offline
StormZone
BANNED
Join Date: Nov 2008
Location: [RO]Hunedoara/Petrosani
Old 10-06-2009 , 15:43   Re: prechacing and emiting sounds
Reply With Quote #6

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 );
        } 

Last edited by StormZone; 10-06-2009 at 15:56.
StormZone is offline
Send a message via Yahoo to StormZone Send a message via Skype™ to StormZone
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 10-06-2009 , 17:01   Re: prechacing and emiting sounds
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
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 );
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-06-2009 , 17:11   Re: prechacing and emiting sounds
Reply With Quote #8

I had the same idea, but Emp already posted it, so...
vitorrd is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-06-2009 , 17:13   Re: prechacing and emiting sounds
Reply With Quote #9

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.
__________________
Arkshine is offline
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-06-2009 , 17:18   Re: prechacing and emiting sounds
Reply With Quote #10

Quote:
Originally Posted by Arkshine View Post
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.
vitorrd 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 22:33.


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