Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #define DEBUG
- #define PLUGIN_AUTHOR "IMDeadShot"
- #define PLUGIN_VERSION "1.00"
- #define PREFIX " \x04[Vgames]\x01"
- #define NEW_PLAYER_CASH 500
- #define QUERY_DEFAULT_SIZE 256
- #include <sourcemod>
- #include <sdktools>
- #include <cstrike>
- EngineVersion g_Game;
- public Plugin:myinfo =
- {
- name = "CashSystem",
- author = PLUGIN_AUTHOR,
- description = "",
- version = PLUGIN_VERSION,
- url = ""
- };
- Database g_dbDataBase;
- int g_iCash[MAXPLAYERS + 1];
- char g_szLogLocation[PLATFORM_MAX_PATH];
- public OnPluginStart()
- {
- g_Game = GetEngineVersion();
- if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
- {
- SetFailState("This plugin is for CSGO/CSS only.");
- }
- LoadTranslations("common.phrases");
- if(g_dbDataBase == INVALID_HANDLE)
- {
- char szError[QUERY_DEFAULT_SIZE];
- g_dbDataBase = SQL_Connect("CashSystem", true, szError, sizeof(szError));
- if(g_dbDataBase == null)
- {
- SetFailState("Faild to connect to the database. Error(%s)", szError);
- return;
- }
- g_dbDataBase.Query(SQL_Void, "CREATE TABLE `users_cash` ( `steamid` VARCHAR(32), `cash` INT );");
- }
- BuildPath(Path_SM, g_szLogLocation, sizeof(g_szLogLocation), "logs/setcashlog.txt");
- RegConsoleCmd("sm_cash", Commend_Cash, "Show the client the cash he have.");
- RegAdminCmd("sm_setcash", Commend_SetCash, ADMFLAG_ROOT, "Set client cash.");
- RegConsoleCmd("sm_givecash", Commend_GiveCash, "Client give cash to client");
- }
- /* Commends */
- public Action Commend_Cash(int client, int args)
- {
- PrintToChat(client, "%s You have \x0c%d\x01 cash", PREFIX, g_iCash[client]);
- return Plugin_Handled;
- }
- public Action Commend_SetCash(int client, int args)
- {
- if(args < 2)
- {
- PrintToChat(client, "%s Usage: /setcash <client> <cash>", PREFIX);
- return Plugin_Handled;
- }
- char arg1[MAX_NAME_LENGTH], arg2[11];
- GetCmdArg(1, arg1, sizeof(arg1));
- GetCmdArg(2, arg2, sizeof(arg2));
- int target = FindTarget(client, arg1, false, false);
- if(target == -1)
- {
- return Plugin_Handled;
- }
- int cash = StringToInt(arg2);
- setCash(target, cash);
- PrintToChat(client, "%s You set \x0c%N\x01 cash to \x0c%d\x01", PREFIX, arg1, cash);
- PrintToChat(target, "%s \x02ADMIN:\x01 %N set your cash to \x0c%d", PREFIX, client, cash);
- LogToFile(g_szLogLocation, "%L set %L cash to %d", client, target, cash);
- return Plugin_Handled;
- }
- public Action Commend_GiveCash(int client, int args)
- {
- if(args < 2)
- {
- PrintToChat(client, "%s Usage: /givecash <client> <cash>", PREFIX);
- return Plugin_Handled;
- }
- char arg1[MAX_NAME_LENGTH], arg2[11];
- GetCmdArg(1, arg1, sizeof(arg1));
- GetCmdArg(2, arg2, sizeof(arg2));
- int target = FindTarget(client, arg1, false, false);
- if(target == -1)
- {
- return Plugin_Handled;
- }
- int cash = StringToInt(arg2);
- if(g_iCash[client] <= cash && cash > 0)
- {
- return Plugin_Handled;
- }
- giveCash(target, cash);
- takeCash(client, cash);
- PrintToChat(client, "%s You give to \x0c%N\x01 \x0c%d\x0c cash!", PREFIX, target, cash);
- PrintToChat(target, "%s \x0c%N\x01 give to you \x0c%d\x01 cash!", PREFIX, client, cash);
- return Plugin_Handled;
- }
- /* */
- public void OnClientPostAdminCheck(int client)
- {
- char szSteamID[MAX_NAME_LENGTH];
- if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
- {
- char szQuery[QUERY_DEFAULT_SIZE];
- FormatEx(szQuery, sizeof(szQuery), "SELECT cash FROM users_cash WHERE steamid='%s'", szSteamID);
- g_dbDataBase.Query(SQL_ClientCash, szQuery, GetClientSerial(client));
- }
- }
- /* SQL Callbacks */
- public void SQL_Void(Database db, DBResultSet results, const char[] error, any data)
- {
- if(results == null)
- {
- LogError("Error: SQL Query failed: %s", error);
- }
- }
- public void SQL_ClientCash(Database db, DBResultSet results, const char[] error, any data)
- {
- if(results == null)
- {
- LogError("Error: SQL_ClientCash failed: %s", error);
- }
- int client = GetClientFromSerial(data);
- if(!client)
- {
- return;
- }
- if(results.FetchRow())
- {
- g_iCash[client] = results.FetchInt(0);
- }
- else
- {
- char szSteamID[MAX_NAME_LENGTH];
- if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
- {
- char szQuery[QUERY_DEFAULT_SIZE];
- FormatEx(szQuery, sizeof(szQuery), "INSERT INTO users_cash (steamid, cash) VALUES ('%s', '%i')", szSteamID, NEW_PLAYER_CASH);
- g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
- g_dbDataBase.Query(SQL_Void, szQuery);
- g_iCash[client] = NEW_PLAYER_CASH;
- }
- }
- }
- /* */
- /* Functions, stocks.. */
- void setCash(int client, int cash)
- {
- char szSteamID[MAX_NAME_LENGTH];
- if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
- {
- char szQuery[QUERY_DEFAULT_SIZE];
- FormatEx(szQuery, sizeof(szQuery), "UPDATE users_cash SET cash='%i' WHERE steamid='%s'", cash, szSteamID);
- g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
- g_dbDataBase.Query(SQL_Void, szQuery);
- g_iCash[client] = cash;
- }
- }
- void giveCash(int client, int cash)
- {
- char szSteamID[MAX_NAME_LENGTH];
- if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
- {
- g_iCash[client] = g_iCash[client] + cash;
- char szQuery[QUERY_DEFAULT_SIZE];
- FormatEx(szQuery, sizeof(szQuery), "UPDATE users_cash SET cash='%i' WHERE steamid='%s'", g_iCash[client], szSteamID);
- g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
- g_dbDataBase.Query(SQL_Void, szQuery);
- }
- }
- void takeCash(int client, int cash)
- {
- if(g_iCash[client] <= cash && cash > 0)
- {
- return;
- }
- char szSteamID[MAX_NAME_LENGTH];
- if(GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID)))
- {
- g_iCash[client] = g_iCash[client] - cash;
- char szQuery[QUERY_DEFAULT_SIZE];
- FormatEx(szQuery, sizeof(szQuery), "UPDATE users_cash SET cash='%i' WHERE steamid='%s'", g_iCash[client], szSteamID);
- g_dbDataBase.Query(SQL_Void, szQuery, GetClientSerial(client));
- g_dbDataBase.Query(SQL_Void, szQuery);
- }
- }
- /* */
- /* Natives */
- public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
- {
- CreateNative("SetClientCash", Native_SetClientCash);
- CreateNative("TakeClientCash", Native_TakeClientCash);
- return APLRes_Success;
- }
- public int Native_SetClientCash(Handle plugin, int numParams)
- {
- int client = GetNativeCell(1);
- int cash = GetNativeCell(2);
- giveCash(client, cash);
- return;
- }
- public int Native_TakeClientCash(Handle plugin, int numParams)
- {
- int client = GetNativeCell(1);
- int cash = GetNativeCell(2);
- takeCash(client, cash);
- return;
- }
- /* */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement