Raised This Month: $ Target: $400
 0% 

[CS:GO] Need a simple point tracking system!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
A_RM
AlliedModders Donor
Join Date: Oct 2016
Location: Canada
Old 10-22-2016 , 21:55   [CS:GO] Need a simple point tracking system!
Reply With Quote #1

Hey everyone!

**edited version:

What I'm looking to do is have a point tracking system that:
-gives out points based on time played (per minute, say 2 points base rate)
-can give out extra points per minute based on two separate things,
  • if they have a phrase in their Steam name (ex. + 1 more points per minute)
  • if they are in my Steam group and using my clan tag (ex. + 1 more points per minute)

MySQL is necessary as I'd like to have access to user point stats on my website so users can redeem them.

I want to be able to access the amount of points the user has locally so I can use an sm_hsay plugin to show the user how many points they have. No chat commands are necessary.

Backstory for a better understanding:
I'm working on a little project for some friends who are partnered Twitch streamers. My goal is to have an idle server where viewers can idle overnight/while they are at school etc. MOTD ads will be run to bring in revenue. The user can then go to my website and redeem their points for a PayPal cashout so they can afford to subscribe or donate to the streamer. This is aimed at younger kids who don't have jobs. I don't plan to really make a profit off this. Just pay off the server cost then give the rest back to the viewers of my friends.

Last edited by A_RM; 10-23-2016 at 14:32. Reason: added clarity
A_RM is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 10-23-2016 , 05:42   Re: [CS:GO] Looking for a simple point tracking system!
Reply With Quote #2

I made this little script for ya. Not tested through.

Also, you want to edit the line 10 and maybe 8. The database schema should be like this :
Code:
+------ PLAYER_TIME ------+
+                         +
+  steamid (primary key)  +
+        stime (int)      +
+-------------------------+
Time stored in secondes. I'm sure you would be able to do the point systen by yourself now, or you still need help ?
PHP Code:
#include <SteamWorks>
#include <sourcemod>
#include <sdktools>
#undef REQUIRE_EXTENSIONS
#include <cstrike>

//Plugin infos
#define PLUGIN_AUTHOR             "Arkarr"
#define PLUGIN_VERSION             "1.00"
//CONFIG var
#define    DB_SAVE_INTERVAL        30
#define CLANTAG                    "MY CLAN TAG"
#define STEAM_NAME_PHRASE        "STEAM NAME PHRASE"
#define GROUP_ID                0000000
//Database queries
#define    DB_CONFIGURATION_NAME    "mydatabaseCONFIG"
#define QUERY_INIT_DATABASE        "CREATE TABLE IF NOT EXISTS `player_time` (`steamid` varchar(45) NOT NULL, `stime` int NOT NULL, PRIMARY KEY (`steamid`))"
#define QUERY_LOAD_CLIENT_TIME    "SELECT `stime` FROM player_time WHERE `steamid`=\"%s\""
#define QUERY_UPDATE_ENTRY        "UPDATE `player_time` SET `stime`=\"%i\" WHERE `steamid`=\"%s\";"
#define QUERY_NEW_ENTRY            "INSERT INTO `player_time` (`steamid`,`stime`) VALUES (\"%s\", %i);"

EngineVersion engineName;

Handle DATABASE_PlayerTime;

bool IsInDatabase[MAXPLAYERS 1];
bool inGroup[MAXPLAYERS 1];

int NbrSeconds[MAXPLAYERS 1];
int Seconds;
int Tick;

public 
Plugin myinfo 
{
    
name "[ANY] Play Time Recorder",
    
author PLUGIN_AUTHOR,
    
description "Record the number of seconds a player spent on the server.",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
CreateTimer(1.0TMR_UpdateClientTime_TIMER_REPEAT);
    
    
engineName GetEngineVersion();
}

public 
void OnConfigsExecuted()
{
    
SQL_TConnect(GotDatabaseDB_CONFIGURATION_NAME);
}

public 
void OnClientPutInServer(int client)
{
    
SteamWorks_GetUserGroupStatus(clientGROUP_ID);
}

public 
void OnClientConnected(int client)
{
    
LoadPlayTime(client);
}

public 
void OnClientDisconnect(int client)
{
    
SaveIntoDatabase(client);
}

public 
int SteamWorks_OnClientGroupStatus(int authidint groupidbool isMemberbool isOfficer)
{
    
int client GetUserFromAuthID(authid);
    if(
isMember)
        
inGroup[client] = true;    
}

public 
int GetUserFromAuthID(int authid)
{
    for(
int i=1i<=MaxClientsi++)
    {
        
char authstring[50];
        
GetClientAuthId(iAuthId_Steam3authstringsizeof(authstring));    
        
        
char authstring2[50];
        
IntToString(authidauthstring2sizeof(authstring2));
        
        if(
StrContains(authstringauthstring2) != -1)
        {
            return 
i;
        }
    }
    
    return -
1;
}

