All pastes #339989 Raw Edit

Lottery (untested)

public cpp v1 · immutable
·published 2007-02-04 13:54 UTC
rendered paste body
#include <a_samp>new PlayerTickets[MAX_PLAYERS][6];new PlayerMatchs[MAX_PLAYERS];new bool:PlayerIn[MAX_PLAYERS];forward LotteryStart();#define LOTTERY_INTERVAL 60 // 60 seconds#define TICKET_PRICE 100 // $100public OnGameModeInit(){    SetTimer("LotteryStart", LOTTERY_INTERVAL*1000, 1);}public LotteryStart(){	new rand1, rand2, rand3, rand4, rand5, rand6;	rand1 = random(49);	rand2 = random(49);	rand3 = random(49);	rand4 = random(49);	rand5 = random(49);	rand6 = random(49);	new string[256];	format(string, sizeof(string), "Lottery numbers: %d, %d, %d, %d, %d, %d", rand1, rand2, rand3, rand4, rand5, rand6);	SendClientMessageToAll(0xFFFFFFAA, string);	for(new i = 0; i < MAX_PLAYERS; i++)	{	    if(IsPlayerConnected(i) && PlayerIn[i])	    {			for(new j = 0; j < 6; j++)			{			    if(PlayerTickets[i][j] == rand1 || PlayerTickets[i][j] == rand2 || PlayerTickets[i][j] == rand3 || PlayerTickets[i][j] == rand4 || PlayerTickets[i][j] == rand5 || PlayerTickets[i][j] == rand6)			    {			        PlayerMatchs[i]++;			    }			    PlayerTickets[i][j]=0;			}			PlayerIn[i]=false;			if(PlayerMatchs[i] > 0)			{			    format(string, sizeof(string), "You got %d numbers correct! You win $%d", PlayerMatchs[i], PlayerMatchs[i]*100);			    SendClientMessage(i, 0xFFFFFFAA, string);			    GivePlayerMoney(i,PlayerMatchs[i]*100);			    PlayerMatchs[i]=0;			}	    }	}}public OnPlayerConnect(playerid){	for(new i = 0; i < 6; i++)	{	    PlayerTickets[playerid][i]=0;	}	PlayerIn[playerid]=false;	PlayerMatchs[playerid]=0;}public OnPlayerCommandText(playerid, cmdtext[]){	new cmd[256];	new idx;	cmd = strtok(cmdtext, idx);	if(strcmp(cmd, "/buyticket", true) == 0) {	    new no1[256], no2[256], no3[256], no4[256], no5[256], no6[256];		no1 = strtok(cmdtext, idx);		no2 = strtok(cmdtext, idx);		no3 = strtok(cmdtext, idx);		no4 = strtok(cmdtext, idx);		no5 = strtok(cmdtext, idx);		no6 = strtok(cmdtext, idx);				if(!strlen(no1) || !strlen(no2) || !strlen(no3) || !strlen(no4) || !strlen(no5) || !strlen(no6))		{			return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /buyticket [1] [2] [3] [4] [5] [6]");		}		if(GetPlayerMoney(playerid) >= TICKET_PRICE)		{		    GivePlayerMoney(playerid, -1*TICKET_PRICE);		    PlayerIn[playerid]=true;		    PlayerTickets[playerid][0]=strval(no1);		    PlayerTickets[playerid][1]=strval(no2);		    PlayerTickets[playerid][2]=strval(no3);		    PlayerTickets[playerid][3]=strval(no4);		    PlayerTickets[playerid][4]=strval(no5);		    PlayerTickets[playerid][5]=strval(no6);		    new string[256];		    format(string, sizeof(string), "Your lottery ticket numbers: %d, %d, %d, %d, %d, %d", strval(no1), strval(no2), strval(no3), strval(no4), strval(no5), strval(no6));            return SendClientMessage(playerid, 0xFFFFFFAA, string);		} else {		    new string[256];		    format(string, sizeof(string), "Not enough money! Lottery tickets cost %d", TICKET_PRICE);            return SendClientMessage(playerid, 0xFFFFFFAA, string);		}		return 1;	}	return false;}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;}