Help Number Plate (+REP)
#1

Hello. I have a question. How can i set random number to SetVehicleNumberPlate?

I have like this

Код:
SetVehicleNumberPlate(p,"LV-2541")
But i want the numbers after LV- to be randomaized, because every vehicle has the same numbers. Is it possible? If yes, please tell me how.

Thanks.
P.S Sorry for my bad English.

+REP To everyone who helped.
Reply
#2

Ex:
pawn Код:
new VBString[10];
format(VBString, 10, "LV-%d",1000+random(9000));
SetVehicleNumberPlate(p,VBString);
Reply
#3

Код:
public OnVehicleSpawn(vehicleid)
{
new str[32]; format(str, sizeof str, ''LV-%i", vehicleid);
SetVehicleNumberPlate(vehicleid, str);
SetVehicleToRespawn(vehicleid);
return 1;
}
Reply
#4

Quote:
Originally Posted by ViniBorn
Посмотреть сообщение
Ex:
pawn Код:
new VBString[10];
format(VBString, 10, "LV-%d",1000+random(9000));
SetVehicleNumberPlate(p,VBString);
Done. Thanks
Reply
#5

Quote:
Originally Posted by ViniBorn
Посмотреть сообщение
Ex:
pawn Код:
new VBString[10];
format(VBString, 10, "LV-%d",1000+random(9000));
SetVehicleNumberPlate(p,VBString);
BTW, have a question, can i do the same with letters?
Reply
#6

Of course, set an array with random letters.
Reply
#7

Код:
new LetterList[26][] =
{
    "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", 
    "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
}; 

stock SetVehicleRandomNumberPlate(vehicleid)
{
    new string[10];
    format(string, sizeof(string), "%s%s%s%s %d%d%d", LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], random(10), random(10), random(10));
    SetVehicleNumberPlate(vehicleid, string);
    return 1;
}
Link to thread where I found this code:
https://sampforum.blast.hk/showthread.php?tid=308961
Reply
#8

Quote:
Originally Posted by Blademaster680
Посмотреть сообщение
Код:
new LetterList[26][] =
{
    "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", 
    "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
}; 

stock SetVehicleRandomNumberPlate(vehicleid)
{
    new string[10];
    format(string, sizeof(string), "%s%s%s%s %d%d%d", LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], random(10), random(10), random(10));
    SetVehicleNumberPlate(vehicleid, string);
    return 1;
}
Link to thread where I found this code:
https://sampforum.blast.hk/showthread.php?tid=308961
Ok, thank you very much for help. I'll give you +rep tomorrow, i can't give anymore today. ;/
Reply
#9

No problem
Reply
#10

Use %c instead of %s for characters.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)