#include <sourcemod>
#include <multicolors>
#define TAG "[{yellow}JackPot{default}]"
#define newdecls required
#define semicolon 1
native Cases_SetClientBalance(client, credits);
native Cases_GetClientBalance(client);
int Pot=0, GmbCount=0;
int Gambled[MAXPLAYERS + 1], chance[MAXPLAYERS+1], g_iLastGamble[MAXPLAYERS+1];
bool wonHisChances[MAXPLAYERS + 1];
ConVar cvar_min, cvar_max;
public void OnPluginStart()
{
RegConsoleCmd("sm_jackpot", Cmd_Pot);
EngineVersion game = GetEngineVersion();
if(game == Engine_CSGO)
{
HookEvent("round_end", OnRoundEnd, EventHookMode_Post);
}
else if(game == Engine_TF2)
{
HookEvent("teamplay_round_win", OnRoundEnd, EventHookMode_Post);
HookEvent("teamplay_round_stalemate", OnRoundEnd, EventHookMode_Post);
}
else
{
SetFailState("This plugin is only for CSGO/TF2");
}
cvar_min = CreateConVar("sm_jackpot_min", "50", "Min w Jackpocie.", _, true);
cvar_max = CreateConVar("sm_jackpot_max", "10000", "Max w Jackpocie.", _, true, 1.0);
}
public void OnClientDisconnect(int client)
{
if (Gambled[client])
GmbCount--;
Pot -= Gambled[client];
Cases_SetclientBalance(client, Cases_GetClientBalance(client) + Gambled[client]);
Gambled[client] = 0;
chance[client] = 0;
wonHisChances[client] = false;
}
public Action Cmd_Pot(int client, int args)
{
if(!args)
{
if(Pot)
{
CPrintToChat(client, "%s Jest \x03%d\x01 euro w puli.", TAG, Pot);
if(GmbCount)
{
Menu hMenu = CreateMenu(Gamblers);
hMenu.SetTitle(">> Premium Jackpot %d euro w puli:", Pot);
for(int i = 1; i <= MaxClients; i++)
{
if (!IsValidClient(i) || !Gambled[i]) continue;
char bfr[100];
int b = RoundToNearest((Gambled[i] * 100.0) / Pot);
if(i != client)
{
Format(bfr, sizeof(bfr), "%N - Postawilem %d euro (%d%% szansy)", i, Gambled[i], b);
hMenu.AddItem("Sup", bfr);
}
else
{
Format(bfr, sizeof(bfr), "Postawiles %d euro (%d%% szansy)", Gambled[client], b);
hMenu.AddItem("Sup", bfr, ITEMDRAW_DISABLED);
}
}
hMenu.ExitBackButton = true;
hMenu.Display(client, 30);
}
}
else
{
CPrintToChat(client, "%s W puli nie ma euro.", TAG);
}
}
else
{
char arg[8];
GetCmdArg(1, arg, 8);
int credits;
if(!strcmp(arg, "Wszystko", false))
credits = Cases_GetClientBalance(client);
else if(!strcmp(arg, "Polowa", false))
credits = Cases_GetClientBalance(client) / 2;
else
credits = StringToInt(arg);
if (credits < cvar_min.IntValue)
{
CPrintToChat(client, "%s Minimalna kwota do gry to 50 euro.", TAG);
return Plugin_Handled;
}
if (Cases_GetClientBalance(client) < credits)
{
CPrintToChat(client, "%s Nie masz %d euro aby grac na Jackpocie!", TAG, credits);
return Plugin_Handled;
}
if(Gambled[client] + credits > cvar_max.IntValue)
{
CPrintToChat(client, "%s Maxymalna kwota do gry to 10000 euro.", TAG);
return Plugin_Handled;
}
int time = GetTime();
if (!(time - g_iLastGamble[client] < 10))
{
if(!Gambled[client]) GmbCount++;
Gambled[client] += credits;
Pot += credits;
Cases_SetClientBalance(client, Cases_GetClientBalance(client) - credits);
CPrintToChatAll("%s %N postawil %d euro w {darkred}JackPot{default}, powodzenia!", TAG, client, credits);
CPrintToChat(client, "%s INFO: Mozesz zagrac ponownie.", TAG);
g_iLastGamble[client] = GetTime();
}
else
{
CPrintToChat(client, "%s Poczekaj %d aby uzyc komendy ponownie.", TAG, 10 - (time - g_iLastGamble[client]));
}
}
return Plugin_Handled;
}
public int Gamblers(Handle menu, MenuAction action, int client, int param2)
{
if (action == MenuAction_End)
delete menu;
}
public Action OnRoundEnd(Handle hEvent, char[] sName, bool bBroadcast)
{
if(Pot > 0)
{
int random;
bool atLeastOne = false;
for(int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i) && Gambled[i])
{
chance[i] = RoundToNearest((Gambled[i] * 100.0) / Pot);
wonHisChances[i] = (GetRandomInt(1, 100) <= chance[i]);
if(wonHisChances[i])
atLeastOne = true;
}
}
if(atLeastOne)
{
do
random = GetRandomInt(1, MaxClients);
while (!IsValidClient(random) || !wonHisChances[random]);
}
else
{
do
random = GetRandomInt(1, MaxClients);
while (!IsValidClient(random) || !Gambled[random]);
}
PrintCenterTextAll("%N wygrał pulę! (%d euro z Jackpota, mial %d%% szansy)", random, Pot, chance[random]);
CPrintToChatAll("%s \x03%N\x01 wygrał pulę! (\x03%d\x01 euro, \x03%d%%\x01 szansy).", TAG, random, Pot, chance[random]);
Cases_SetClientBalance(random, Cases_GetClientBalance(random) + Pot);
}
for(int i = 1; i <= MaxClients; i++)
{
Gambled[i] = 0;
chance[i] = 0;
wonHisChances[i] = false;
}
Pot = 0;
GmbCount = 0;
return Plugin_Continue;
}
stock bool IsValidClient(client)
{
if (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && IsFakeClient(client) && IsClientSourceTV(client))return true;
return false;
}
Tutaj jest plugin na JackPota jest jeden maly problem
W czasie wpisywania !jackpot i dodanie wartosci np: !jackpot 100 to nam podwaja sume euro...
Jak sie wygra Jackpota to tak samo zamiast dac nam z puli 100 euro daje nam x2 tego co juz mamy.
Pomoze mi ktos to jakos rozwiazac jak dodac aby sprawdzlo ile mamy euro i zeby nam nie dubblowalo przy dawaniu !jackpot <euro>?
// Ten JackPot jest na sklep zephyrsua ale chcialem go przerobic na nasza walute serwera...