Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <clientprefs>
- public Plugin myinfo =
- {
- name = "Shop API",
- author = "JuSTaR",
- description = "Shop API",
- version = "1.0",
- url = "https://www.fxp.co.il/"
- }
- Handle DataCookies; // used to handle cookies Database
- ConVar GambleChance; // cvar used to set the gamble wining precent
- int Points[MAXPLAYERS]; // store players points
- public void OnPluginStart()
- {
- DataCookies = RegClientCookie("ShopAPI", "ShopAPI Cookies", CookieAccess_Private);
- GambleChance = CreateConVar("gamble_chance", "50", "Sets gamble winning chance");
- RegConsoleCmd("p", CheckPoints);
- RegConsoleCmd("points", CheckPoints);
- RegConsoleCmd("gamble", OnGamble);
- RegAdminCmd("give_points", OnGivePoints, ADMFLAG_RCON);
- RegAdminCmd("take_points", OnTakePoints, ADMFLAG_RCON);
- RegAdminCmd("set_points", OnSetPoints, ADMFLAG_RCON);
- LoadTranslations("common.phrases.txt"); // FindTarget uses it
- }
- public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
- {
- CreateNative("Native_GivePoints", Native_Give_Points);
- CreateNative("Native_TakePoints", Native_Take_Points);
- CreateNative("Native_GetPoints", Native_Get_Points);
- CreateNative("Native_SetPoints", Native_Set_Points);
- return APLRes_Success;
- }
- public void OnClientPutInServer(int client)
- {
- if (AreClientCookiesCached(client))
- {
- char sPoints[12];
- GetClientCookie(client, DataCookies, sPoints, sizeof(sPoints));
- Points[client] = StringToInt(sPoints);
- }
- }
- public void OnClientDisconnect(int client)
- {
- SavePoints(client);
- }
- public int Native_Set_Points(Handle:plugin, int numParams)
- {
- int target = GetNativeCell(1);
- int PtsToSet = GetNativeCell(2);
- GivePoints(target, PtsToSet);
- }
- public int Native_Get_Points(Handle:plugin, int numParams)
- {
- int target = GetNativeCell(1);
- if (IsClientConnected(target))
- return Points[target];
- else
- LogError("[ShopAPI] (Get_Points) Unable to find target [id:%d].", target);
- return -1;
- }
- public int Native_Give_Points(Handle:plugin, int numParams)
- {
- int target = GetNativeCell(1);
- int PtsToGive = GetNativeCell(2);
- GivePoints(target, PtsToGive);
- }
- public int Native_Take_Points(Handle:plugin, int numParamse)
- {
- int target = GetNativeCell(1);
- int PtsToTake = GetNativeCell(2);
- TakePoints(target, PtsToTake);
- }
- public void SetPoints(int target, int PtsToSet)
- {
- if (IsClientConnected(target))
- {
- Points[target] = PtsToSet;
- SavePoints(target);
- }
- else
- LogError("[ShopAPI] (Set_Points) Unable to find target [id:%d].", target);
- }
- public void GivePoints(int target, int PtsToGive)
- {
- if (IsClientConnected(target))
- {
- Points[target] += PtsToGive;
- SavePoints(target);
- }
- else
- LogError("[ShopAPI] (Give_Points) Unable to find target [id:%d].", target);
- }
- public void TakePoints(int target, int PtsToTake)
- {
- if (IsClientConnected(target))
- {
- if (Points[target] - PtsToTake < 0)
- Points[target] = 0;
- else
- Points[target] -= PtsToTake;
- SavePoints(target);
- }
- else
- LogError("[ShopAPI] (Take_Points) Unable to find target [id:%d].", target);
- }
- public Action CheckPoints(int client, int args)
- {
- char arg[32];
- if (GetCmdArg(1, arg, sizeof(arg)) > 0)
- {
- int target = FindTarget(0, arg);
- if (target == -1)
- {
- PrintToChat(client,"Invalid player name.");
- return Plugin_Handled;
- }
- else
- {
- PrintToChat(client,"%N has %d Points.", target, Points[target]);
- return Plugin_Handled;
- }
- }
- PrintToChat(client,"You have %d Points.", Points[client]);
- return Plugin_Handled;
- }
- public Action OnGamble(int client, int args)
- {
- char arg[32];
- GetCmdArg(1, arg, sizeof(arg));
- int GambledPoints = StringToInt(arg);
- bool AllIn = false;
- if (StrEqual(arg, "AllIn", false)) // if allin
- {
- GambledPoints = Points[client];
- AllIn = true;
- }
- if (GambledPoints == 0) // if arg is not a number
- {
- PrintToChat(client,"Invalid points number.");
- return Plugin_Handled;
- }
- else if (Points[client] == 0 || Points[client] < GambledPoints) // not enough points
- {
- PrintToChat(client,"You don't have enough points.");
- return Plugin_Handled;
- }
- if (GetRandomInt(1, 100) >= 100-GetConVarInt(GambleChance)) // won gamble
- {
- if (AllIn)
- {
- PrintToChatAll("%N has gambled AllIn (%d Points) and Won!", client, GambledPoints);
- GivePoints(client, GambledPoints);
- AllIn = false;
- }
- else
- {
- PrintToChatAll("%N has gambled and Won %d Points!", client, GambledPoints);
- GivePoints(client, GambledPoints);
- }
- }
- else // lose gamble
- {
- if (AllIn)
- {
- PrintToChatAll("%N has gambled AllIn (%d Points) and Lost!", client, GambledPoints);
- TakePoints(client, GambledPoints);
- AllIn = false;
- }
- else
- {
- PrintToChatAll("%N has gambled %d Points and Lost.", client, GambledPoints);
- TakePoints(client, GambledPoints);
- }
- }
- return Plugin_Handled;
- }
- public Action OnSetPoints(int client, int args)
- {
- char a1[32];
- char a2[32];
- GetCmdArg(1, a1, sizeof(a1));
- GetCmdArg(2, a2, sizeof(a2));
- int target = FindTarget(0, a1);
- int PtsToSet;
- if (target == -1)
- {
- PrintToChat(client,"Invalid player name.");
- return Plugin_Handled;
- }
- if (StringToInt(a2) <= 0)
- {
- PrintToChat(client,"Invalid points number.");
- return Plugin_Handled;
- }
- PtsToSet = StringToInt(a2);
- PrintToChatAll("%N has set %N %d Points!", client, target, PtsToSet);
- SetPoints(target, PtsToSet);
- return Plugin_Handled;
- }
- public Action OnGivePoints(int client, int args)
- {
- char a1[32];
- char a2[32];
- GetCmdArg(1, a1, sizeof(a1));
- GetCmdArg(2, a2, sizeof(a2));
- int target = FindTarget(0, a1);
- int PtsToGive;
- if (target == -1)
- {
- PrintToChat(client,"Invalid player name.");
- return Plugin_Handled;
- }
- if (StringToInt(a2) <= 0)
- {
- PrintToChat(client,"Invalid points number.");
- return Plugin_Handled;
- }
- PtsToGive = StringToInt(a2);
- PrintToChatAll("%N has gave %N %d Points!", client, target, PtsToGive);
- GivePoints(target, PtsToGive);
- return Plugin_Handled;
- }
- public Action OnTakePoints(int client, int args)
- {
- char a1[32];
- char a2[32];
- GetCmdArg(1, a1, sizeof(a1));
- GetCmdArg(2, a2, sizeof(a2));
- int target = FindTarget(0, a1);
- int PtsToTake;
- if (target == -1)
- {
- PrintToChat(client,"Invalid player name.");
- return Plugin_Handled;
- }
- if (StringToInt(a2) <= 0)
- {
- PrintToChat(client,"Invalid points number.");
- return Plugin_Handled;
- }
- PtsToTake = StringToInt(a2);
- PrintToChatAll("%N has took %d Points from %N!", client, PtsToTake, target);
- TakePoints(target, PtsToTake);
- return Plugin_Handled;
- }
- public void SavePoints(int client)
- {
- if (AreClientCookiesCached(client))
- {
- char sPoints[12];
- IntToString(Points[client], sPoints, sizeof(sPoints));
- SetClientCookie(client, DataCookies, sPoints);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement