AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Double kill with a grenade (https://forums.alliedmods.net/showthread.php?t=164096)

Backstabnoob 08-07-2011 09:17

Double kill with a grenade
 
Hello.

I'd like to know how to detect when two players are killed by 1 grenade.
I'm not sure if deathmsg defines the killer properly when it's done by grenade, so:
1. Is the killer in DeathMsg index of player who actually killed someone with grenade? If so, is the grenade's string "hegren", as it is for all other weapons?
2. How do I detect if it was a double kill?

For the second point, I think the gametime for both the kills should be the same, but I'm not sure.

Hunter-Digital 08-07-2011 09:53

Re: Double kill with a grenade
 
Yes, killer is the player index and it's "hegren"... you could've just tested by debugging deathmsg :)

And yeah, game time + killer check should be ok, but they don't have to match exacly, you can allow at least 1 second for error because a player can't throw grenades faster than 1 second AFAIK.

Backstabnoob 08-07-2011 10:15

Re: Double kill with a grenade
 
In DeathMsg if(equali(weapon, "hegren")) works not.

Edit: The weapon name is actually "grenade"

Hunter-Digital 08-07-2011 10:37

Re: Double kill with a grenade
 
See, it took you 5 minutes to test it out (the additional minute to edit your post :P)

Bugsy 08-07-2011 12:24

Re: Double kill with a grenade
 
There may be a better way but this works. It will notify via client_print if more than 1 kill is made with the same grenade.
PHP Code:

#include <amxmodx>
#include <engine>
#include <hamsandwich>
#include <fakemeta>
#include <celltrie>

new const Version[] = "0.1";

new 
Trie:g_Trie;

public 
plugin_init() 
{
    
register_plugin"Multi Grenade Kill" Version "bugsy" );
    
    
RegisterHamHam_TakeDamage "player" "fw_HamTakeDamage" );
    
register_think"grenade" "fw_GrenadeThink" );

    
g_Trie TrieCreate();
}

public 
plugin_end()
{
    
TrieDestroyg_Trie );
}

public 
fw_GrenadeThinkiEntity 
{
    
//This gets called 3 times when the condition ( get_gametime() > entity_get_float( iEntity, EV_FL_dmgtime ) is checked.
    //The third and last time always occurred at approx 0.650005 in my tests.
    
if( !is_valid_entiEntity ) || ( ( get_gametime() - entity_get_floatiEntityEV_FL_dmgtime ) ) < 0.64 ) )
        return;
    
    new 
szKey];
    
num_to_striEntity szKey charsmaxszKey ) );
    
    if ( 
TrieKeyExistsg_Trie szKey ) )
    {
        new 
iKills;
        
TrieGetCellg_Trie szKey iKills );
        
        if ( 
iKills )
        {
            new 
szOwner] , iKiller szName33 ]
            
formatexszOwner charsmaxszOwner ) , "%s%s" szKey "OWNER" );
            
TrieGetCellg_Trie szOwner iKiller );
            
            
get_user_nameiKiller szName charsmaxszName ) );
            
client_printprint_chat "* %s's grenade killed %d players!" szName iKills );
            
            
TrieDeleteKeyg_Trie szOwner );
        }
        
        
TrieDeleteKeyg_Trie szKey );
    }
}

public 
fw_HamTakeDamageiVictim iInflictor iAttacker Float:fDamage iDamageBits )
{
    if ( 
iInflictor && ( iInflictor != iAttacker ) && !is_user_aliveiVictim ) && ( fm_cs_get_grenade_typeiInflictor ) == CSW_HEGRENADE ) )
    {
        new 
szKey] , szOwner] , iKillCount;
        
num_to_striInflictor szKey charsmaxszKey ) );
        
formatexszOwner charsmaxszOwner ) , "%sOWNER" szKey );
        
TrieGetCellg_Trie szKey iKillCount );
        
TrieSetCellg_Trie szKey , ++iKillCount );
        
TrieSetCellg_Trie szOwner iAttacker );
    }
}

fm_cs_get_grenade_typeindex 
{
    if (!
pev_valid(index))
        return 
0
    
    
new classname[9]
    
pev(indexpev_classnameclassname8)
    if (!
equal(classname"grenade"))
        return 
0
    
    
if (get_pdata_int(index96) & (1<<8))
        return 
CSW_C4
    
    
new bits get_pdata_int(index114)
    if (
bits & (1<<0))
        return 
CSW_HEGRENADE
    
else if (bits & (1<<1))
        return 
CSW_SMOKEGRENADE
    
else if (!bits)
        return 
CSW_FLASHBANG
    
    
return 0



Exolent[jNr] 08-07-2011 16:54

Re: Double kill with a grenade
 
I prefer this method:
Code:
#include <amxmodx> #include <csx> #include <hamsandwich> new g_grenadeKills[33] public plugin_init() {     RegisterHam(Ham_Think, "grenade", "FwdGrenadeThink") } public FwdGrenadeThink(ent) {     if(!pev(ent, pev_bInDuck)) {         new Float:dmgtime         pev(ent, pev_dmgtime, dmgtime)                 if(dmgtime <= get_gametime()) {             g_grenadeKills[pev(ent, pev_owner)] = 0             set_pev(ent, pev_bInDuck, 1)         }     } } public client_death(victim, killer, weapon, hitPlace, teamKill) {     if(weapon == CSW_HEGRENADE && ++g_grenadeKills[killer] > 1) {         // more than 1 kill for nade     } }

The only difference with my method is that you can't properly check for more than 1 kill number without using tasks and more stuff.
But with bugsy's code, it's easy to check for more than 1 kill number.
(By more than 1 kill number, I mean checking for 2 or 3 kills)

SpeeDeeR 08-07-2011 17:20

Re: Double kill with a grenade
 
Is it the same with other weapons?

Exolent[jNr] 08-07-2011 17:36

Re: Double kill with a grenade
 
Quote:

Originally Posted by SpeeDeeR (Post 1527846)
Is it the same with other weapons?

No, that's for grenades only.

SpeeDeeR 08-07-2011 17:50

Re: Double kill with a grenade
 
Could you show me how can it be made with the other weapons.

r14170 08-07-2011 18:12

Re: Double kill with a grenade
 
deleted.


All times are GMT -4. The time now is 03:25.

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