Ok, so i made this..
#1

Lottery system..

Well basically, I got problems in these lines:

pawn Код:
LotN = random(ticket1 + random(ticket2));
pawn Код:
if(ticket1 || ticket2 == LotN)
        {
            format(string, sizeof(string), "Congratulations! You have won the lottery of {FFFFFF}$%d.", LotP);
            SendClientMessage(i, -1, string);
            format(string, sizeof(string), "Congratulations to %s! He has won the lottery of $%d!", name, LotP);
            SendClientMessageToAll(-1, string);
            GivePlayerMoney(i, LotP);
        }
The problem with line 1: Well, this system has a /setticket command, wich sets the ticket minimum/maximum ammount, The winning ticket is supposed to be between those two ammounts set on /setticket..

The problem with line 2: I Won the lottery once, BUT, it didn't give me no money. // I think i fixed this.


pawn Код:
new LotN;
new LotP;
new ticket1, ticket2;
new lottopr;
new Lottery[MAX_PLAYERS];


public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}


public OnFilterScriptExit()
{
    return 1;
}

CMD:lotto(playerid, params[])
{
   
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "[{FF0606}ERROR{FFFFFF}]: You have no authorization to use this command.");
    if(sscanf(params, "d", lottopr)) return SendClientMessage(playerid, -1, "{FF9900}/lotto {FFFFFF}<prize>");
    if(lottopr < 10000 || lottopr > 5000000) return SendClientMessage(playerid, -1, "Invalid prize number. Prize must be between $10,000 and $5,000,000.");
    if(LotN != 0) return SendClientMessage(playerid, -1, "There is a lottery already going on.");
    else
    {
        new string[256];
        SendClientMessage(playerid, -1, " "); SendClientMessageToAll(COLOR_ORANGE, "A new lottery has begun use {FFFFFF}/ticket {FF9900}[ number ] to buy a ticket!");
        format(string, sizeof(string), "Ticket numbers: {FFFFFF}[%d - %d]", ticket1, ticket2);
        SendClientMessageToAll(COLOR_ORANGE, string);
        format(string, sizeof(string), "Lottery Prize: $%d", lottopr);
        SendClientMessage(playerid, COLOR_ORANGE, string);
        SendClientMessage(playerid, -1, " ");
        LotN = random(ticket1 + random(ticket2));
        LotP = lottopr;
        SetTimer("Lotteria", 15000, false);
    }
    return 1;
}

CMD:setticket(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "[{FF0606}ERROR{FFFFFF}]: You have no authorization to use this command.");
    new string[256];
    if(sscanf(params, "dd", ticket1, ticket2)) return SendClientMessage(playerid, -1, " {FFFFFF} Usage: {FF9900} /setticket [Minimum - Maximum] ");
    format(string, sizeof(string), "You have set the minimum amount of a ticket {FFFFFF}to: %d {FF9900} and the maximum {FFFFFF}to: %d", ticket1, ticket2);
    SendClientMessage(playerid, COLOR_ORANGE , string);
    SendClientMessage(playerid, -1, "Remember you setted this to start a new lottery, not to just spam commands..");
    return 1;
}

CMD:ticket(playerid, params[])
{
    new string[256], number;
    if(LotN == 0) return SendClientMessage(playerid, -1, "There is no lottery going on.");
   
    if(sscanf(params, "d", number)) return SendClientMessage(playerid, -1, " {FF9900}/ticket {FFFFFF}<number>");
    if(number < ticket1 || number > ticket2)
    {
        format(string, sizeof(string), "Invalid ticket, ticket must be between %d and %d", ticket1, ticket2);
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        format(string, sizeof(string), "You picked number %d for the lottery wich costs $100.", number);
        SendClientMessage(playerid, -1, string);
        Lottery[playerid] = number;
        GivePlayerMoney(playerid, -100);
    }
    return 1;
}

