View Full Version : Vehicle Plate Generation problem

30/07/2017, 01:48 AM

I've been trying for 5 hours to summon a function that can regenerate a license plate.

For example: AAA-001, AAA-002 and nice line.
In MySQL, store the last license number to decide what to do next.

I say getnewplate command and server drop me this: "AAA-003", next "AAA-004", and work all

AAA-009 next AAA-010

Unfortunately I did not have too much success, but I could replace one character. : 'D

I hope someone can help me.

Thank you in advance for your response.

30/07/2017, 02:17 AM
Here's how I do it in my script by going off California license plates:

At the top of your script, place this. It'll generate characters from A-Z.

new possiblePlates[][] = {"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"};

Inside the command / function you have:

It's pretty self explanatory.

new rand[3], carPlates[32];

rand[0] = random(sizeof(possiblePlates));
rand[1] = random(sizeof(possiblePlates));
rand[2] = random(sizeof(possiblePlates));

format(carPlate, sizeof(carPlate), "%d%s%s%s%d%d%d", random(9), possiblePlates[rand[0]], possiblePlates[rand[1]], possiblePlates[rand[2]], random(9), random(9), random(9));

Just remember there's a limit of 32 characters on each number plate (including embedded colors).

This is just an example.

30/07/2017, 02:21 AM
Arthur's code generates random plates everytime, and its more recommended.

But if you want it to be like AAA_000 next AAA_001 ect.. then here is a simple try

new LastPlate;
stock GetNewPlate()
new str[7];
if(LastPlate<10) format(str, sizeof(str), "AAA_00%d", LastPlate);
else if(LastPlate>9 && LastPlate<100) format(str, sizeof(str), "AAA_0%d", LastPlate);
else if(LastPlate>99 && LastPlate<1000) format(str, sizeof(str), "AAA_%d", LastPlate);
return str;

30/07/2017, 02:51 AM
@Shinja - read up on format syntax, you can add leading zeroes much more easily:
new LastPlate;
stock GetNewPlate()
new str[7];
format(str, sizeof(str), "AAA_%03d", LastPlate);
return str;

30/07/2017, 07:11 PM