[Done] Vehicle Plate Generation problem -
TeddHUN - 30.07.2017
Hello!
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.
Re: Vehicle Plate Generation problem -
Kane - 30.07.2017
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.
PHP код:
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.
PHP код:
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.
Re: Vehicle Plate Generation problem -
Shinja - 30.07.2017
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
PHP код:
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);
LastPlate++;
return str;
}
Re: Vehicle Plate Generation problem -
Misiur - 30.07.2017
@Shinja - read up on format syntax, you can add leading zeroes much more easily:
pawn Код:
new LastPlate;
stock GetNewPlate()
{
new str[7];
format(str, sizeof(str), "AAA_%03d", LastPlate);
LastPlate++;
return str;
}
Re: Vehicle Plate Generation problem -
TeddHUN - 30.07.2017
Thanks!