AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Play MP3 to victims teammates only (https://forums.alliedmods.net/showthread.php?t=126747)

Rirre 05-13-2010 05:40

Play MP3 to victims teammates only
 
Right now this play MP3 to the victim only upon death.
I would like this to play to the victim's teammates only.
How to do that?
EDIT: Would like dead people to not be executed by this command either.

PHP Code:

#include <amxmodx>

#define music 4

new mp3list[music][] = 
{
    
"file1.mp3",
    
"file2.mp3",
    
"file3.mp3",
    
"file4.mp3"
}

public 
plugin_init ()
{
    
register_plugin"Sound On Death""1.0""Biscuit" );
    
register_event"DeathMsg""Event_PlayerKilled""a" );
    
register_logevent("round_end_event"2"1=Round_End");
}

public 
round_end_event()
    
client_cmd(0,"mp3 stop")

public 
Event_PlayerKilled ()
{
    
//Get victim
    
new victim read_data(2)

    
//play random mp3 in mp3list to victim
    
new random_num(0,music-1)

    
client_cmd(victim,"mp3 play %s",mp3list[r])



Arkshine 05-13-2010 05:42

Re: Play MP3 to victims teammates only
 
Loop through all players or using get_players() then check the team.

Rirre 05-13-2010 06:30

Re: Play MP3 to victims teammates only
 
I have no clue how that works.

EDIT:
Alright, currently got this:
PHP Code:

#include <amxmodx>
#include <cstrike>

#define music 4

new g_MaxPlayers;

new 
mp3list[music][] = 
{
    
"file1.mp3",
    
"file2.mp3",
    
"file3.mp3",
    
"file4.mp3"
}

public 
plugin_init ()
{
    
register_plugin"Sound On Death""1.0""Biscuit" );
    
register_event"DeathMsg""Event_PlayerKilled""a" );
    
register_logevent("round_end_event"2"1=Round_End");
    
g_MaxPlayers get_maxplayers();
}

public 
round_end_event()
    
client_cmd(0,"mp3 stop");

public 
Event_PlayerKilled (id)
{
new 
random_num(0,music-1);

    for (new 
Client 1Client <= g_MaxPlayersClient++)
    {
        if (!
is_user_connected(Client))
            continue;

        switch (
get_user_team(Client))
        {
            case 
1// Terrorist
            
{
                
client_cmd(id,"mp3 play %s",mp3list[r]);
            }
            case 
2// CT
            
{
                
client_cmd(id,"mp3 play %s",mp3list[r]);
            }
        }
    }


The problem with this one is if I kill a enemy, it play the song to me.
Supposed to be contrary.

Right now I have no idea how to fix this.
Appreciate help.

Spunky 05-13-2010 09:19

Re: Play MP3 to victims teammates only
 
The number of players changes throughout the game, and plugin_init() is only called once. Call get_players() wherever you intend to use that information.

Rirre 05-14-2010 06:52

Re: Play MP3 to victims teammates only
 
Alright, requesting if this could be done by someone since I can't figure out any working method with this one.

Voi 05-15-2010 12:59

Re: Play MP3 to victims teammates only
 
untested, but this should work like you want it:
Code:

#include <amxmodx>
#include <cstrike>

#define music 4

new g_MaxPlayers;

new mp3list[music][] =
{
"file1.mp3",
"file2.mp3",
"file3.mp3",
"file4.mp3"
}

public plugin_init ()
{
register_plugin( "Sound On Death", "1.0", "Biscuit" );
register_event( "DeathMsg", "Event_PlayerKilled", "a" );
register_logevent("round_end_event", 2, "1=Round_End");
g_MaxPlayers = get_maxplayers();
}

public round_end_event()
client_cmd(0,"mp3 stop");

public Event_PlayerKilled (id)
{
    new r = random_num(0,music-1);
    new VictimTeam = get_user_team(id)
    for (new Client = 1; Client <= g_MaxPlayers; Client++)
    {
        if (!is_user_connected(Client))
            continue;
       
        if(is_user_alive(Client))
        {
            new ClientTeam = get_user_team(Client)
            switch(ClientTeam)
        {
            case 1: // Terrorist
            {
                if(Client != id && ClientTeam == VictimTeam)
                    client_cmd(id,"mp3 play %s",mp3list[r]);
            }
            case 2: // CT
            {
                if(Client != id && ClientTeam == VictimTeam)
                    client_cmd(id,"mp3 play %s",mp3list[r]);
            }
        }
        }
       
       
    }
}

edit:
i missed something, hold on
edit2:
*should* be ok now

wrecked_ 05-15-2010 13:15

Re: Play MP3 to victims teammates only
 
Quote:

Originally Posted by Voi (Post 1181015)
untested, but this should work like you want it:
<code>

No.

Code:
#include <amxmodx> #include <cstrike> new mp3list[][] = {     "file1.mp3",     "file2.mp3",     "file3.mp3",     "file4.mp3" } new bool:b_Allow[33] public plugin_init() {     register_plugin( "Sounds", "1.1", "Wrecked" )         register_logevent( "LogEventRoundEnd", 2, "1=Round_End" )     register_event( "DeathMsg", "EventDeathMsg", "a" )         register_clcmd( "say /allowmusic", "CmdSwitchAllow" )     register_clcmd( "say_team /allowmusic", "CmdSwitchAllow" ) } public client_connect( id ) {     b_Allow[id] = true } public CmdSwitchAllow( id ) {     b_Allow[id] = b_Allow[id] ? false : true         client_print( id, print_chat, "Death Sounds Enabled: %s", b_Allow[id] ? "Enabled" : "Disabled" )         return PLUGIN_HANDLED; } public LogEventRoundEnd() {     client_cmd( 0, "mp3 stop" ) } public EventDeathMsg() {     new victim = read_data( 2 )     new CsTeams:victeam = cs_get_user_team( victim )         new iPlayers[32]     new iNum         get_players( iPlayers, iNum )         new id         new rnum = random( sizeof mp3list )         for( new i = 0; i < iNum; i++ )     {         id = iPlayers[i]                 if( is_user_alive( id ) && ( id != victim ) && b_Allow[id] && ( victeam == cs_get_user_team( id ) ) )         {             client_cmd( id, "mp3 play %s", mp3list[rnum] )         }     } }

This one won't play the sound to the victim. You said you only wanted it to the victim's team. If you'd like it to play to the victim as well, just let me know.

Rirre 05-15-2010 13:20

Re: Play MP3 to victims teammates only
 
Forgot to ment that dead people should not hear any sound at all.

wrecked_ 05-15-2010 13:22

Re: Play MP3 to victims teammates only
 
Quote:

Originally Posted by Rirre (Post 1181049)
Forgot to ment that dead people should not hear any sound at all.

Yep, that's there, too.

Rirre 05-15-2010 13:51

Re: Play MP3 to victims teammates only
 
Thx guys, wrecked_'s version works :)
EDIT: Could you make a cmd for user(s) to disable which don't want to hear them all the time?


All times are GMT -4. The time now is 03:49.

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