AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   AMXX Module: EmitSound2 (https://forums.alliedmods.net/showthread.php?t=238457)

slLent 04-11-2014 07:11

AMXX Module: EmitSound2
 
1 Attachment(s)
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


Black Rose 04-12-2014 08:28

Re: AMXX Module: EmitSound2
 
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.

Arkshine 04-12-2014 08:40

Re: AMXX Module: EmitSound2
 
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.

Black Rose 04-12-2014 08:51

Re: AMXX Module: EmitSound2
 
Quote:

Originally Posted by Arkshine (Post 2123539)
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.

slLent 04-12-2014 12:10

Re: AMXX Module: EmitSound2
 
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 :wink:

baneado 07-12-2021 13:52

Re: AMXX Module: EmitSound2
 
[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

DarthMan 07-13-2021 15:37

Re: AMXX Module: EmitSound2
 
Quote:

Originally Posted by baneado (Post 2752675)
[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.


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

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