|
Member
|
07-19-2018
, 20:31
Re: [CS:GO] coinflip credits for store plugin
|
#6
|
Quote:
Originally Posted by LenHard
PHP Code:
#include <sourcemod>
#include <store>
#pragma semicolon 1
#pragma newdecls required
#define DELAY 10.0
float gF_Delay[MAXPLAYERS + 1];
public void OnPluginStart() {
RegConsoleCmd("sm_coinflip", Cmd_FlipCoin, "Flips a coin.");
}
public void OnClientPostAdminCheck(int client) {
gF_Delay[client] = 0.0;
}
public Action Cmd_FlipCoin(int client, int args)
{
if (0 < client <= MaxClients && IsClientInGame(client))
{
if (args != 2)
{
ReplyToCommand(client, "[SM] Usage: sm_coinflip <heads | tails> <quantity>");
return Plugin_Handled;
}
float fTime = GetGameTime();
if (gF_Delay[client] > fTime)
{
ReplyToCommand(client, "[SM] You need to wait \x04%.02f\x01 seconds before using the command again.", gF_Delay[client] - fTime);
return Plugin_Handled;
}
char[] sArg = new char[10];
GetCmdArg(1, sArg, 10);
bool bHead;
if (StrContains(sArg, "head", false) != -1)
bHead = true;
GetCmdArg(2, sArg, 10);
int iValue = StringToInt(sArg);
if (iValue > 0)
{
int iCredits = Store_GetClientCredits(client);
if (iCredits < iValue)
{
ReplyToCommand(client, "[SM] Insufficient funds.");
return Plugin_Handled;
}
gF_Delay[client] = fTime + DELAY;
if (view_as<bool>(GetRandomInt(0, 1)) == bHead)
{
Store_SetClientCredits(client, iCredits + iValue);
PrintToChat(client, "[SM] You won \x04%i\x01 credits due to the result being \"\x04Heads\x01\"", iValue);
}
else
{
Store_SetClientCredits(client, iCredits - iValue);
PrintToChat(client, "[SM] You lost \x04%i\x01 credits due to the result being \"\x04Tails\x01\"", iValue);
}
}
else ReplyToCommand(client, "[SM] You need to bet higher than 0");
}
return Plugin_Handled;
}
|
Worked fine! thanks.
|
|
|
|