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

Detect double kill


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 05-29-2011 , 11:32   Detect double kill
Reply With Quote #1

What is the best and most efficient way to detect double kill (a.k.a. 2 kills with 1 bullet)
reinert is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-29-2011 , 11:47   Re: Detect double kill
Reply With Quote #2

Check timing between 2 kills? If 0 or < 1.0 (or some small value) then double kill. get_gametime() returns float value. You can also check if one weapon fire resulted in multiple kills. Im sure there are plenty of ways.

Untested
PHP Code:
new Float:g_fLastKill33 ];

//When kill is made
g_fLastKillid ] = get_gametime();

//do this check first before the above line
if ( ( get_gametime() - g_fLastKillid ] ) < 0.25 )
     
//double kill? 
__________________
Bugsy is offline
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 05-29-2011 , 11:49   Re: Detect double kill
Reply With Quote #3

I used something like this a while ago

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

#define FUNKYTHING 871

new giKills[33];

public 
plugin_init()
{
    
RegisterHam(Ham_Killed"player""fwdPlayerDeath"0);
}

public 
fwdPlayerDeath(iVictimiKiller)
{
    if(
giKills[iKiller]++ == 2)
    {
         
giKills[iKiller] = 0;
         
         
//Your code here
         
         
return;
    }
    
    
set_task(0.1"funcResetCount"iKiller FUNKYTHING);
}

public 
funcResetCount(id)
{
    
giKills[id FUNKYTHING] = 0;

__________________
minimiller is offline
Send a message via MSN to minimiller
reinert
Veteran Member
Join Date: Feb 2007
Old 05-29-2011 , 12:08   Re: Detect double kill
Reply With Quote #4

Do I've to use return in giKills checking ?
If yes why ?

Also, can I check it in

this event:

PHP Code:
register_message(get_user_msgid("DeathMsg"), "Event_DeathMsg"
reinert is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-29-2011 , 12:23   Re: Detect double kill
Reply With Quote #5

You could use Bugsy's method to detect serval quick kills, not only double kill by adding a task with 0.26 and removing it at the same time, that way if the player keeps killing people, it won't show "double kill", "multi kill", etc, it will just show the final result if he stopped.
__________________
Hunter-Digital is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-29-2011 , 12:29   Re: Detect double kill
Reply With Quote #6

I think it should be if ( ++giKills[ iKiller ] == 2 ).

You don't have to return a value but if you want to use HAM_IGNORED. You can use DeathMsg instead. Just use register_event( "DeathMsg" , ...
__________________
Bugsy is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-29-2011 , 12:39   Re: Detect double kill
Reply With Quote #7

PHP Code:
register_event("DeathMsg","Event_DeathMsg","a"
Like this ?

Well I'm using none of the returns only the return PLUGIN_HANDLED; on the end of the public function, and in the beggining where I check if(!is_user_connected(killer))

Last edited by reinert; 05-29-2011 at 12:42.
reinert is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-29-2011 , 12:43   Re: Detect double kill
Reply With Quote #8

Add "1>0" condition
__________________
Bugsy is offline
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 05-29-2011 , 13:15   Re: Detect double kill
Reply With Quote #9

i only returned it to stop the set_task doing whats already done

and i think giKills[iKiller]++ and ++giKills[iKiller] will both work
__________________
minimiller is offline
Send a message via MSN to minimiller
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-29-2011 , 13:23   Re: Detect double kill
Reply With Quote #10

You will get different results with each:

Var++ returns the value prior to incrementing, so the first time it'll be 0, second time 1.

++Var returns the value post-increment, first would be 1, second 2
__________________

Last edited by Bugsy; 05-29-2011 at 13:46.
Bugsy 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 10:00.


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