Raised This Month: $12 Target: $400
 3% 

AMXX Module: EmitSound2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
slLent
Member
Join Date: Apr 2010
Location: Tomsk, Russia
Old 04-11-2014 , 07:11   AMXX Module: EmitSound2
Reply With Quote #1

EmitSound2


Description:
The new native emit_sound allowing send message SVC_SOUND for only one client.

Quote:
/*
* id - Player index which play the sound.
* receiver - Player index which receives the sound.
* channel - Channel
* sample - Sample sound
* volume - Volume sound
* attn - Attenuation
* pitch - Pitch sound
* origin - Coordinates play the sound if "id" equal 0 (worldspawn)
*/

native emit_sound2(id,receiver,channel,const sample[],Float:volume,Float:attn,flags,pitch,Float: origin[3] = {0.0,0.0,0.0});
Example:
PHP Code:
#include <amxmodx>

native emit_sound2(id,receiver,channel,const sample[],Float:volume,Float:attn,flags,pitch,Float:origin[3] = {0.0,0.0,0.0});

public 
plugin_init()
{
    
register_clcmd("say /emit2","cmdSound");
}

public 
cmdSound(id)
{
    
emit_sound2(id,id,CHAN_WEAPON,"weapons/ak47-1.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM);

or for everybody, apart from "id" player

PHP Code:
public cmdSound(id)
{
    for(new 
1<= get_maxplayers(); i++)
    {
        if(!
is_user_connected(i) || == id)
            continue;

        
emit_sound2(id,i,CHAN_WEAPON,"weapons/ak47-1.wav",VOL_NORM,ATTN_NORM,0,PITCH_NORM);
    }



View source file

Attached Files
File Type: zip EmitSound2.zip (20.2 KB, 438 views)

Last edited by slLent; 04-11-2014 at 23:16.
slLent is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-12-2014 , 08:28   Re: AMXX Module: EmitSound2
Reply With Quote #2

Is there advantages from using the default EmitSound()?
If I were you I would make that perfectly clear because I would never download a module for a function that I already have.
Give an example where EmitSound() would not work where this would create a solution for that problem.
__________________
Black Rose is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-12-2014 , 08:40   Re: AMXX Module: EmitSound2
Reply With Quote #3

emit_sound() can't be used for one player. emit_sound2() is basically the same but allow only one player hearing ambient sound.

You could do the same by calling SVC_SPAWNSTATICSOUND.
__________________

Last edited by Arkshine; 04-12-2014 at 08:40.
Arkshine is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-12-2014 , 08:51   Re: AMXX Module: EmitSound2
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
emit_sound() can't be used for one player. emit_sound2() is basically the same but allow only one player hearing ambient sound.

You could do the same by calling SVC_SPAWNSTATICSOUND.
But SVC_SPAWNSTATICSOUND would not require a module. I can't see the downside of that.
__________________

Last edited by Black Rose; 04-12-2014 at 08:51.
Black Rose is offline
slLent
Member
Join Date: Apr 2010
Location: Tomsk, Russia
Old 04-12-2014 , 12:10   Re: AMXX Module: EmitSound2
Reply With Quote #5

SVC_SPAWNSTATICSOUND channel has only CHAN_STATIC.
and also playback sound different quality

Can also use this method by PRoSToTeM@

PHP Code:
#include <amxmodx>

#define BIT(%0)            (1<<(%0))
#define BITSUM(%0)        (BIT(%0)-1)

new g_iWritingBits;
new 
g_iCurrentByte;

public 
plugin_init()
{
    
register_clcmd("say /emit2","cmdSound");
}
public 
cmdSound(id)
{
    
message_begin(MSG_ONE,SVC_SOUND,_,id);

    
MSG_StartBitWriting();

    new 
iFlags 0;

    
MSG_WriteBits(iFlags,9);
    
MSG_WriteBits(CHAN_WEAPON,3);
    
MSG_WriteBits(0,11);
    
MSG_WriteBits(precache_sound("weapons/ak47-1.wav"),8);

    
MSG_WriteOneBit(0);
    
MSG_WriteOneBit(0);
    
MSG_WriteOneBit(0);

    
MSG_EndBitWriting();
    
message_end();
}
MSG_StartBitWriting()
{
    
g_iWritingBits 0;
    
g_iCurrentByte 0;
}
MSG_WriteBits(iValue,iBits)
{
    if(
iBits 25)
    {
        return;
    }
    
g_iCurrentByte |= ((iValue BITSUM(iBits)) << g_iWritingBits);
    
g_iWritingBits += iBits;

    while(
g_iWritingBits >= 8)
    {
        
write_byte(g_iCurrentByte BITSUM(8));

        
g_iCurrentByte >>= 8;
        
g_iWritingBits -= 8;
    }
}
MSG_WriteOneBit(iBit)
{
    
MSG_WriteBits(iBit,1);
}
MSG_EndBitWriting()
{
    if(
g_iWritingBits)
    {
        
write_byte(g_iCurrentByte);
    }

EmitSound2 was written mainly for anti-cheat, maybe prove useful for someone

Last edited by slLent; 06-05-2016 at 06:37.
slLent is offline
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 07-12-2021 , 13:52   Re: AMXX Module: EmitSound2
Reply With Quote #6

[AMXX] Plugin "my_test_plugin.amxx" failed to load: Plugin uses an unknown function (name "emit_sound2") - check your modules.ini.

and module is loaded correctly:
[10] EmitSound2 RUN - sound_amxx.dll v0.3 pl1 ANY ANY

Why happen this?
Windows environment
baneado is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-13-2021 , 15:37   Re: AMXX Module: EmitSound2
Reply With Quote #7

Quote:
Originally Posted by baneado View Post
[AMXX] Plugin "my_test_plugin.amxx" failed to load: Plugin uses an unknown function (name "emit_sound2") - check your modules.ini.

and module is loaded correctly:
[10] EmitSound2 RUN - sound_amxx.dll v0.3 pl1 ANY ANY

Why happen this?
Windows environment
Use rh_emit_sound2 from ReAPI instead.
DarthMan is offline
Reply


Thread Tools
Display Modes

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 19:37.


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