Random vehicle ID -
TayFunCZE - 27.07.2017
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(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, GREEN, string);
return 1;
}
else
{
carID = randomEx(494,536);
format(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, BLUE, string);
return 1;
}
Re: Random vehicle ID -
Jefff - 27.07.2017
it must be
pawn Код:
if(carID != 430 && carID != 435 && carID != 446 && carID != 449 ....
Re: Random vehicle ID -
Paulice - 27.07.2017
Use switch instead.
Re: Random vehicle ID -
IstuntmanI - 27.07.2017
What you did is basically the same as:
PHP код:
new carID=randomEx(400,611), string[96];
if(carID != 430 || 435 != 0 || 446 != 0 || 449 != 0 || 450 != 0 || 452 != 0 || 453 != 0 || 454 != 0 || 460 != 0 || 472 != 0 || 473 != 0 || 484 != 0 || 493 != 0 || 537 != 0 || 538 != 0 || 539 != 0 || 553 != 0 || 569 != 0 || 570 != 0 || 577 != 0 || 584 != 0 || 590 != 0 || 591 != 0 || 592 != 0 || 594 != 0 || 595 != 0 || 606 != 0 || 607 != 0 || 608 != 0 || 610 != 0 || 611)
{
format(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, GREEN, string);
return 1;
}
else
{
carID = randomEx(494,536);
format(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, BLUE, string);
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(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, GREEN, string);
return 1;
}
else
{
carID = randomEx(494,536);
format(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, BLUE, string);
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 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(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, GREEN, string);
return 1;
}
default:
{
carID = randomEx(494,536);
format(string, sizeof(string), "You got vehicle ID: %d!",carID);
SCM(playerid, BLUE, string);
return 1;
}
}
Re: Random vehicle ID -
TayFunCZE - 27.07.2017
Oh, I didn't know that, thank you all for that fast reply, thanks