Raised This Month: $ Target: $400
 0% 

detect self kill ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Neon123
Senior Member
Join Date: Jan 2016
Old 05-27-2019 , 20:24   detect self kill ?
Reply With Quote #1

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

Last edited by Neon123; 05-27-2019 at 20:48.
Neon123 is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 05-27-2019 , 21:36   Re: detect self kill ?
Reply With Quote #2

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;


Last edited by redivcram; 05-28-2019 at 11:10.
redivcram is offline
Neon123
Senior Member
Join Date: Jan 2016
Old 05-27-2019 , 22:42   Re: detect self kill ?
Reply With Quote #3

thanks
Neon123 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-27-2019 , 22:48   Re: detect self kill ?
Reply With Quote #4

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

Last edited by Bugsy; 05-27-2019 at 22:48.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-28-2019 , 07:44   Re: detect self kill ?
Reply With Quote #5

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.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-28-2019 , 10:51   Re: detect self kill ?
Reply With Quote #6

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
__________________

Last edited by <VeCo>; 05-28-2019 at 10:52.
<VeCo> is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 05-28-2019 , 11:11   Re: detect self kill ?
Reply With Quote #7

Fixed my code. +1 for all.
redivcram 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 09:39.


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