#1

I made a command and I used if/else statements but I changed my mind and I wanted to convert it to cases.
So I switch the money but while I was compiling I noticed that the compiler stopped response.
Did I do anything wrong.
pawn Код:
// If/Else Statements:
if( money == 200000 )
{
    // Code
}
else if( money > 200000 && money < 400000 )
{
    // Code
}
// More with if statements..
// The last statement
else
{
    // Code
}
// ==========
// After converting..
// Cases:
    switch( money )
    {
        case 200000: SetPlayerWantedLevel( id, 1 );
        case 200001 .. 399999: SetPlayerWantedLevel( id, 2 );
        case 400001 .. 799999: SetPlayerWantedLevel( id, 3 );
        case 800001 .. 1599999: SetPlayerWantedLevel( id, 4 );
        case 1600001 .. 3199999: SetPlayerWantedLevel( id, 5 );
        default: SetPlayerWantedLevel( id, 6 );
    }
Reply
#2

I didn't notice anything but I thought i'd point out

pawn Код:
case 200001 .. 399999: SetPlayerWantedLevel( id, 2 );
case 400001 .. 799999: SetPlayerWantedLevel( id, 3 ); //puts a hole in here making 400000 set their wanted level to 6 as 6 = default


case 200001 .. 399999: SetPlayerWantedLevel( id, 2 );
case 400000 .. 799999: SetPlayerWantedLevel( id, 3 );
Reply
#3

Does default means that money is non of the above money on cases, right?
Can you explain what do you mean Antonio, I want 6 Wanted levels. and for more 3,2M the Wanted Level should be 6 = default.
Reply
#4

It means that if the player has exactly $400000 then it is neither 399999 nor 400001, thus reverting to the default case.
Reply
#5

if the money AND wantedlevel amounts raise up linear, you can divide the money amount by a static value to get the wantedlevel - but for your non linear raising wanteds, i suggest to use an array, using the money/100000 as pointer to its cell:
pawn Код:
new MoneyThruHundretKRobToWanted[]={0,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6};
pawn Код:
if( money => 100000 )//this avoids cell 0 being used, its level 0 anyways...
{
    SetPlayerWantedLevel( id, MoneyThruHundretKRobToWanted[money/100000] );
}
if the money/100000 exceeds the array size, you need to script an exception, i doubt that anyone will rob 3.2m
Reply
#6

The compiler doesn't response everytime I use case num1 .. num2:.
Anyway, I will change it to if/else statements, because someone ( if he is rich ) can bounty someone else with 5 billions too.
Too sad I coun't make it with cases, it would be 10 lines smaller.
Thanks for the comments!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)