Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #include <sourcemod>
- #define PLUGIN_VERSION "0.1"
- new Handle:db = INVALID_HANDLE;
- new Handle:sm_loyalty_version;
- new timep[MAXPLAYERS+1];
- new joined[MAXPLAYERS+1];
- new points[MAXPLAYERS+1];
- new timeReq;
- public Plugin:myinfo =
- {
- name = "sG Loyalty Point System",
- author = "fail klark",
- description = "Loyalty points are credited for time played on the server",
- version = PLUGIN_VERSION,
- url = ""
- }
- public OnPluginStart() {
- new Handle:sm_loyal_time = CreateConVar("sm_loyal_time", "10", "Minutes of play required to be awarded points");
- sm_loyal_version = CreateConVar("sm_loyal_version", PLUGIN_VERSION, "Version of sG Loyalty System", FCVAR_NOTIFY);
- SetConVarString(sm_loyal_version, PLUGIN_VERSION);
- LoadTranslations("common.phrases");
- RegConsoleCmd("sm_points", Command_points, "See current points.");
- decl String:steamid[32];
- for(new i=1;i<=MaxClients;i++) {
- if(IsClientConnected(i) && IsClientAuthorized(i)) {
- GetClientAuthString(i, steamid, sizeof(steamid));
- OnClientAuthorized(i, steamid);
- }
- }
- decl String:error[256];
- if(SQL_CheckConfig("loyaltysystem")) {
- db = SQL_Connect("loyaltysystem", true, error, sizeof(error));
- LogMessage("Connecting to database...");
- }else{
- db = INVALID_HANDLE;
- LogMessage("Could not find database in config.");
- }
- if(db==INVALID_HANDLE)
- SetFailState("Could not connect to database: %s", error);
- }
- public OnClientAuthorized(client, const String:steamid[]) {
- if (!IsFakeClient(client)) {
- decl String:query[512];
- Format(query, sizeof(query), "SELECT time,points FROM loyal WHERE steamid='%s'", steamid);
- SQL_TQuery(db, SQLQueryConnect, query, GetClientUserId(client));
- joined[client] = GetTime();
- }
- }
- public OnClientDisconnect(client) {
- if(!IsFakeClient(client)) {
- decl String:steamid[32], String:query[512];
- GetClientAuthString(client, steamid, sizeof(steamid));
- Format(query, sizeof(query), "UPDATE loyal SET time=time+%i WHERE steamid='%s'", GetTime()-joined[client], steamid);
- SQL_TQuery(db, SQLErrorCheckCallback, query);
- }
- }
- public Action:Command_points(client, args) {
- return Plugin_Handled;
- }
- public SQLCheckServerPermission(Handle:owner, Handle:hndl, const String:error[], any:aid)
- {
- new bool:IsAidPresent;
- if (hndl == INVALID_HANDLE)
- {
- LogError("Query failed(SQLCheckServerPermission)! %s", error);
- }
- else
- {
- while(SQL_FetchRow(hndl))
- {
- if((SQL_FetchInt(hndl, 0) == aid))
- {
- IsAidPresent = true;
- break;
- }
- }
- }
- return IsAidPresent;
- }
- public SQLQueryConnect(Handle:owner, Handle:hndl, const String:error[], any:data) {
- new client;
- if((client = GetClientOfUserId(data))==0)
- return;
- if(hndl==INVALID_HANDLE) {
- LogError("Query failed(SQLQueryConnect): %s", error);
- } else {
- decl String:query[512], String:clientname[MAX_NAME_LENGTH], String:steamid[32];
- GetClientName(client, clientname, sizeof(clientname));
- ReplaceString(clientname, sizeof(clientname), "'", "");
- GetClientAuthString(client, steamid, sizeof(steamid));
- if(!SQL_MoreRows(hndl)) {
- Format(query, sizeof(query), "INSERT INTO loyal (steamid, time, points, forumid) VALUES ('%s', 0, 0, 0)", steamid);
- }
- SQL_TQuery(db, SQLErrorCheckCallback, query);
- timep[client] = 0;
- points[client] = 0;
- } else if(SQL_FetchRow(hndl)) {
- timep[client] = SQL_FetchInt(hndl, 0);
- points[client] = SQL_FetchInt(hndl, 1);
- }
- }
- }
- public SQLErrorCheckCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
- {
- if(!StrEqual("", error))
- LogError("Query failed(SQLErrorCheckCallback): %s", error);
- }
Add Comment
Please, Sign In to add comment