AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Delay Emit sound (https://forums.alliedmods.net/showthread.php?t=215749)

cstrike37 05-11-2013 21:54

[SOLVED] Delay Emit sound
 
How do you add a delay to emit sound? It's kinda annoying hearing the pain sound every time you get hit.
Ex. If you get hit then a pain sound will play and if u get hit again within 3 second then the pain sound will not play.

claudiuhks 05-11-2013 22:06

Re: Delay Emit sound
 
PHP Code:

const FloatIntervalBetweenSounds 3.0;

new 
Floatg_Time;

public Function( 
/* ... */ ) {
  if( 
get_gametime( ) - g_Time IntervalBetweenSounds ) {
    
emit_sound/* ... */ );

    
g_Time get_gametime( );

    return 
FMRES_SUPERCEDE;
  }

  else return 
FMRES_SUPERCEDE;

  return 
FMRES_IGNORED;



Blizzard_87 05-11-2013 22:08

Re: Delay Emit sound
 
try the client_cmd ( 0, spk........

see if that works any better.

claudiuhks 05-11-2013 22:14

Re: Delay Emit sound
 
Quote:

Originally Posted by Blizzard_87 (Post 1950275)
try the client_cmd ( 0, spk........

see if that works any better.

That won't be emitted. That will be listened by all players. If you emit something, the sound will be listened locally, not in entirely map.

cstrike37 05-12-2013 01:07

Re: Delay Emit sound
 
Update:
Hi, it did work but I'm having a bit of a problem.
The knife sound disappear after adding the pain sound delay.

PHP Code:

public fwEmitSound2(idchannel, const sound[], Float:volumeFloat:attnflagspitch)  
{
    if(!
is_user_connected(id))
    return 
FMRES_IGNORED;  
    
cs_get_user_model(idmodelcharsmax(model)) 
    
    if( 
get_gametime( ) - g_Time IntervalBetweenSounds ) {
    if(
equal(sound[7],"bhit",4) && equal(model"sas") == 1
    
engfunc(EngFunc_EmitSoundidchannelpain_spk[random_num(0sizeof pain_spk 1)], 1.00.92flagspitch);  
    
    
g_Time get_gametime( );

    return 
FMRES_SUPERCEDE;
    }

    else return 
FMRES_SUPERCEDE;

    return 
FMRES_IGNORED;



claudiuhks 05-12-2013 01:45

Re: Delay Emit sound
 
For Counter-Strike I think this should work. You will have to select the sounds you want.

PHP Code:

#include amxmodx
#include fakemeta
#include cstrike

new const FloatIntervalBetweenSounds 0.85;

new const 
g_PlayerHurtSounds[ ][ ] = {
  
"player/bhit_flesh-1.wav"// health
  
"player/bhit_flesh-2.wav"// health
  
"player/bhit_flesh-3.wav"// health
  
"player/bhit_helmet-1.wav"// armor
  
"player/bhit_kevlar-1.wav"// armor
  
"player/headshot1.wav"// headshot
  
"player/headshot2.wav"// headshot
  
"player/headshot3.wav"// headshot
  
"player/pl_die1.wav"// < something like "ah" >
  
"player/pl_fallpain1.wav"// fall pain
  
"player/pl_fallpain2.wav"// fall pain
  
"player/pl_fallpain3.wav"// fall pain
  
"player/pl_pain2.wav"// pain
  
"player/pl_pain4.wav"// pain
  
"player/pl_pain5.wav"// pain
  
"player/pl_pain6.wav"// pain
  
"player/pl_pain7.wav"// pain
  
"player/pl_shot1.wav" // < something like "uh" >
};

new const 
g_Replacements[ ][ ] = {
  
"misc/talk.wav" // bip
};

new 
Floatg_Time 0.0;

boolIsPlayerHurtSoundSound[ ] ) {
  static 
Iterator;

  for( 
Iterator 0Iterator sizeof g_PlayerHurtSoundsIterator ++ )
    if( 
equaliSoundg_PlayerHurtSoundsIterator ] ) )
      return 
true;

  return 
false;
}

public 
plugin_init( )
  
register_forwardFM_EmitSound"EmitSound" );

public 
plugin_precache( ) {
  static 
Iterator;

  for( 
Iterator 0Iterator sizeof g_ReplacementsIterator ++ )
    
precache_soundg_ReplacementsIterator ] );
}

public 
EmitSoundEntityChannelSound[ ], FloatVolumeFloatAttenuationFlagsPitch ) {
  static 
MaximumClients;

  if( !
MaximumClients )
    
MaximumClients get_maxplayers( );

  if( 
<= Entity <= MaximumClients ) {
    static 
Model32 ], boolIsHurtSoundboolIsSas;

    
cs_get_user_modelEntityModelsizeof Model );

    
IsHurtSound IsPlayerHurtSoundSound );

    
IsSas boolequaliModel"sas" );

    if( 
IsHurtSound ) {
      if( 
IsSas ) {
        if( 
get_gametime( ) - g_Time IntervalBetweenSounds ) {
          
emit_soundEntityChannelg_Replacementsrandom_num0sizeof g_Replacements ) ], VOL_NORM0.92FlagsPitch );

          
g_Time get_gametime( );

          return 
FMRES_SUPERCEDE;
        }

        else
          return 
FMRES_SUPERCEDE;
      }
    }
  }

  return 
FMRES_IGNORED;



cstrike37 05-12-2013 01:56

Re: Delay Emit sound
 
now its working :D
Ty sooo much!!

cstrike37 05-12-2013 02:35

Re: [SOLVED] Delay Emit sound
 
Is it also possible to add a check if the bot has the model?

claudiuhks 05-12-2013 02:46

Re: [SOLVED] Delay Emit sound
 
Quote:

Originally Posted by cstrike37 (Post 1950343)
Is it also possible to add a check if the bot has the model?

I can't understand. I think you can use

PHP Code:

cs_get_user_model 

for bots.

If it won't work, then try

PHP Code:

static ClientModel32 ];

get_user_infoClient"model"Modelsizeof Model ); 

To check if is a Fake Client, use

PHP Code:

static ClientboolIsBot;

IsBot boolis_user_botClient ); 


cstrike37 05-12-2013 03:34

Re: [SOLVED] Delay Emit sound
 
worked TYY :D:D:D:D
:up::up::up:


All times are GMT -4. The time now is 16:24.

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