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

CS:GO Stat tracking plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
toxicandy
Junior Member
Join Date: Mar 2016
Old 02-12-2019 , 14:06   CS:GO Stat tracking plugin
Reply With Quote #1

I am working on writing in some new functionality for a stat tracking plugin for one of our 10 man servers. Currently, we can track the basics like kills, deaths, score, assists, steamid and so on.

I am working on adding in a couple stats:

RWS/Rating (we have a mathematical formula we are following) but this requires us to calculate stuff like 2k, 3k, 4k, 5k in a round. Is the best way to do this to run: m_iNumRoundKills every round end and update columns for players in the match based on the number of kills they had for that round?

Also if we wanted to track clutch kills how would I go about that? I can't find any good property for doing that. How do I determine when it is a clutch situation code wise. I know that if Team A Player Count > Team B Player count AND Team B Player Count = 1 then it is a clutch situation for team B. How do I do that in the code though because I would have to mid round know that there is a clutch situation, after the round I wouldn't be able to tell because the round would be Team A alive = 0, Team B alive = 1 and I wouldn't know how many Team A were killed.

I am fairly new to sourcepawn and all the properties are very confusing as they are not well documented in any 1 spot I can find and half the time if I implement one it doesn't work and I have to use trial and error to find working properties.

I am working off an existing plugin and just adding bits to it here and there, so far all that I have tried has worked but now that I am getting into more round specific stats it is getting more difficult. I assume for round end stats like rws I would use a listener for round end and update after that.

Thanks for helping me.

Last edited by toxicandy; 02-12-2019 at 14:07.
toxicandy is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 02-12-2019 , 14:21   Re: CS:GO Stat tracking plugin
Reply With Quote #2

PHP Code:

#include <sourcemod> 
#include <sdktools> 
#include <sdkhooks> 

int g_RoundKills[MAXPLAYERS 1];
int g_Aces[MAXPLAYERS 1];
int g_ClutchKills[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
HookEvent("player_death"PlayerDeath);
    
HookEvent("round_start"RoundStart);
    
HookEvent("round_end"RoundEnd);
}

public 
void OnClientConnected(int client)
{
    
g_RoundKills[client] = 0;
    
g_Aces[client] = 0;
    
g_ClutchKills[client] = 0;
}

public 
void PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    
    if (
attacker && client && attacker != client)
    {
        
g_RoundKills[attacker]++;
        
        if (
IsInClutchSituation(attacker))
        {
            
g_ClutchKills[attacker]++;
        }
    }
}

bool IsInClutchSituation(int client)
{
    
int clientTeam GetClientTeam(client);
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            if (
!= client && GetClientTeam(i) == clientTeam)
            {
                if (
IsPlayerAlive(i))
                {
                    return 
false// we found another player alive in client's team
                
}
            }
        }
    }
    
    return 
true// if he's alone in his team or he's the last player alive in his team - clutch situation. You can improve this code.
}

public 
void RoundStart(Event event, const char[] namebool dontBroadcast)
{
    for (
int i 1<= MaxClientsi++)
    {
        
g_RoundKills[i] = 0// when a new round starts, we reset the array
    
}
}

public 
void RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientConnected(i))
        {
            switch (
g_RoundKills[i])
            {
                case 
2// 2k
                
case 3// 3k
                
case 4// 4k
                
case 5g_Aces[i]++; //ace
            
}
        }
    }

__________________
Ilusion9 is offline
toxicandy
Junior Member
Join Date: Mar 2016
Old 02-12-2019 , 22:53   Re: CS:GO Stat tracking plugin
Reply With Quote #3

So based on that can I add to the
Code:
RoundEnd
code and add RWS after the switch? That would work correct? Also just for my own clarification what is the difference between the i_ and g_ properties? I am very new to writing even snippets of plugins, I have a big list of properties but I have never seen g_XYZ. Just asking for my own understanding.
toxicandy is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 02-13-2019 , 02:05   Re: CS:GO Stat tracking plugin
Reply With Quote #4

It's just a naming convention. Calling a variable g_Blah usually means that it's global scope.
CliptonHeist is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-13-2019 , 02:18   Re: CS:GO Stat tracking plugin
Reply With Quote #5

Quote:
Originally Posted by toxicandy View Post
So based on that can I add to the
Code:
RoundEnd
code and add RWS after the switch? That would work correct? Also just for my own clarification what is the difference between the i_ and g_ properties? I am very new to writing even snippets of plugins, I have a big list of properties but I have never seen g_XYZ. Just asking for my own understanding.
You want to start looking into hooking events. For your case, you want to check for a clutch situation every time there's a death, similar to what Ilusion9 did. For more info to get you going on sourcepawn, look at:
https://wiki.alliedmods.net/Introduction_to_SourcePawn
https://wiki.alliedmods.net/Category...eMod_Scripting

The latter has a section on events. Events vary by game, mode, and more. Here's some lists of events:
https://wiki.alliedmods.net/Game_Events_(Source)
https://wiki.alliedmods.net/Generic_..._Server_Events

A few notes regarding Ilusion9's code, which he graciously provided you:
  • IsInClutchSituation will need to verify the round hasnt ended already (during the time between round end and start of next round). They didn't clutch if the kills are after round end and/or they lost the round.
  • Additionally, IsInClutchSituation will need to verify there are players alive on the other team. While checking that, you might as well count them to verify if 5v1, 4v1, etc.
  • Since you are already hooking the player death event, you should manually count the deaths by incrementing client variables in the hook. The other methodology would miss kills that happen after the round.

To your later question, all coders have different styles of formatting, naming conventions, etc. It is common to name variables so that they are self-identifying by the label. For variables that are outside of functions (i.e. they are "global" variables), many coders, myself included, start the variable name with "g_". Personally, I always put a lower case letter before the label indicating what type of variable it is, then add g_ for global, a_ for arraylists, ga_ for global arraylists, etc. So, when I see a variable in my code that is ga_iSomeClientVariable, I instantly know that it is a global arraylist of integers that I've named "SomeClientVariable". Styles/conventions can vary significantly across different coders.

Here is some code snippets from one of my plugins in how I addressed clutches:

Code from TOG Scrim plugin


Hope that helps.

Side note: I'm currently separating the stats component from my scrim plugin, then personalizing it for a community's specific wants. PM me if interested in a non-personalized version.
__________________

Last edited by ThatOneGuy; 02-13-2019 at 02:21.
ThatOneGuy is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 02-13-2019 , 05:27   Re: CS:GO Stat tracking plugin
Reply With Quote #6

Quote:
Originally Posted by ThatOneGuy View Post
  • Additionally, IsInClutchSituation will need to verify there are players alive on the other team. While checking that, you might as well count them to verify if 5v1, 4v1, etc.
If there are not enemies alive, then player_death will not be triggered, unless there's a team kill or self kill. This is useless and a waste of time.
__________________
Ilusion9 is offline
toxicandy
Junior Member
Join Date: Mar 2016
Old 02-13-2019 , 12:40   Re: CS:GO Stat tracking plugin
Reply With Quote #7

Would death events trigger in warm up or does all this assume the match has begun?
toxicandy is offline
Reply


Thread Tools
Display Modes

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 02:46.


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