Raised This Month: $32 Target: $400
 8% 

Emit sound to specific team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 04-22-2017 , 06:44   Emit sound to specific team
Reply With Quote #1

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


Last edited by Krtola; 04-22-2017 at 06:44.
Krtola is offline
Send a message via Skype™ to Krtola
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-22-2017 , 06:52   Re: Emit sound to specific team
Reply With Quote #2

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

Last edited by edon1337; 04-22-2017 at 08:24.
edon1337 is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 04-22-2017 , 07:24   Re: Emit sound to specific team
Reply With Quote #3

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...
__________________
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2017 , 07:48   Re: Emit sound to specific team
Reply With Quote #4

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.
__________________

Last edited by HamletEagle; 04-22-2017 at 07:49.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-22-2017 , 08:24   Re: Emit sound to specific team
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
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?
__________________
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-22-2017 , 08:36   Re: Emit sound to specific team
Reply With Quote #6

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

__________________

Last edited by OciXCrom; 04-22-2017 at 08:38.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Krtola
Veteran Member
Join Date: Oct 2013
Location: Serbia
Old 04-22-2017 , 08:38   Re: Emit sound to specific team
Reply With Quote #7

edon1337 tested and dont work.
Krtola is offline
Send a message via Skype™ to Krtola
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2017 , 10:13   Re: Emit sound to specific team
Reply With Quote #8

Quote:
Originally Posted by edon1337 View Post
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.
__________________
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-22-2017 , 10:20   Re: Emit sound to specific team
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
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.
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2017 , 10:32   Re: Emit sound to specific team
Reply With Quote #10

Quote:
Originally Posted by edon1337 View Post
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.
__________________

Last edited by HamletEagle; 04-22-2017 at 11:41.
HamletEagle 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 03:40.


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