AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved How to achieve cumulative effect on death pool? (https://forums.alliedmods.net/showthread.php?t=340669)

damage220 12-02-2022 12:33

How to achieve cumulative effect on death pool?
 
1 Attachment(s)
Hi, guys. I cannot figure out how to summarize all kills made with, say, he grenade or awp. I want to allow players to set money showing their kills and the problem here is not to update money, since I have all the necessary messages, but a fact that game engine processes death messages one by one and so when someone kills multiple enemies at once, the hud always shows +1 kill, though the total number of kills is correct. I want it to be cumulative, how to make it show +2, ..., +5 kills? I did some message logging, and here is what I got:
PHP Code:

[36.621555ham_killed_pre
[36.621555DeathMsg (83)
[
36.621555death_event
[36.621555Health (70)
[
36.621555ham_killed_post
[36.621555ham_killed_pre
[36.621555DeathMsg (83)
[
36.621555death_event
[36.621555Health (70)
[
36.621555ham_killed_post
[36.621555ham_killed_pre
[36.621555DeathMsg (83)
[
36.621555death_event
[36.621555Health (70)
[
36.621555ham_killed_post
[36.621555ham_killed_pre
[36.621555DeathMsg (83)
[
36.621555death_event
[36.621555Health (70)
[
36.621555ham_killed_post
killed phillip_style with grenade
killed -=Sh0rTy=- with grenade
killed bussemann with grenade
killed The Muffin Man with grenade
[36.630783Health (70)
[
36.630783Damage (71)
client_death36.630783
[36.630783Health (70)
[
36.630783Damage (71)
client_death36.630783
[36.634681Health (70)
[
36.661983Health (70)
[
36.661983Damage (71)
client_death36.661983
[36.661983Health (70)
[
36.661983Damage (71)
client_death36.661983
[36.794578death_msg_timer
[36.794578death_msg_timer
[36.794578death_msg_timer
[36.794578death_msg_timer 

You can see that most vital DeathMsg messages are all at one frame with gametime: 36.621555. The problem here is that I do not know where the last kill is. So I need something that is called after all these messages and to be sure it is called all the time.
1. I wish I could rely on client_death, but this forward is not triggered on suicide (team change) or amxmodx user_slap( function.
2. I tried to use set_task_ex(0.01, "death_msg_timer") to set a timer, but for some reason it takes too much time to execute the code (173 ms)
3. Damage message appears to be triggered after all DeathMsg messages, but again it is not triggered on team change, etc...
I completely lost at this point. Is the timer single possible solution to this problem? Except client_preThink which I do not want to consider actually.

Is it possible to somehow catch these console messages?
PHP Code:

killed phillip_style with grenade
killed -=Sh0rTy=- with grenade
killed bussemann with grenade
killed The Muffin Man with grenade 

They have perfect timing)

Ps: for those who have no idea what I am talking about, please see attachments (notice +1 above 4).

damage220 12-02-2022 13:40

Re: How to achieve cumulative effect on death pool?
 
I am sorry, I spent many hours with no success to achieve this goal and only after creating this thread I have found out that there is a function RequestFrame. I hope this will help someone in the future.

Natsheh 12-02-2022 15:12

Re: How to achieve cumulative effect on death pool?
 
You can create a player global variable and store in it the current gametime when the player dies/killed, and update the players kills after one or two seconds passed from the last kill.

PHP Code:

new Float:g_fLastKillTime[33], g_UserComboFrags[33];

// HOOKED via ham sandwich module.
public fwPlayerKilledPost( const vId, const kId, const bool:shouldgib )
{
   if(!
is_user_connected(kId)) return;
   
g_fLastKillTime[kId] = get_gametime();
   
g_UserComboFrags[kId] ++;

   
set_task(1.25"UpdatePlayer"kId);
}

public 
UpdatePlayer(id)
{
   if( ( 
get_gametime() - g_fLastKillTime[id] ) >= 1.0 )
   {
       
// do your stuff...
   
}



damage220 12-02-2022 15:45

Re: How to achieve cumulative effect on death pool?
 
Quote:

Originally Posted by Natsheh (Post 2794206)
You can create a player global variable and store in it the current gametime when the player dies/killed, and update the players kills after one or two seconds passed from the last kill.

PHP Code:

new Float:g_fLastKillTime[33], g_UserComboFrags[33];

// HOOKED via ham sandwich module.
public fwPlayerKilledPost( const vId, const kId, const bool:shouldgib )
{
   if(!
is_user_connected(kId)) return;
   
g_fLastKillTime[kId] = get_gametime();
   
g_UserComboFrags[kId] ++;

   
set_task(1.25"UpdatePlayer"kId);
}

public 
UpdatePlayer(id)
{
   if( ( 
get_gametime() - g_fLastKillTime[id] ) >= 1.0 )
   {
       
// do your stuff...
   
}



I could but I do not like delayed response. I am pretty happy with the solution I posted above.

kww 12-03-2022 05:12

Re: How to achieve cumulative effect on death pool?
 
very poor implementation for just hooking grenade multikill
Quote:

zettai ryouiki (RADIO): Fire in the hole!
zettai ryouiki killed Albert with grenade
zettai ryouiki killed Norm with grenade
zettai ryouiki killed Henry with grenade
zettai ryouiki killed Niles with grenade
zettai ryouiki killed Ernie with grenade
zettai ryouiki killed Jason with grenade
zettai ryouiki killed Ulric with grenade
# Entity 121 is thinking! Beware!
# zettai ryouiki made 7 kills in this tick!
PHP Code:

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

new g_iEntity;
new 
g_kills[MAX_PLAYERS+1];

public 
plugin_init()
{
    
register_plugin("ggf","d","a");
    
g_iEntity create_entity("info_target");
    
console_print(0"created entity %i"g_iEntity);

    
register_event("DeathMsg""Event_DeathMsg""a")
    
RegisterHam(Ham_Think"info_target""Ham_info_target_Think");
}

public 
Event_DeathMsg()
{
    static 
attackerattacker read_data(1);

    if(!
is_user_connected(attacker))
        return;
    
    
g_kills[attacker]++;
    
set_pev(g_iEntitypev_nextthinkget_gametime() + 0.05); // if you do grenade multikill, all kills will happen at the same tick
}

public 
Ham_info_target_Think(iEnt)
{
    
console_print(0"^t# Entity %i is thinking! Beware!"iEnt);

    if(
iEnt != g_iEntity)
        return;
    
    new 
players[MAX_PLAYERS], playerCount;
    
get_players_ex(playersplayerCountGetPlayers_ExcludeDead GetPlayers_ExcludeHLTV);

    static 
id;

    for(new 
iplayerCounti++)
    {
        
id players[i];
        if(
g_kills[id])
        {
            
// do whatever you want with kills value
            
console_print(0"^t# %n made %i kills in this tick!"idg_kills[id])

            
// but reset it after your operations
            
g_kills[id] = 0;
        }
    }



damage220 12-04-2022 14:27

Re: How to achieve cumulative effect on death pool?
 
Quote:

Originally Posted by kww (Post 2794256)
very poor implementation for just hooking grenade multikill

PHP Code:

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

new g_iEntity;
new 
g_kills[MAX_PLAYERS+1];

public 
plugin_init()
{
    
register_plugin("ggf","d","a");
    
g_iEntity create_entity("info_target");
    
console_print(0"created entity %i"g_iEntity);

    
register_event("DeathMsg""Event_DeathMsg""a")
    
RegisterHam(Ham_Think"info_target""Ham_info_target_Think");
}

public 
Event_DeathMsg()
{
    static 
attackerattacker read_data(1);

    if(!
is_user_connected(attacker))
        return;
    
    
g_kills[attacker]++;
    
set_pev(g_iEntitypev_nextthinkget_gametime() + 0.05); // if you do grenade multikill, all kills will happen at the same tick
}

public 
Ham_info_target_Think(iEnt)
{
    
console_print(0"^t# Entity %i is thinking! Beware!"iEnt);

    if(
iEnt != g_iEntity)
        return;
    
    new 
players[MAX_PLAYERS], playerCount;
    
get_players_ex(playersplayerCountGetPlayers_ExcludeDead GetPlayers_ExcludeHLTV);

    static 
id;

    for(new 
iplayerCounti++)
    {
        
id players[i];
        if(
g_kills[id])
        {
            
// do whatever you want with kills value
            
console_print(0"^t# %n made %i kills in this tick!"idg_kills[id])

            
// but reset it after your operations
            
g_kills[id] = 0;
        }
    }



Thanks, kww. I did it in similar way except that I prefer RequestFrame much more and I take into account other kills like c4 explosion or gun shot.

kww 12-05-2022 08:14

Re: How to achieve cumulative effect on death pool?
 
Quote:

Originally Posted by damage220 (Post 2794403)
Thanks, kww. I did it in similar way except that I prefer RequestFrame much more and I take into account other kills like c4 explosion or gun shot.

This was a good experience on making thinking entities for me


All times are GMT -4. The time now is 15:38.

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