AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   check if player dies (https://forums.alliedmods.net/showthread.php?t=196590)

cstrike37 09-23-2012 00:03

check if player dies
 
how do you check if the player dies?

example if he dies a sound will play.

Doc-Holiday 09-23-2012 01:51

Search

cstrike37 09-23-2012 02:24

Re: check if player dies
 
i got this
Code:

public DeathMsg()
{
        new kid = read_data(1)
        new vid = read_data(2)
       
        if( kid == vid )
                return PLUGIN_CONTINUE;
        if( !g_bIsVip[ vid ] )
                return PLUGIN_CONTINUE;
        new pnum, players[32]
        get_players( players, pnum )
        for( new i, tid; i < pnum; i++ )
        {
                tid = players[i]
                client_cmd(tid, "spk %s", die_spk[ random( 2 ) ]);

        }

        return PLUGIN_CONTINUE;
}

But the sound wont play when the player kills himself. It only plays when you got killed by a gun or from a fall

ConnorMcLeod 09-23-2012 03:10

Re: check if player dies
 
PHP Code:

#include <amxmodx>
#include <hamsandwich>

#define PLUGIN ""
#define VERSION "0.0.1"

new const g_szDeathSounds[][] = 
{
    
"",
    
"",
    
"",
    
""
}

public 
plugin_init()
{
    
RegisterHam(Ham_Killed"player""OnCBasePlayer_Killed_Post"true)
}

public 
plugin_precache()
{
    for(new 
iisizeof(g_szDeathSounds); i++)
    {
        
precache_soundg_szDeathSounds[i] )
    }
}

public 
OnCBasePlayer_Killed_PostidiAttackeriGib )
{
    new 
players[32], num
    get_players
(playersnum"ch")
    for(new 
iplayeri<numi++)
    {
        
player players[i]
        if( !
is_user_connecting(player) )
        {
            
client_cmd(id"spk %s"g_szDeathSoundsrandomsizeof(g_szDeathSounds) ) ])
        }
    }



Liverwiz 09-23-2012 08:36

Re: check if player dies
 
Quote:

Originally Posted by cstrike37 (Post 1804421)
i got this
Code:

public DeathMsg()
{
        new kid = read_data(1)
        new vid = read_data(2)
       
        if( kid == vid )
                return PLUGIN_CONTINUE;
        if( !g_bIsVip[ vid ] )
                return PLUGIN_CONTINUE;
        new pnum, players[32]
        get_players( players, pnum )
        for( new i, tid; i < pnum; i++ )
        {
                tid = players[i]
                client_cmd(tid, "spk %s", die_spk[ random( 2 ) ]);

        }

        return PLUGIN_CONTINUE;
}

But the sound wont play when the player kills himself. It only plays when you got killed by a gun or from a fall

did you try to understand that code at all? if(kid == vid) return PLUGIN_CONTINUE returns out of the function if the player killed himself. -if killer equals victim
Or search past that one bit of code?
1. These variable names are worse than MINE! -And that's saying something. (vid, kid, tid) how about victimID, killerID, tempID?
2. It includes things you don't need (or mentioned nothing of) g_bIsVip[vid]
3. If you're only indexing the players array once (to get the tempID) You don't need to store it in a variable. Just directly call players[i] but this is only true if you call it once. otherwise cache it as you have here.


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

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