AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Emit sound to specific team (https://forums.alliedmods.net/showthread.php?t=296483)

Krtola 04-22-2017 06:44

Emit sound to specific team
 
When player reload specific sound is played. That sound can hear all players,from TS and CT.
How can I make this sound heard only players on my team?

PHP Code:

public Event_OnReload ( const i_Ent )
{
        static 
idid pev i_Entpev_owner );
        
        if ( 
UTIL_IsWeaponReloading idi_Ent ) )
        {
            
emit_sound idCHAN_AUTOSoundListrandom_num0sizeof SoundList ) ], 1.0ATTN_NORM0PITCH_NORM );
        }



edon1337 04-22-2017 06:52

Re: Emit sound to specific team
 
Create a variable that will hold player's team, loop through all players and check if looped player's team isn't equal to the player who is reloading, if true use continue, else emit_sound with the variable that you looped.
Code:
new g_iMaxPlayers ; public plugin_init( ) {     g_iMaxPlayers = get_maxplayers( ) ; } public Event_OnReload ( const i_Ent ) {     static id; id = pev ( i_Ent, pev_owner );         new iTeam = get_user_team( id ) ;         if ( UTIL_IsWeaponReloading ( id, i_Ent ) )     {           for( new i = 1 ; i <= g_iMaxPlayers ; i++ ) {                         if( ! is_user_connected( i ) )             continue ;             if( iTeam != get_user_team( i ) )             continue ;                         emit_sound ( i, CHAN_AUTO, SoundList[ random_num( 0, sizeof SoundList - 1 ) ], 1.0, ATTN_NORM, 0, PITCH_NORM );         }     }         return PLUGIN_CONTINUE ; }

Depresie 04-22-2017 07:24

Re: Emit sound to specific team
 
I don't think you can do that, even the name suggests it, "emit a sound ( from a location )"
The only official way to do something like that is using the spk command

But, there may be a workaround, but i'm not sure if it would work..

One thing i was thinking was blocking the sound by hooking the emit sound forward ( if i remember right there should be something like that )

Another thing would be to use a specific channel, then for the specific players emit a mute sound on the same channel it should replace the previous sound...

HamletEagle 04-22-2017 07:48

Re: Emit sound to specific team
 
I'm tired of repeating it, but edon, that's not how you loop through all players. Your code will throw errors in 99,99% of cases.

edon1337 04-22-2017 08:24

Re: Emit sound to specific team
 
Quote:

Originally Posted by HamletEagle (Post 2514259)
I'm tired of repeating it, but edon, that's not how you loop through all players. Your code will throw errors in 99,99% of cases.

Huh?

OciXCrom 04-22-2017 08:36

Re: Emit sound to specific team
 
PHP Code:

for(new i0i++)
{
    if(
"edon1337" uses wrong loop)
        
message("edon1337""USE get_players() function")



Krtola 04-22-2017 08:38

Re: Emit sound to specific team
 
edon1337 tested and dont work.

HamletEagle 04-22-2017 10:13

Re: Emit sound to specific team
 
Quote:

Originally Posted by edon1337 (Post 2514264)
Huh?

How do you know that all slots from 1 to max players are filled? Using get_players is the proper way. Before asking why, search, you will find one million threads about that.

edon1337 04-22-2017 10:20

Re: Emit sound to specific team
 
Quote:

Originally Posted by HamletEagle (Post 2514291)
How do you know that all slots from 1 to max players are filled? Using get_players is the proper way. Before asking why, search, you will find one million threads about that.

is_user_connected .. ? Get_players has became an obsession to you, it's not like he's trying to make the fastest plugin ever. Module or not, they both do the same thing.

HamletEagle 04-22-2017 10:32

Re: Emit sound to specific team
 
Quote:

Originally Posted by edon1337 (Post 2514293)
is_user_connected .. ? Get_players has became an obsession to you, it's not like he's trying to make the fastest plugin ever. Module or not, they both do the same thing.

I simply don't understand why people want to use bad ways and even more, defend them. Why would you teach yourself bad practices? Why would you teach others bad practices?
That's not about speed after all, it's about keeping good practices while coding. If not, you'll just keep using poor ways over and over again, because who cares, right? At some points all this small things will start to matter. You already messed it by not adding the is_user_connected in the first place. If you would simply go with the right way you would not had any issue.

Do whatever you want, if you can't see that I'm trying to help, fine by me. Just don't tell other people to do the same.


All times are GMT -4. The time now is 17:47.

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