Random vehicle ID
#1

Hello, I'm trying to get a random id of a car, but I don't want these down here, when I use a command for this, I'm getting any random number from 400 to 611, but the SendClientMessage with a blue text never pop up in a chat, only a green message, so I don't even know, if that carID = randomEx(494,536); is called, any reasons?

PHP код:
        new carID=randomEx(400,611), string[96];
        if(
carID != 430||435||446||449||450||452||453||454||460||472||473||484||493||537||538||539||553||569||570||577||584||590||591||592||594||595||606||607||608||610||611)
        {
            
format(stringsizeof(string), "You got vehicle ID: %d!",carID);
            
SCM(playeridGREENstring);
            return 
1;
        }
        else
        {
            
carID randomEx(494,536);
            
format(stringsizeof(string), "You got vehicle ID: %d!",carID);
            
SCM(playeridBLUEstring);
            return 
1;
        } 
Reply
#2

it must be
pawn Код:
if(carID != 430 && carID != 435 && carID != 446 && carID != 449 ....
Reply
#3

Use switch instead.
Reply
#4

What you did is basically the same as:
PHP код:
new carID=randomEx(400,611), string[96]; 
if(
carID != 430 || 435 != || 446 != || 449 != || 450 != || 452 != || 453 != || 454 != || 460 != || 472 != || 473 != || 484 != || 493 != || 537 != || 538 != || 539 != || 553 != || 569 != || 570 != || 577 != || 584 != || 590 != || 591 != || 592 != || 594 != || 595 != || 606 != || 607 != || 608 != || 610 != || 611

    
format(stringsizeof(string), "You got vehicle ID: %d!",carID); 
    
SCM(playeridGREENstring); 
    return 
1

else 

    
carID randomEx(494,536); 
    
format(stringsizeof(string), "You got vehicle ID: %d!",carID); 
    
SCM(playeridBLUEstring); 
    return 
1

Because 435 is indeed different than 0 the whole check will stop at that second check and it will execute the code in the first pair of brackets, because that check is always true. What you need to do is this:
PHP код:
new carID=randomEx(400,611), string[96];
if(
carID != 430 || carID != 435 || carID != 446 || carID != 449 || carID != 450 || carID != 452 || carID != 453 || carID != 454 || carID != 460 || carID != 472 || carID != 473 || carID != 484 || carID != 493 || carID != 537 || carID != 538 || carID != 539 || carID != 553 || carID != 569 || carID != 570 || carID != 577 || carID != 584 || carID != 590 || carID != 591 || carID != 592 || carID != 594 || carID != 595 || carID != 606 || carID != 607 || carID != 608 || carID != 610 || carID != 611)
{
    
format(stringsizeof(string), "You got vehicle ID: %d!",carID);
    
SCM(playeridGREENstring);
    return 
1;
}
else
{
    
carID randomEx(494,536);
    
format(stringsizeof(string), "You got vehicle ID: %d!",carID);
    
SCM(playeridBLUEstring);
    return 
1;

This is way better, switch is way faster when having to check that many values, it is also what you tried to do in the first place:
PHP код:
new carID=randomEx(400,611), string[32];
switch(
carID)
{
    case 
430435446449450452453454460472473484493537538539553569570577584590591592594595606607608610611:
    {
        
format(stringsizeof(string), "You got vehicle ID: %d!",carID);
        
SCM(playeridGREENstring);
        return 
1;
    }
    default:
    {
        
carID randomEx(494,536);
        
format(stringsizeof(string), "You got vehicle ID: %d!",carID);
        
SCM(playeridBLUEstring);
        return 
1;
    }

Reply
#5

Oh, I didn't know that, thank you all for that fast reply, thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)