Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #define DEBUG
  4.  
  5. #define PLUGIN_AUTHOR "IMDeadShot"
  6. #define PLUGIN_VERSION "1.00"
  7. #define PREFIX " \x04[Vgames]\x01"
  8. #define NEW_PLAYER_CASH 500
  9. #define QUERY_DEFAULT_SIZE 256
  10.  
  11. #include <sourcemod>
  12. #include <sdktools>
  13. #include <cstrike>
  14.  
  15.  
  16. EngineVersion g_Game;
  17.  
  18. public Plugin:myinfo =
  19. {
  20. name = "CashSystem",
  21. author = PLUGIN_AUTHOR,
  22. description = "",
  23. version = PLUGIN_VERSION,
  24. url = ""
  25. };
  26.  
  27. Database g_dbDataBase;
  28. int g_iCash[MAXPLAYERS + 1];
  29. char g_szLogLocation[PLATFORM_MAX_PATH];
  30.  
  31.  
  32. public OnPluginStart()
  33. {
  34. g_Game = GetEngineVersion();
  35. if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
  36. {
  37. SetFailState("This plugin is for CSGO/CSS only.");
  38. }
  39.  
  40. LoadTranslations("common.phrases");
  41.  
  42. if(g_dbDataBase == INVALID_HANDLE)
  43. {
  44. char szError[QUERY_DEFAULT_SIZE];
  45.  
  46. g_dbDataBase = SQL_Connect("CashSystem", true, szError, sizeof(szError));
  47. if(g_dbDataBase == null)
  48. {
  49. SetFailState("Faild to connect to the database. Error(%s)", szError);
  50. return;
  51. }
  52. g_dbDataBase.Query(SQL_Void, "CREATE TABLE `users_cash` ( `steamid` VARCHAR(32), `cash` INT );");
  53. }
  54. BuildPath(Path_SM, g_szLogLocation, sizeof(g_szLogLocation), "logs/setcashlog.txt");
  55.  
  56. RegConsoleCmd("sm_cash", Commend_Cash, "Show the client the cash he have.");
  57. RegAdminCmd("sm_setcash", Commend_SetCash, ADMFLAG_ROOT, "Set client cash.");
  58. RegConsoleCmd("sm_givecash", Commend_GiveCash, "Client give cash to client");
  59.  
  60. }
  61.  
  62. /* Commends */
  63.  
  64. public Action Commend_Cash(int client, int args)
  65. {
  66. PrintToChat(client, "%s You have \x0c%d\x01 cash", PREFIX, g_iCash[client]);
  67. return Plugin_Handled;
  68. }
  69.  
  70. public Action Commend_SetCash(int client, int args)
  71. {
  72. if(args < 2)
  73. {
  74. PrintToChat(client, "%s Usage: /setcash <client> <cash>", PREFIX);
  75. return Plugin_Handled;
  76. }
  77.  
  78. char arg1[MAX_NAME_LENGTH], arg2[11];
  79. GetCmdArg(1, arg1, sizeof(arg1));
  80. GetCmdArg(2, arg2, sizeof(arg2));
  81.  
  82. int target = FindTarget(client, arg1, false, false);
  83. if(target == -1)
  84. {
  85. return Plugin_Handled;
  86. }
  87. int cash = StringToInt(arg2);
  88.  
  89. setCash(target, cash);
  90.  
  91. PrintToChat(client, "%s You set \x0c%N\x01 cash to \x0c%d\x01", PREFIX, arg1, cash);
  92. PrintToChat(target, "%s \x02ADMIN:\x01 %N set your cash to \x0c%d", PREFIX, client, cash);
  93.  
  94. LogToFile(g_szLogLocation, "%L set %L cash to %d", client, target, cash);
  95.  
  96. return Plugin_Handled;
  97. }
  98.  
  99. public Action Commend_GiveCash(int client, int args)
  100. {
  101. if(args < 2)
  102. {
  103. PrintToChat(client, "%s Usage: /givecash <client> <cash>", PREFIX);
  104. return Plugin_Handled;
  105. }
  106.  
  107. char arg1[MAX_NAME_LENGTH], arg2[11];
  108. GetCmdArg(1, arg1, sizeof(arg1));
  109. GetCmdArg(2, arg2, sizeof(arg2));
  110.  
  111. int target = FindTarget(client, arg1, false, false);
  112. if(target == -1)
  113. {
  114. return Plugin_Handled;
  115. }
  116. int cash = StringToInt(arg2);
  117.  
  118. if(g_iCash[client] <= cash && cash > 0)
  119. {
  120. return Plugin_Handled;
  121. }
  122.  
  123. giveCash(target, cash);
  124. takeCash(client, cash);
  125.  
  126. PrintToChat(client, "%s You give to \x0c%N\x01 \x0c%d\x0c cash!", PREFIX, target, cash);
  127. PrintToChat(target, "%s \x0c%N\x01 give to you \x0c%d\x01 cash!", PREFIX, client, cash);
  128. return Plugin_Handled;
  129.  
  130. }
  131.  
  132. /* */
  133.  
  134. public void OnClientPostAdminCheck(int client)
  135. {
  136. char szSteamID[MAX_NAME_LENGTH];
  137.  
  138. if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
  139. {
  140. char szQuery[QUERY_DEFAULT_SIZE];
  141. FormatEx(szQuery, sizeof(szQuery), "SELECT cash FROM users_cash WHERE steamid='%s'", szSteamID);
  142. g_dbDataBase.Query(SQL_ClientCash, szQuery, GetClientSerial(client));
  143. }
  144. }
  145.  
  146. /* SQL Callbacks */
  147.  
  148. public void SQL_Void(Database db, DBResultSet results, const char[] error, any data)
  149. {
  150. if(results == null)
  151. {
  152. LogError("Error: SQL Query failed: %s", error);
  153. }
  154. }
  155.  
  156. public void SQL_ClientCash(Database db, DBResultSet results, const char[] error, any data)
  157. {
  158. if(results == null)
  159. {
  160. LogError("Error: SQL_ClientCash failed: %s", error);
  161. }
  162.  
  163. int client = GetClientFromSerial(data);
  164. if(!client)
  165. {
  166. return;
  167. }
  168.  
  169. if(results.FetchRow())
  170. {
  171. g_iCash[client] = results.FetchInt(0);
  172. }
  173. else
  174. {
  175. char szSteamID[MAX_NAME_LENGTH];
  176.  
  177. if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
  178. {
  179. char szQuery[QUERY_DEFAULT_SIZE];
  180. FormatEx(szQuery, sizeof(szQuery), "INSERT INTO users_cash (steamid, cash) VALUES ('%s', '%i')", szSteamID, NEW_PLAYER_CASH);
  181. g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
  182. g_dbDataBase.Query(SQL_Void, szQuery);
  183. g_iCash[client] = NEW_PLAYER_CASH;
  184. }
  185. }
  186. }
  187.  
  188. /* */
  189.  
  190. /* Functions, stocks.. */
  191.  
  192. void setCash(int client, int cash)
  193. {
  194. char szSteamID[MAX_NAME_LENGTH];
  195. if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
  196. {
  197. char szQuery[QUERY_DEFAULT_SIZE];
  198. FormatEx(szQuery, sizeof(szQuery), "UPDATE users_cash SET cash='%i' WHERE steamid='%s'", cash, szSteamID);
  199. g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
  200. g_dbDataBase.Query(SQL_Void, szQuery);
  201. g_iCash[client] = cash;
  202. }
  203. }
  204.  
  205. void giveCash(int client, int cash)
  206. {
  207. char szSteamID[MAX_NAME_LENGTH];
  208. if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
  209. {
  210. g_iCash[client] = g_iCash[client] + cash;
  211. char szQuery[QUERY_DEFAULT_SIZE];
  212. FormatEx(szQuery, sizeof(szQuery), "UPDATE users_cash SET cash='%i' WHERE steamid='%s'", g_iCash[client], szSteamID);
  213. g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
  214. g_dbDataBase.Query(SQL_Void, szQuery);
  215.  
  216. }
  217. }
  218.  
  219. void takeCash(int client, int cash)
  220. {
  221. if(g_iCash[client] <= cash && cash > 0)
  222. {
  223. return;
  224. }
  225. char szSteamID[MAX_NAME_LENGTH];
  226. if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
  227. {
  228. g_iCash[client] = g_iCash[client] - cash;
  229. char szQuery[QUERY_DEFAULT_SIZE];
  230. FormatEx(szQuery, sizeof(szQuery), "UPDATE users_cash SET cash='%i' WHERE steamid='%s'", g_iCash[client], szSteamID);
  231. g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
  232. g_dbDataBase.Query(SQL_Void, szQuery);
  233. }
  234. }
  235.  
  236. /* */
  237.  
  238.  
  239. /* Natives */
  240.  
  241. public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
  242. {
  243. CreateNative("SetClientCash", Native_SetClientCash);
  244. CreateNative("TakeClientCash", Native_TakeClientCash);
  245. return APLRes_Success;
  246. }
  247.  
  248. public int Native_SetClientCash(Handle plugin, int numParams)
  249. {
  250. int client = GetNativeCell(1);
  251. int cash = GetNativeCell(2);
  252. giveCash(client, cash);
  253. return;
  254. }
  255.  
  256. public int Native_TakeClientCash(Handle plugin, int numParams)
  257. {
  258. int client = GetNativeCell(1);
  259. int cash = GetNativeCell(2);
  260. takeCash(client, cash);
  261. return;
  262. }
  263.  
  264. /* */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement