Vehicle Plate Generation problem
#1

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.
Reply
#2

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(carPlatesizeof(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.
Reply
#3

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<10format(strsizeof(str), "AAA_00%d"LastPlate);
    else if(
LastPlate>&& LastPlate<100format(strsizeof(str), "AAA_0%d"LastPlate);
    else if(
LastPlate>99 && LastPlate<1000format(strsizeof(str), "AAA_%d"LastPlate);
    
LastPlate++;
    return 
str;

Reply
#4

@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;
}
Reply
#5

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)