Raised This Month: $12 Target: $400
 3% 

Detect c4 carrier


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sanjay Singh
Veteran Member
Join Date: Sep 2016
Old 12-05-2019 , 10:51   Detect c4 carrier
Reply With Quote #1

how can I detect if I killed a c4 carrier enemy or not?

I want to print chat message if I killed a c4 carrier

PHP Code:
client_print(id0"You just killed a c4 carrier guy (%s)"carrier name
__________________
Sanjay Singh is offline
Send a message via AIM to Sanjay Singh
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-05-2019 , 11:27   Re: Detect c4 carrier
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Notify about C4 victim"
#define VERSION "1.0"
#define AUTHOR "redivcram"

public plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
RegisterHam(Ham_Killed"player""HamPlayerKilled"1);
}

public 
HamPlayerKilled(iVictimiAttacker)
{
    if((
iVictim != iAttacker) && user_has_weapon(iVictimCSW_C4)) {
        
        new 
szCarrierName[32];
        
get_user_name(iVictimszCarrierNamecharsmax(szCarrierName));
        
        
client_print(iAttacker0"You just killed a c4 carrier guy (%s)"szCarrierName);
    }


Last edited by redivcram; 12-05-2019 at 12:22.
redivcram is offline
Sanjay Singh
Veteran Member
Join Date: Sep 2016
Old 12-05-2019 , 11:32   Re: Detect c4 carrier
Reply With Quote #3

But will it work? becuz it will be called only after player killed?
Quote:
Originally Posted by redivcram View Post
PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Notify about C4 victim"
#define VERSION "1.0"
#define AUTHOR "redivcram"

public plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
RegisterHam(Ham_Killed"player""HamPlayerKilled"1);
}

public 
HamPlayerKilled(iVictimiAttacker)
{
    if(
user_has_weapon(iVictimCSW_C4)) {
        
        new 
szCarrierName[32];
        
get_user_name(iVictimszCarrierNamecharsmax(szCarrierName));
        
        
client_print(iAttacker0"You just killed a c4 carrier guy (%s)"szCarrierName);
    }

__________________
Sanjay Singh is offline
Send a message via AIM to Sanjay Singh
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-05-2019 , 11:39   Re: Detect c4 carrier
Reply With Quote #4

Quote:
Originally Posted by Sanjay Singh View Post
But will it work? becuz it will be called only after player killed?
Maybe test it out?
redivcram is offline
instinctpt1
Senior Member
Join Date: Dec 2016
Location: Chandigarh, India
Old 12-05-2019 , 12:02   Re: Detect c4 carrier
Reply With Quote #5

@redivcram Maybe with iVictim != iAttacker check too ?
instinctpt1 is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-05-2019 , 12:22   Re: Detect c4 carrier
Reply With Quote #6

Quote:
Originally Posted by instinctpt1 View Post
@redivcram Maybe with iVictim != iAttacker check too ?
You are right! I totally forgot about that, thanks!
Updated my code above.
redivcram is offline
thEsp
BANNED
Join Date: Aug 2017
Old 12-05-2019 , 14:23   Re: Detect c4 carrier
Reply With Quote #7

(just a side note)
You may use "%n" formatting rule in order to get some player's name directly.
https://github.com/alliedmodders/amxmodx/pull/93
thEsp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-05-2019 , 18:59   Re: Detect c4 carrier
Reply With Quote #8

Not thoroughly tested
PHP Code:

#include <amxmodx>
#include <hamsandwich>

new g_iPlayerHasC4;

public 
plugin_init() 
{
    
RegisterHamHam_Killed "player" "HamPlayerKilled" );
    
    
register_logevent"LostBomb" "2=Dropped_The_Bomb" );
    
register_logevent"GotBomb" "2=Got_The_Bomb" );
    
register_event"WeapPickup" "GotBomb2" "be" "1=6" );
}

public 
GotBomb()
{
    
g_iPlayerHasC4 get_loguser_index();
}

public 
GotBomb2id )
{
    
g_iPlayerHasC4 id;
}

public 
LostBomb()
{
    if ( 
is_user_aliveget_loguser_index() ) )
    {
        
g_iPlayerHasC4 0;
    }
}

public 
HamPlayerKillediVictim iAttacker )
{
    if ( 
g_iPlayerHasC4 && ( iVictim == g_iPlayerHasC4 ) )
    {
        new 
szCarrierName[32];
        
get_user_nameiVictim szCarrierName charsmaxszCarrierName ) );
    
        
client_printiAttacker print_chat"You just killed a c4 carrier guy (%s)" szCarrierName );
    }
}

get_loguser_index() 
{
    new 
loguser[80], name[32]
    
read_logargv(0loguser79)
    
parse_loguser(logusername31)
    
    return 
get_user_index(name)

__________________

Last edited by Bugsy; 12-05-2019 at 19:01.
Bugsy is offline
Sanjay Singh
Veteran Member
Join Date: Sep 2016
Old 12-06-2019 , 02:53   Re: Detect c4 carrier
Reply With Quote #9

This code working fine but you also need to add code for spawn c4 func and get his id. else its fine.
Thanks @bugsy

Quote:
Originally Posted by Bugsy View Post
Not thoroughly tested
PHP Code:

#include <amxmodx>
#include <hamsandwich>

new g_iPlayerHasC4;

public 
plugin_init() 
{
    
RegisterHamHam_Killed "player" "HamPlayerKilled" );
    
    
register_logevent"LostBomb" "2=Dropped_The_Bomb" );
    
register_logevent"GotBomb" "2=Got_The_Bomb" );
    
register_event"WeapPickup" "GotBomb2" "be" "1=6" );
}

public 
GotBomb()
{
    
g_iPlayerHasC4 get_loguser_index();
}

public 
GotBomb2id )
{
    
g_iPlayerHasC4 id;
}

public 
LostBomb()
{
    if ( 
is_user_aliveget_loguser_index() ) )
    {
        
g_iPlayerHasC4 0;
    }
}

public 
HamPlayerKillediVictim iAttacker )
{
    if ( 
g_iPlayerHasC4 && ( iVictim == g_iPlayerHasC4 ) )
    {
        new 
szCarrierName[32];
        
get_user_nameiVictim szCarrierName charsmaxszCarrierName ) );
    
        
client_printiAttacker print_chat"You just killed a c4 carrier guy (%s)" szCarrierName );
    }
}

get_loguser_index() 
{
    new 
loguser[80], name[32]
    
read_logargv(0loguser79)
    
parse_loguser(logusername31)
    
    return 
get_user_index(name)

__________________
Sanjay Singh is offline
Send a message via AIM to Sanjay Singh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-06-2019 , 06:21   Re: Detect c4 carrier
Reply With Quote #10

This should hook when a player is spawned with c4.
__________________
Bugsy is offline
Reply


Thread Tools
Display Modes

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 14:50.


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