How would I do this...
#1

How would I make it so if say;
pawn Код:
Player[playerid][Somevarable] += 1;
if(Player[playerid][Somevarable] <= 9)
{
    SendClientMessage(playerid, COLOR_SOMECOLOR, " MESSAGE 2 ");
}
//It'd say that from 1-9
//then at 10 say
else if(Player[playerid][Somevarable] == 10)
{
    SendClientMessage(playerid, COLOR_SOMECOLOR, " SOME DIFFERNT MESSAGE! ");
}
//then at 11-19 say
else if(Player[playerid][Somevarable] <= 19)
{
    SendClientMessage(playerid, COLOR_SOMECOLOR, " SAME AS MESSAGE 1! ");
}
// etc.
I tried it similar to that, but once it reaches 10, 20, 30, etc. It doesn't do Message Two, it does Message 1 still.
Reply
#2

First off, do the following to make sure its incrementing properly.

Player[playerid][Somevarable] = Player[playerid][Somevarable] + 1;

As far as the rest, it looks fine.
Reply
#3

Thanks!
I had it right, I just forgot the +1 after the shortvar = Player[blah][blah]
Reply
#4

pawn Код:
if(var > 0 && var < 10 )
{

}
else ic(var > 10 && var < 20)
{

}
like that you can check multiple things
Reply
#5

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
pawn Код:
if(var > 0 && var < 10 )
{

}
else ic(var > 10 && var < 20)
{

}
like that you can check multiple things
^, not sure if you care about how you do it or not, but I might as well just put it out there. It's faster and a lot cleaner then a ton of if / else if 's.

You could also do

pawn Код:
switch(Player[playerid][Somevarable])
{
    case 1..9:
    {
        //message if the var is inbetween 1 and 9.
    }
    case 10:
    {
        //message if the var = 10
    }
    case 11..19:
    {
        //message if the var is inbetween 11 and 19
    }
}
Reply
#6

Quote:
Originally Posted by Haydz
Посмотреть сообщение
^, not sure if you care about how you do it or not, but I might as well just put it out there. It's faster and a lot cleaner then a ton of if / else if 's.

You could also do

pawn Код:
switch(Player[playerid][Somevarable])
{
    case 1..9:
    {
        //message if the var is inbetween 1 and 9.
    }
    case 10:
    {
        //message if the var = 10
    }
    case 11..19:
    {
        //message if the var is inbetween 11 and 19
    }
}
Yep, that would work aswell. I just got out of bed, so couldnt think of that yet
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)