Код:
#include <a_samp>
#include <dini>
//--------|| Here you can easy change this ||--------//
#define LottoTime 1 //(number of minutes)
#define LottoPrice 500
#define MAX_NUMBERS 200
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_ERROR 0x9ACD32AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_DBLUE 0x375FFFFF
#define COLOR_YELLOW 0xFFFF00AA
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
forward Lotto(number);
forward LoadJackpot();
forward SaveJackpot();
new Jackpot;
new Timer;
new pLottoNumber[MAX_PLAYERS];
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Lottery System V 1.0 By Zero_Cool ");
print("--------------------------------------\n");
Timer = SetTimer("LottoShow", 1000*(LottoTime*60), 1);
if(!fexist("Jackpot.ini"))
{
dini_Create("Jackpot.ini");
dini_IntSet("Jackpot.ini","Jackpot",10000);
return 1;
}
else
{
LoadJackpot();
}
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
pLottoNumber[playerid] = 0;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
pLottoNumber[playerid] = 0;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(lotto,5,cmdtext);
dcmd(setjackpot,10,cmdtext);
return 0;
}
dcmd_setjackpot(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
new tmp[256], idx;
tmp = strtok(params, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE,"USAGE: /setjackpot [amount]");
return 1;
}
new amount = strval(tmp);
Jackpot = amount;
SaveJackpot();
return 1;
}
return 1;
}
dcmd_lotto(playerid,params[])
{
new tmp[256], idx;
new string[256];
tmp = strtok(params, idx);
if(IsPlayerConnected(playerid))
{
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE,"USAGE: /lotto [number]");
return 1;
}
if(pLottoNumber[playerid] > 0)
{
SendClientMessage(playerid,COLOR_WHITE,"You already have a Lottery Ticket");
return 1;
}
if(GetPlayerMoney(playerid) < LottoPrice)
{
format(string,sizeof(string),"You need $%d for a Lottery Ticket !",LottoPrice);
SendClientMessage(playerid,-1, "You need {FF0000}$500{FFFFFF} for a Lottery Ticket !");
return 1;
}
new lottonr = strval(tmp);
for(new i;i<MAX_PLAYERS;i++)
{
if(pLottoNumber[playerid] == lottonr) return SendClientMessage(playerid, COLOR_ERROR,"That Number Already Used!");
}
if(lottonr < 1 || lottonr > MAX_NUMBERS) {format(string, sizeof(string), "Lottery Number not below 1 or above %d !",MAX_NUMBERS); SendClientMessage(playerid, COLOR_GREY,string); return 1; }
format(string, sizeof(string), "You bought a Lottery Ticket with number:{FF0000} %d{FFFFFF},Current Jackpot:{FF0000} %d", lottonr,Jackpot);
SendClientMessage(playerid, COLOR_WHITE, string);
GivePlayerMoney(playerid, - LottoPrice);
pLottoNumber[playerid] = lottonr;
}
return 1;
}
public Lotto(number)
{
new string[256];
new winner[MAX_PLAYER_NAME];
format(string, sizeof(string), "{FF0000}Lottery News:{FFFFFF} Today the Winning Number has fallen on: %d.", number);
SendClientMessageToAll(COLOR_WHITE, string);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(pLottoNumber[i] > 0)
{
if(pLottoNumber[i] == number)
{
GetPlayerName(i, winner, sizeof(winner));
GivePlayerMoney(i, Jackpot);
format(string, sizeof(string), "{FF0000}Lottery{FFFFFF} News: %s has won the Jackpot of $%d with his/her Lottery Ticket.", winner, Jackpot);
SendClientMessageToAll(COLOR_DBLUE, string);
format(string, sizeof(string), "*You have Won $%d with your Lottery Ticket.", Jackpot);
SendClientMessage(i, COLOR_YELLOW, string);
format(string,256,"~w~You have Won ~g~$%d",Jackpot);
GameTextForPlayer(i,string,10000,4);
}
else
{
SendClientMessage(i, COLOR_WHITE, "* You haven't won with your Lottery Ticket this time.");
}
}
pLottoNumber[i] = 0;
}
}
new rand = randomEx(1000,200000);
Jackpot += rand;
SaveJackpot();
format(string, sizeof(string), "{FF0000}Lottery News:{FFFFFF} The Jackpot has been raised to $%d.", Jackpot);
SendClientMessageToAll(COLOR_DBLUE, string);
return 1;
}
new time;
forward LottoShow();
public LottoShow()
{
new str[256];
format(str,256,"~g~/Lotto (1 - %d)~n~~g~Jackpot %d",MAX_NUMBERS,Jackpot);
GameTextForAll(str,10000,3);
KillTimer(Timer);
time = SetTimer("LottoWiner",15000,1);
return 1;
}
forward LottoWiner();
public LottoWiner()
{
new string[256];
KillTimer(time);
format(string, sizeof(string),"{FF0000}Lottery News:{FFFFFF} Lottery Election Started.");
SendClientMessageToAll(COLOR_DBLUE, string);
new rand = randomEx(1,MAX_NUMBERS);
if(rand < MAX_NUMBERS - 3) { rand += 3; }
Timer = SetTimer("LottoShow", 1000*(LottoTime*60), 1);
Lotto(rand);
}
public LoadJackpot()
{
new file[128];
format(file,sizeof(file),"Jackpot.ini");
Jackpot = dini_Int(file,"Jackpot");
return 1;
}
public SaveJackpot()
{
new file[128];
format(file,sizeof(file),"Jackpot.ini");
dini_IntSet(file,"Jackpot",Jackpot);
return 1;
}
//-----------|| By ****** ||---------------||
stock randomEx(minnum = cellmin, maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;
stock strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}