SA-MP Forums Archive
How would I do this... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How would I do this... (/showthread.php?tid=315174)



How would I do this... - Lynn - 02.02.2012

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.


Re: How would I do this... - Rokzlive - 02.02.2012

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.


Re: How would I do this... - Lynn - 02.02.2012

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


Re: How would I do this... - Wesley221 - 02.02.2012

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

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

}
like that you can check multiple things


Re: How would I do this... - Haydz - 02.02.2012

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
    }
}



Re: How would I do this... - Wesley221 - 02.02.2012

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