public 
Action TMR_UpdateClientTime(Handle tmr)
{
    
Tick++;
    
Seconds++;
    for(
int client=1client <= MaxClientsclient++)
    {
        if(
IsClientInGame(client))
        {
            if(
Seconds >= 60)
            {
                if(
engineName == Engine_CSGO && inGroup[client])
                {
                    
char clanTag[45];
                    
CS_GetClientClanTag(clientclanTagsizeof(clanTag));
                    if(
StrEqual(clanTagCLANTAG))
                        
NbrSeconds[client]++;
                }
                
                
char clientName[100];
                
GetClientName(clientclientNamesizeof(clientName));
                if(
StrEqual(STEAM_NAME_PHRASEclientName))
                        
NbrSeconds[client]++;                
            }
            
            
NbrSeconds[client]++;
            if(
Tick >= DB_SAVE_INTERVAL && DATABASE_PlayerTime != INVALID_HANDLE)
                
SaveIntoDatabase(client);
        }
    }
    
    if(
Seconds >= 60)
        
Seconds 0;
        
    if(
Tick >= DB_SAVE_INTERVAL)
        
Tick 0;
}

public 
void LoadPlayTime(int client)
{
    
char query[100];
    
char steamid[30];
    
GetClientAuthId(clientAuthId_SteamID64steamidsizeof(steamid));
    
    
Format(querysizeof(query), QUERY_LOAD_CLIENT_TIMEsteamid);
    
SQL_TQuery(DATABASE_PlayerTimeT_GetPlayerInfoqueryclient);
}

public 
GotDatabase(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
hndl == INVALID_HANDLE)
    {
        
SetFailState(error);
        return;
    }
    
    
DATABASE_PlayerTime hndl;
    
    
char buffer[300];
    if (!
SQL_FastQuery(DATABASE_PlayerTimeQUERY_INIT_DATABASE))
    {
        
SQL_GetError(DATABASE_PlayerTimebuffersizeof(buffer));
        
SetFailState("%s"buffer);
    }
    
    for (
int z 0MaxClientsz++)
    {
        if (!
IsClientInGame(z))
            continue;
        
        
LoadPlayTime(z);
    }
}

public 
void T_GetPlayerInfo(Handle dbHandle results, const char[] errorany data)
{
    if(
DATABASE_PlayerTime == INVALID_HANDLE)
        return;
        
    
int client data;
    
    if (!
IsClientInGame(client))
        return;
    
    if (!
SQL_FetchRow(results))
    {
        
IsInDatabase[client] = false;
    }
    else
    {
        
NbrSeconds[client] = SQL_FetchInt(results0);
        
IsInDatabase[client] = true;
    }
}