forward Lotteria(playerid);
public Lotteria(playerid)
{
    new name[MAX_PLAYER_NAME], string[256];
    format(string, sizeof(string), "The lottery winning number is %d!",LotN);
    SendClientMessageToAll(COLOR_ORANGE, string);
    foreach(Player, i)
    {
        GetPlayerName(i, name, sizeof(name));
        if(ticket1 || ticket2 == LotN)
        {
            format(string, sizeof(string), "Congratulations! You have won the lottery of {FFFFFF}$%d.", LotP);
            SendClientMessage(i, -1, string);
            format(string, sizeof(string), "Congratulations to %s! He has won the lottery of $%d!", name, LotP);
            SendClientMessageToAll(-1, string);
            GivePlayerMoney(i, LotP);
        }
        else SendClientMessage(i, -1, "You haven't win the lottery! Better luck next time.");
    }
    foreach(Player, i)
    {
        Lottery[i] = 0;
        }
            LotN = 0;
            LotP = 0;
            Lottery[playerid] = 0;
            return 1;
}
Reply
#2

So what you're saying is, with line 1, the code doesn't pick the right number or is there another problem?

That's not the right formula to choose a random number between min and mix.
It should be:
pawn Код:
random(max - min) + min;
Reply
#3

Aha, thanks +rep
Reply
#4

I got another problem, "Sorry for double posting but nobody would read it"

pawn Код:
format(string, sizeof(string), "The lottery winning number is %i!", LotN);
This format is showing the wrong winning number

I've tried ( ticket1 || ticket2) but it doesn't work..
Reply
#5

pawn Код:
#include <a_samp>
#include <zcmd>
#include <foreach>
#include <sscanf2>

#define DEFAULT_TICKET_NUMBER_1         (4)
#define DEFAULT_TICKET_NUMBER_2         (10)

#define COLOR_ORANGE                    (-1)


new bool:bLotteryStarted; // boolean
new iTicketNumbers[ 2 ]; // 2 ticket numbers (global)
new iFinalTicket;
new iLotteryPrize;

new iLotteryPicked[ MAX_PLAYERS ]; // for player to save his lotto number


forward LottoWin( );

public OnFilterScriptInit()
{
    ResetLottoVars( );

    return 1;
}

public OnFilterScriptExit()
{
    ResetLottoVars( );
   
    return 1;
}

ResetLottoVars( )
{
    bLotteryStarted = false;
    iTicketNumbers[ 0 ] = DEFAULT_TICKET_NUMBER_1;
    iTicketNumbers[ 1 ] = DEFAULT_TICKET_NUMBER_2;
    iLotteryPrize = 0;
    iFinalTicket = 0;
   
    foreach( Player, i )
    {
        iLotteryPicked[ i ] = 0;
    }
   
    return 1;
}

stock rand( min, max )
{
    return random( max - min ) + min;
}

CMD:lotto( playerid, params[ ] )
{

    if( !IsPlayerAdmin( playerid ) ) return 0; // or just use SendClientMessage (return 0 will show "Server: Unknown CMD")

    new iPrize;
    if( sscanf( params, "d", iPrize ) ) return SendClientMessage( playerid, -1, "Usage: /lotto [prize]" );
   
    if( iPrize < 10000 || iPrize > 5000000 ) return SendClientMessage( playerid, -1, "Prize must be between $10,000 and $5,000,000");
   
    if( bLotteryStarted ) return SendClientMessage( playerid, -1, "The lottery is already going on." );
   
    new szStr[ 100 ];
   
    SendClientMessageToAll( -1, "" );
    SendClientMessageToAll( COLOR_ORANGE, "A new lottery has begun use {FFFFFF}/ticket {FF9900}[ number ] to buy a ticket!" );
   
    format( szStr, sizeof( szStr ), "Ticket Numbers: {FFFFFF}%d to %d.", iTicketNumbers[ 0 ], iTicketNumbers[ 1 ] );
    SendClientMessageToAll( -1, szStr );
   
    format( szStr, sizeof( szStr ), "Lottery Prize: {FFFFFF}$%d.", iLotteryPrize );
    SendClientMessageToAll( -1, szStr );
   
    iFinalTicket = rand( iTicketNumbers[ 0 ], iTicketNumbers[ 1 ] );
    iLotteryPrize = iPrize;
   
    bLotteryStarted = true;
   
    SetTimer( "LottoWin", 15000, false );
   
    return 1;
}

