Guest User

Untitled

a guest
Oct 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #define PLUGIN_VERSION "0.1"
  4.  
  5. new Handle:db = INVALID_HANDLE;
  6. new Handle:sm_loyalty_version;
  7. new timep[MAXPLAYERS+1];
  8. new joined[MAXPLAYERS+1];
  9. new points[MAXPLAYERS+1];
  10. new timeReq;
  11.  
  12. public Plugin:myinfo =
  13. {
  14. name = "sG Loyalty Point System",
  15. author = "fail klark",
  16. description = "Loyalty points are credited for time played on the server",
  17. version = PLUGIN_VERSION,
  18. url = ""
  19. }
  20.  
  21. public OnPluginStart() {
  22. new Handle:sm_loyal_time = CreateConVar("sm_loyal_time", "10", "Minutes of play required to be awarded points");
  23. sm_loyal_version = CreateConVar("sm_loyal_version", PLUGIN_VERSION, "Version of sG Loyalty System", FCVAR_NOTIFY);
  24. SetConVarString(sm_loyal_version, PLUGIN_VERSION);
  25.  
  26. LoadTranslations("common.phrases");
  27. RegConsoleCmd("sm_points", Command_points, "See current points.");
  28.  
  29. decl String:steamid[32];
  30. for(new i=1;i<=MaxClients;i++) {
  31. if(IsClientConnected(i) && IsClientAuthorized(i)) {
  32. GetClientAuthString(i, steamid, sizeof(steamid));
  33. OnClientAuthorized(i, steamid);
  34. }
  35. }
  36.  
  37. decl String:error[256];
  38. if(SQL_CheckConfig("loyaltysystem")) {
  39. db = SQL_Connect("loyaltysystem", true, error, sizeof(error));
  40. LogMessage("Connecting to database...");
  41. }else{
  42. db = INVALID_HANDLE;
  43. LogMessage("Could not find database in config.");
  44. }
  45.  
  46. if(db==INVALID_HANDLE)
  47. SetFailState("Could not connect to database: %s", error);
  48. }
  49.  
  50. public OnClientAuthorized(client, const String:steamid[]) {
  51. if (!IsFakeClient(client)) {
  52. decl String:query[512];
  53. Format(query, sizeof(query), "SELECT time,points FROM loyal WHERE steamid='%s'", steamid);
  54. SQL_TQuery(db, SQLQueryConnect, query, GetClientUserId(client));
  55. joined[client] = GetTime();
  56. }
  57. }
  58.  
  59. public OnClientDisconnect(client) {
  60. if(!IsFakeClient(client)) {
  61. decl String:steamid[32], String:query[512];
  62. GetClientAuthString(client, steamid, sizeof(steamid));
  63. Format(query, sizeof(query), "UPDATE loyal SET time=time+%i WHERE steamid='%s'", GetTime()-joined[client], steamid);
  64. SQL_TQuery(db, SQLErrorCheckCallback, query);
  65. }
  66. }
  67.  
  68. public Action:Command_points(client, args) {
  69. return Plugin_Handled;
  70. }
  71.  
  72.  
  73. public SQLCheckServerPermission(Handle:owner, Handle:hndl, const String:error[], any:aid)
  74. {
  75. new bool:IsAidPresent;
  76. if (hndl == INVALID_HANDLE)
  77. {
  78. LogError("Query failed(SQLCheckServerPermission)! %s", error);
  79. }
  80. else
  81. {
  82. while(SQL_FetchRow(hndl))
  83. {
  84. if((SQL_FetchInt(hndl, 0) == aid))
  85. {
  86. IsAidPresent = true;
  87. break;
  88. }
  89. }
  90. }
  91. return IsAidPresent;
  92. }
  93.  
  94. public SQLQueryConnect(Handle:owner, Handle:hndl, const String:error[], any:data) {
  95. new client;
  96. if((client = GetClientOfUserId(data))==0)
  97. return;
  98. if(hndl==INVALID_HANDLE) {
  99. LogError("Query failed(SQLQueryConnect): %s", error);
  100. } else {
  101. decl String:query[512], String:clientname[MAX_NAME_LENGTH], String:steamid[32];
  102. GetClientName(client, clientname, sizeof(clientname));
  103. ReplaceString(clientname, sizeof(clientname), "'", "");
  104. GetClientAuthString(client, steamid, sizeof(steamid));
  105. if(!SQL_MoreRows(hndl)) {
  106. Format(query, sizeof(query), "INSERT INTO loyal (steamid, time, points, forumid) VALUES ('%s', 0, 0, 0)", steamid);
  107. }
  108. SQL_TQuery(db, SQLErrorCheckCallback, query);
  109. timep[client] = 0;
  110. points[client] = 0;
  111. } else if(SQL_FetchRow(hndl)) {
  112. timep[client] = SQL_FetchInt(hndl, 0);
  113. points[client] = SQL_FetchInt(hndl, 1);
  114. }
  115. }
  116. }
  117.  
  118. public SQLErrorCheckCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
  119. {
  120. if(!StrEqual("", error))
  121. LogError("Query failed(SQLErrorCheckCallback): %s", error);
  122. }
Add Comment
Please, Sign In to add comment