public 
void SaveIntoDatabase(int client)
{
    
char query[400];
    
char steamid[30];
    
    if (!
GetClientAuthId(clientAuthId_SteamID64steamidsizeof(steamid)))
        return;
    
    if (
IsInDatabase[client])
    {
        
Format(querysizeof(query), QUERY_UPDATE_ENTRYNbrSeconds[client], steamid);
        
SQL_FastQuery(DATABASE_PlayerTimequery);
    }
    else
    {
        
Format(querysizeof(query), QUERY_NEW_ENTRYsteamidNbrSeconds[client]);
        
SQL_FastQuery(DATABASE_PlayerTimequery);
    }

Attached Files
File Type: sp Get Plugin or Get Source (PlayTimeRecorder.sp - 75 views - 4.7 KB)
__________________
Want to check my plugins ?

Last edited by Arkarr; 10-23-2016 at 16:03.
Arkarr is offline
A_RM
AlliedModders Donor
Join Date: Oct 2016
Location: Canada
Old 10-23-2016 , 13:24   Re: [CS:GO] Looking for a simple point tracking system!
Reply With Quote #3

Quote:
Originally Posted by Arkarr View Post
I made this little script for ya. Not tested through.

Also, you want to edit the line 10 and maybe 8. The database schema should be like this :
Code:
+------ PLAYER_TIME ------+
+                         +
+  steamid (primary key)  +
+        stime (int)      +
+-------------------------+
Time stored in secondes. I'm sure you would be able to do the point systen by yourself now, or you still need help ?

I appreciate your help Arkarr, it means a lot!

To be honest yes I would need some help figuring out how to convert it to points, say per 1 minute of play time, as I have almost no experience with this

I'd hope to be able to access the point info in client as well. For example I want the users points to show up in a hint message every once in a while, I know there are a bunch of plugins using sm_hsay that I can do with this. So if you'd be able to help me figure out the time to point conversion aspect with this in mind (being able to access it within another plugin).

Again I greatly appreciate your help, thank you!

*Sorry I also forgot to mention I'd like to be able to give people extra points per minute if they meet a certain criteria, like if they're in my Steam group and using the clan tag... I feel like this would have to be changed in the original code you posted rather than after when the time is converted to points... if I'm thinking about this right? Honestly I'm not too sure.

Last edited by A_RM; 10-23-2016 at 13:30. Reason: added thought
A_RM is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 10-23-2016 , 13:39   Re: [CS:GO] Looking for a simple point tracking system!
Reply With Quote #4

how about Stamm? https://forums.alliedmods.net/showthread.php?p=1338942
Use just the core plugin and config to get points only for time.
__________________
coding & free software
shanapu is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 10-23-2016 , 13:59   Re: [CS:GO] Looking for a simple point tracking system!
Reply With Quote #5

@A_RM
You should consider using the shapanu solution. Also, if you would like me to finish my plugin, you should prepare a list of features you want (and post it in the OP) because it's extremly annoying (at least to me) to re-think / edit the whole plugin.
__________________
Want to check my plugins ?
Arkarr is offline
A_RM
AlliedModders Donor
Join Date: Oct 2016
Location: Canada
Old 10-23-2016 , 14:12   Re: [CS:GO] Looking for a simple point tracking system!
Reply With Quote #6

Quote:
Originally Posted by shanapu View Post
how about Stamm? https://forums.alliedmods.net/showthread.php?p=1338942
Use just the core plugin and config to get points only for time.
I took a quick look at that the other day and I didn't notice the "all in one downloader" that lets you configure a bunch of settings on their webpage, it looks much more appealing now!

Do you have any experience using Stamm? So which files would I have to upload exactly just for the point tracking... /cfg/stamm/everything + sourcemod/configs/databases.cfg + sourcemod/plugins/stamm.smx does that seem right, is there anythign else I would need?

Thanks for the help.
A_RM is offline
A_RM
AlliedModders Donor
Join Date: Oct 2016
Location: Canada
Old 10-23-2016 , 14:38   Re: [CS:GO] Looking for a simple point tracking system!
Reply With Quote #7

Quote:
Originally Posted by Arkarr View Post
@A_RM
You should consider using the shapanu solution. Also, if you would like me to finish my plugin, you should prepare a list of features you want (and post it in the OP) because it's extremly annoying (at least to me) to re-think / edit the whole plugin.
I understand completely. My sincerest apologies. I don't know if Stamm has exactly what I'm looking for. I have edited the original post if you could take a look. If it isn't clear enough let me know. I know this is probably a decent amount of work so I hope if you could get this working that you would accept a donation for your time

Last edited by A_RM; 10-23-2016 at 14:45.
A_RM is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 10-23-2016 , 14:54   Re: [CS:GO] Need a simple point tracking system!
Reply With Quote #8

I just read your edited post, it doesn't change much, at least less then what I thought.
Anyway, what are those 'points' ? You do the website part ? It seems like you know how to handle the php script to convert the points in cash.
__________________
Want to check my plugins ?
Arkarr is offline
A_RM
AlliedModders Donor
Join Date: Oct 2016
Location: Canada
Old 10-23-2016 , 15:01   Re: [CS:GO] Need a simple point tracking system!
Reply With Quote #9

Quote:
Originally Posted by Arkarr View Post
I just read your edited post, it doesn't change much, at least less then what I thought.
Anyway, what are those 'points' ? You do the website part ? It seems like you know how to handle the php script to convert the points in cash.
Points: for example you get 4 points/credits per minute by meeting the two name criteria. Once you have XXXXX amount of points you can request a $5 PayPal payment from me on the website so you can afford to subscribe on Twitch.

I have two friends who are web developers and have experience with mysql and php that are helping me with the website. However they don't have any experience with csgo plugins. So as long as the points that each user has are in the website database they should be able to figure out the rest I believe.

Last edited by A_RM; 10-23-2016 at 15:03.
A_RM is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 10-23-2016 , 15:06   Re: [CS:GO] Need a simple point tracking system!
Reply With Quote #10

Quote:
Originally Posted by A_RM View Post
Points: for example you get 4 points/credits per minute by meeting the two name criteria. Once you have XXXXX amount of points you can request a $5 PayPal payment from me on the website so you can afford to subscribe on Twitch.

I have two friends who are web developers and have experience with mysql and php that are helping me with the website. However they don't have any experience with csgo plugins. So as long as the points that each user has are in the website database they should be able to figure out the rest I believe.
Fine. I'll do your code now. Would you do me a favor and tell me if the above snippet works ?
__________________
Want to check my plugins ?
Arkarr 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 05:53.


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