Raised This Month: $32 Target: $400
 8% 

Counting 2 players' actions consecutively


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nanochip
Senior Member
Join Date: Jan 2014
Old 08-23-2017 , 23:37   Counting 2 players' actions consecutively
Reply With Quote #1

I need to figure out how to detect when 2 players kill each other consecutively 5 or more times.

for example:
Bob kills Joe - counter: 1 // starting a counter between Bob and Joe
Joe kills Bob - counter: 2
Bob kills Joe - counter: 3
Joe kills Bob - counter: 4
Bob kills Joe - counter: 5 // counter reached to 5... Bob and Joe are now enemies...

but if Bob kills Joe twice consecutively then the counter resets. so:
Joe kills Bob - counter: 1
Bob Kills Joe - counter: 2
Bob Kills Joe - counter: 0
(or if Joe kills Bob twice consecutively, the counter would reset).

also, if Bob kills someone else after having a consecutive fight with Joe, then reset the counter:
Joe kills Bob - counter: 1
Bob kills Joe - counter: 2
Joe kills Bob - counter: 3
Bob kills Adam - counter: 0
(or if Joe kills some else after having a consecutive fight with Bob)

Basically, I need to figure out how to detect consecutive kills back and forth between someone by using the player_death event under the following circumstances above. I feel like this is super simple, but it's getting passed me and I'm way overthinking it! Rubber duck isn't helping me for once
__________________

Last edited by Nanochip; 08-23-2017 at 23:43.
Nanochip is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-24-2017 , 01:53   Re: Counting 2 players' actions consecutively
Reply With Quote #2

Here's an idea. Untested but you should get the gist

PHP Code:
ArrayList playerkills[MAXPLAYERS 1] = {null, ...};

public 
void OnPluginStart()
{
    
HookEvent("player_death"Event_PlayerDeath);
}

public 
void OnMapStart()
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsValidClient(i))
        {
            if (
playerkills[i] != null)
            {
                
playerkills[i].Clear();
            }
        }
    }
}
public 
void OnClientConnected(int client)
{
    
playerkills[client] = new ArrayList(32);
}

public 
void OnClientDisconnect(int client)
{
    
delete playerkills[client];
}

public 
Action Event_PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    
    if (!
IsValidClient(client) || !IsValidClient(attacker)) // we need both to be valid.
    
{
        return 
Plugin_Continue;
    }
    
    
char steamid[32];
    
GetClientAuthId(attackerAuthId_Steam2steamidsizeof(steamid));
    
playerkills[client].PushString(steamid);
    
    if (
AreLastIndiciesEqual(playerkills[client], 5))
    {
        
// do something
    
}
    return 
Plugin_Continue;
}

// Description: determines if the last X ammount of entries are the same
bool AreLastIndiciesEqual(ArrayList list, int amount)
{
    if (list.
Length == 0// no kills yet
    
{
        return 
false;
    }
    if (list.
Length amount// impossible for it to be true
    
{
        return 
false;
    }
    
    
int startIndex = list.Length amount// string to compare the other four against
    
    
int i startIndex 1// first comparison index
    
    
char string1[32], string2[32]; // temp buffers for GetString
    
    
bool same true// assume their the same, and let the loop prove they're not
    
while (< list.Length && same)
    {
        list.
GetString(startIndexstring1sizeof(string1));
        list.
GetString(istring2sizeof(string2));
        
        if (!
StrEqual(string1string2))
        {
            
same false;
        }
        else
        {
            
i++;
        }
    }
    
    return 
same;
}

bool IsValidClient(int clientbool bAllowBots falsebool bAllowDead true)
{
    if(!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
    {
        return 
false;
    }
    return 
true;

headline is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-25-2017 , 14:01   Re: Counting 2 players' actions consecutively
Reply With Quote #3

My example... free to try
*edit
I haven't tested

*edit
hmmm, last part of your explanation would not work in this code.
Example, it's 3rd turn -> Joe kills Bob -> Joe kills random guy -> Bob kills Joe, counter will continue normally

*edit
maybe not work at all when more players are killing each others
would not work :(
__________________
Do not Private Message @me

Last edited by Bacardi; 08-25-2017 at 14:25.
Bacardi 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 19:39.


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