AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect c4 carrier (https://forums.alliedmods.net/showthread.php?t=320123)

Sanjay Singh 12-05-2019 10:51

Detect c4 carrier
 
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


redivcram 12-05-2019 11:27

Re: Detect c4 carrier
 
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);
    }



Sanjay Singh 12-05-2019 11:32

Re: Detect c4 carrier
 
But will it work? becuz it will be called only after player killed?
Quote:

Originally Posted by redivcram (Post 2675798)
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);
    }




redivcram 12-05-2019 11:39

Re: Detect c4 carrier
 
Quote:

Originally Posted by Sanjay Singh (Post 2675799)
But will it work? becuz it will be called only after player killed?

Maybe test it out?

instinctpt1 12-05-2019 12:02

Re: Detect c4 carrier
 
@redivcram Maybe with iVictim != iAttacker check too ?

redivcram 12-05-2019 12:22

Re: Detect c4 carrier
 
Quote:

Originally Posted by instinctpt1 (Post 2675804)
@redivcram Maybe with iVictim != iAttacker check too ?

You are right! I totally forgot about that, thanks!
Updated my code above.

thEsp 12-05-2019 14:23

Re: Detect c4 carrier
 
(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

Bugsy 12-05-2019 18:59

Re: Detect c4 carrier
 
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 12-06-2019 02:53

Re: Detect c4 carrier
 
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 (Post 2675835)
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)




Bugsy 12-06-2019 06:21

Re: Detect c4 carrier
 
This should hook when a player is spawned with c4.


All times are GMT -4. The time now is 22:56.

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