CMD:setticket( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return 0;
    new ticket[ 2 ], szStr[ 60 ];
    if( sscanf( params, "dd", ticket[ 0 ], ticket[ 1 ] ) ) return SendClientMessage( playerid, -1, "Usage: /setticket [1] [2]" );

    iTicketNumbers[ 0 ] = ticket[ 0 ];
    iTicketNumbers[ 1 ] = ticket[ 1 ];

    format( szStr, sizeof( szStr ), "Lotto: You have set the ticket numbers from %d to %d.", iTicketNumbers[ 0 ], iTicketNumbers[ 1 ] );
    SendClientMessage( playerid, -1, szStr );
   
    SendClientMessage( playerid, -1, "Remember you have set this for the next lottery." );

    return 1;
}

CMD:ticket( playerid, params[ ] )
{
    if( !bLotteryStarted ) return SendClientMessage( playerid, -1, "Lotto: There is no lottery going on." );

    new number, szStr[ 60 ];

    if( sscanf( params, "d", number ) ) return SendClientMessage( playerid, -1, "Usage: /ticket [number]" );

    if( number < iTicketNumbers[ 0 ] || number > iTicketNumbers[ 1 ] )
    {
        format( szStr, sizeof( szStr ), "Invalid Ticket: Ticket must be from: %d to %d.", iTicketNumbers[ 0 ], iTicketNumbers[ 1 ] );
        SendClientMessage( playerid, -1, szStr );
    }
    else
    {
        format( szStr, sizeof( szStr ), "Lotto: You picked %d ticket number for the lotter which costs $100.", number );
        SendClientMessage( playerid, -1, szStr );
       
        iLotteryPicked[ playerid ] = number;
       
        GivePlayerMoney( playerid, GetPlayerMoney( playerid ) - 100 );
       
    }
    return 1;
}



public LottoWin( )
{
    new szStr[ 90 ], count;
    foreach( Player, i ) // just loop once
    {
        format( szStr, sizeof( szStr ), "The Lottery ticket number was %d", iFinalTicket );
        SendClientMessage( i, -1, szStr );
       
        if( iLotteryPicked[ i ] == iFinalTicket ) // success
        {
            count++;
           
            new szName[ MAX_PLAYER_NAME ];
            GetPlayerName( i, szName, sizeof( szName ) );
           
            GivePlayerMoney( i, iLotteryPrize );
           
            format( szStr, sizeof( szStr ), "Lotto: %s has won the lottery of $%d. (Congratulations)", szName, iLotteryPrize );
            SendClientMessageToAll( -1, szStr );
        }
        else // fail
        {
            if( iLotteryPicked[ i ] != 0 ) // those who have picked the lottery ticket
            {
                format( szStr, sizeof( szStr ), "Lotto: You didn't win the lottery of $%d, better luck next time.", iLotteryPrize );
                SendClientMessage( i, -1, szStr );
            }
        }
    }
   
    if( !count )
    {
        format( szStr, sizeof( szStr ), "Lotto: No one won the lottery of $%d.", iLotteryPrize );
    }
    else
    {
        format( szStr, sizeof( szStr ), "Lotto: %d player(s) won the lottery of $%d.", count, iLotteryPrize );
    }
   
    SendClientMessageToAll( -1, szStr );

    ResetLottoVars( ); // reseting all the vars of the players and lottery
}

This might help you. I wrote it a minute ago. Let me know if you have some issues. (not tested)

Regards FalconX
Reply
#6

Quote:
Originally Posted by Strier
Посмотреть сообщение
I got another problem, "Sorry for double posting but nobody would read it"

pawn Код:
format(string, sizeof(string), "The lottery winning number is %i!", LotN);
This format is showing the wrong winning number

I've tried ( ticket1 || ticket2) but it doesn't work..
You still haven't changed this line to work with the new formula.
pawn Код:
LotN = random(ticket1 + random(ticket2));
It really should be
pawn Код:
LotN = random(ticket1 r - ticket2) + ticket2;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)