random
#1

debug = random( 12 );

format(string, 92, "%s press the button and it show number %d.", GetPlayerNameEx(playerid),debug);

I wanna that it would be if numbers 1,2,3,4,5 it shows that "%s press the button and it show number %d which color is %s ."


but if numbers is 6,7,8,9,10,11,12 it shows that color is black, how to set value to random number?
Reply
#2

You could use a switch. Also note that random(12) will generate a random number from 0 to 11. Not 1 to 12. If that's what you want, you should use: debug = random(12)+1;

pawn Код:
new debug = random(12);
switch(debug)
{
    case 0..4:
    {
        //Do whatever you want
    }
    case 5..11:
    {
        //Color black
    }
}
Reply
#3

Using a switch is an easy way to detect that.
pawn Код:
new debug = random(12);
switch(random(12))
{
    case 0...5: format(string, 92, "%s press the button and it show number %d, which color is %s.", GetPlayerNameEx(playerid), debug);
    case 6...12: format(string, 92, "%s press the button and it show number %d, which is black.", GetPlayerNameEx(playerid), debug);
}
Reply
#4

Oh, thanks very much bouth of you guys!
Reply
#5

pawn Код:
new string[ 120 ],
        rspin = random( 36 ) +1;
       
    switch(random( 36 ) +1)
{
    case 1, 3, 5, 7, 9, 12, 14, 16, 18, 21, 23, 25, 27, 28, 30, 32, 34, 36: format(string, 120, "{8d97f4}* %s spins and stops at %d color  is {c12121}red{ffffff}.", GetPlayerNameEx(playerid),rspin);
    case 2, 4, 6, 8, 10, 11, 13, 15, 17, 19, 20, 22, 24, 26, 29, 31, 33, 35: format(string, 120, "{8d97f4}* %s spins and stops at %d color is {222222}black{ffffff}.", GetPlayerNameEx(playerid),rspin);
    ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
}
error 002: only a single statement (or expression) can follow each "case"
warning 215: expression has no effect
warning 209: function "cmd_spin" should return a value
error 010: invalid function or declaration
Reply
#6

You need to finish the switch before using other functions.
pawn Код:
new string[ 120 ],
        rspin = random( 36 ) +1;
       
switch(random( 36 ) +1)
{
    case 1, 3, 5, 7, 9, 12, 14, 16, 18, 21, 23, 25, 27, 28, 30, 32, 34, 36: format(string, 120, "{8d97f4}* %s spins and stops at %d color  is {c12121}red{ffffff}.", GetPlayerNameEx(playerid),rspin);
    case 2, 4, 6, 8, 10, 11, 13, 15, 17, 19, 20, 22, 24, 26, 29, 31, 33, 35: format(string, 120, "{8d97f4}* %s spins and stops at %d color is {222222}black{ffffff}.", GetPlayerNameEx(playerid),rspin);
}
ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
Quote:

warning 209: function "cmd_spin" should return a value

You need to use "return 1;" at the end of your command.
Example using zcmd:
pawn Код:
CMD:whatever(playerid, params[])
{
    // Codes
    return 1;
}
Reply
#7

thanks i make

pawn Код:
CMD:spin( playerid, params[ ] )
{
    #pragma unused params
    //if ( !PlayerHasItemInInv( playerid, ITEM_RULETE ) )
       // return SendClientMessage( playerid, GRAD, "{FF6347}Perspлjimas: Jыs neturite loрimo ruletлs" );
       
    new string[ 120 ],
        rspin = random( 36 ) +1;
       
    switch(random( 36 ) +1)
{
    case 1, 3, 5, 7, 9, 12, 14, 16, 18, 21, 23, 25, 27, 28, 30, 32, 34, 36: format(string, 120, "{8d97f4}* %s iрsuka ruletж ir kamuoliukas sustoja ant %d spalva {c12121}raudona{ffffff}.", GetPlayerNameEx(playerid),rspin);
    case 2, 4, 6, 8, 10, 11, 13, 15, 17, 19, 20, 22, 24, 26, 29, 31, 33, 35: format(string, 120, "{8d97f4}* %s iрsuka ruletж ir kamuoliukas sustoja ant %d spalva {222222}juoda{ffffff}.", GetPlayerNameEx(playerid),rspin);
}
    ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
    return 1;
}
but it wont work it shows one number "juodas" then "raudonas" it wont set random number?
Reply
#8

fixed.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)