AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to check if player has killed somebody (https://forums.alliedmods.net/showthread.php?t=166956)

dreamedward 09-09-2011 16:02

How to check if player has killed somebody
 
So I was wondering how can I check does a specific player killed somebody in the round. I mean in round one Player from the CTs has killed 1, 2, 3... etc Ts(there is FriendlyFire On so i want only kills to the opposite team to be checked) and if he has killed somebody(without teammates) to do a function. But lets guess that in round two he hasn't killed nobody. Well he hasn't killed nobody so I don't want any function to be done. I hope you've understood me right. I'll be waiting for responces :)

Desikac 09-09-2011 17:07

Re: How to check if player has killed somebody
 
PHP Code:

#include <amxmodx>
#include <cstrike>

new KillCount[33]

public 
plugin_init() {
    
register_messageget_user_msgid"DeathMsg" ) , "death" )
    
register_logevent("ResetKills",2,"1=Round_Start")
}

public 
client_disconnect(id)
    
KillCount[id] = 0

    
public ResetKills(){
    new 
players[32] , inum
    get_players
(playersinum)
    for(new 
0inum; ++a)
        
KillCount[a] = 0
}
public 
death() {
    new 
attacker read_data(1);
    new 
victim read_data(2);
       
    if(
attacker == victim)
        return 
PLUGIN_CONTINUE
    
    
if(cs_get_user_team(attacker) == cs_get_user_team(victim))
        return 
PLUGIN_CONTINUE
    
    KillCount
[attacker]++
    
    if(
KillCount[attacker] == 3) {
        
//if he has killed 3 this round execute a function
        
SomeFunction(attacker)
    }
    
    return 
PLUGIN_CONTINUE
    
}

public 
SomeFunction(id) {
    
//your code here
    
client_print(idprint_chat"This is your third kill this round!")



Doc-Holiday 09-09-2011 17:30

Re: How to check if player has killed somebody
 
Just another way

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>

#define m_LastHitGroup 75
new KillCount[33]

public 
plugin_init()
{
    
RegisterHam(Ham_Killed"player""death");
    
register_logevent("ResetKills",2,"1=Round_Start")
}

public 
client_disconnect(id)
    
KillCount[id] = 0

    
public ResetKills()
{
    new 
players[32] , inum
    get_players
(playersinum)
    for(new 
0inum; ++a)
        
KillCount[a] = 0
}
public 
death(iVictimiInflictoriAttackeriShouldGib)
{
    new 
HitGroup get_pdata_int(iVictimm_LastHitGroup);
    if(
iAttacker != iVictim && cs_get_user_team(iVictim) != cs_get_user_team(iAttacker))
    {
        
KillCount[iAttacker]++
        
        if(
HitGroup == HIT_HEAD)
        {
            
//Was a Headshot
        
}
    
        if(
KillCount[iAttacker] == 3)
        {
            
//if he has killed 3 this round execute a function
            
SomeFunction(iAttacker)
        }
    }
    
    return 
HAM_IGNORED;
}

public 
SomeFunction(id)
{
    
//your code here
    
client_print(idprint_chat"This is your third kill this round!")


you can check head shots also in death message by using read_data(3) and doing a check like this

PHP Code:

new HeadShot read_data(3)

if(
HeadShot)
{
    
//Was a headshot


Also i didnt edit his code just changed it over to ham so i didn't test the way it works.

ConnorMcLeod 09-10-2011 04:12

Re: How to check if player has killed somebody
 
Quote:

Originally Posted by Desikac (Post 1551698)
PHP Code:

#include <amxmodx>
#include <cstrike>

new KillCount[33]

public 
plugin_init() {
    
register_messageget_user_msgid"DeathMsg" ) , "death" )
    
register_logevent("ResetKills",2,"1=Round_Start")
}

public 
client_disconnect(id)
    
KillCount[id] = 0

    
public ResetKills(){
    new 
players[32] , inum
    get_players
(playersinum)
    for(new 
0inum; ++a)
        
KillCount[a] = 0
}
public 
death() {
    new 
attacker read_data(1);
    new 
victim read_data(2);
       
    if(
attacker == victim)
        return 
PLUGIN_CONTINUE
    
    
if(cs_get_user_team(attacker) == cs_get_user_team(victim))
        return 
PLUGIN_CONTINUE
    
    KillCount
[attacker]++
    
    if(
KillCount[attacker] == 3) {
        
//if he has killed 3 this round execute a function
        
SomeFunction(attacker)
    }
    
    return 
PLUGIN_CONTINUE
    
}

public 
SomeFunction(id) {
    
//your code here
    
client_print(idprint_chat"This is your third kill this round!")



Check if attacker is connected.

Coincidence 09-11-2011 11:40

Re: How to check if player has killed somebody
 
can be attacker not connected ?

fysiks 09-11-2011 12:54

Re: How to check if player has killed somebody
 
Quote:

Originally Posted by Coincidence (Post 1553029)
can be attacker not connected ?

Yes.

.Dare Devil. 09-11-2011 16:07

Re: How to check if player has killed somebody
 
Quote:

Originally Posted by fysiks (Post 1553083)
Yes.

How??? :)
After all, this is not possible :):)

ConnorMcLeod 09-11-2011 16:22

Re: How to check if player has killed somebody
 
Because it's how gt_user_attacker is done, it checks inflictor, if inflictor is a player it returns the player index, if it's a nade it returns the owner of that nade, if it's another entity type, it returns the owner of that entity if it is a player, else the entity itself.

http://www.amxmodx.org/funcwiki.php?...cker&go=search

Quote:

As of 1.75, get_user_attacker can return a non-player index if the player was attacked by a non-player entity.

Emp` 09-11-2011 23:24

Re: How to check if player has killed somebody
 
Also it can be worldspawn (0) if for example you die by falling.

Napoleon_be 09-12-2011 16:32

Re: How to check if player has killed somebody
 
at least check if the player is alive then.


All times are GMT -4. The time now is 09:12.

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