AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   detect self kill ? (https://forums.alliedmods.net/showthread.php?t=316533)

Neon123 05-27-2019 20:24

detect self kill ?
 
hi, i need to detect a self kill, in console "player killed self with x", how i can ?

example player killed self with x worlspawn , or player killed self with grenade

i need to detect the self-killed playerid

redivcram 05-27-2019 21:36

Re: detect self kill ?
 
PHP Code:

#include <amxmodx>
#include <hamsandwich>

public plugin_init() {
    
    
RegisterHam(Ham_Killed"player""hamPlayerKilled"1);
}

public 
hamPlayerKilled(victimattacker) {
    
    if(
is_user_connected(victim)) {

        if(
victim == attacker || attacker == 0) {
        
            new 
name[32];
            
get_user_name(victimnamecharsmax(name));
        
            
client_print(0print_chat"Player %s killed themselves..."name);
        }
    }

    return 
HAM_IGNORED;



Neon123 05-27-2019 22:42

Re: detect self kill ?
 
thanks

Bugsy 05-27-2019 22:48

Re: detect self kill ?
 
Just something to keep in mind.. If you plan to call any natives on the killer, include an is_user_connected() check because he could be disconnected when the kill happens (e.g. tossing a grenade and disconnect).

OciXCrom 05-28-2019 07:44

Re: detect self kill ?
 
redivcram's code will only detect suicide if the victim is the same as the attacker, so this will work when you kill yourself with a grenade, but won't detect falling to your death, etc.

You need to also check the weapon name and see if it's "worldspawn", "trigger_hurt", "door", "door_rotating", etc.

<VeCo> 05-28-2019 10:51

Re: detect self kill ?
 
worldspawn is entity index 0, so check if killer is 0

for other entities (if you need them), check if killer is greater than maxplayers

redivcram 05-28-2019 11:11

Re: detect self kill ?
 
Fixed my code. +1 for all.


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

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