Creating an Alphanumeric Number plate? (Letters and Numbers.)
#1

Hey fellow scripters,
I am trying to make a number plate system.

First of all, we want three(3) Letters, Space, Hyphen, space and then three(3) numbers.

For example.
ABC - 123
or at least
ABC-123

Then I need to save it to a database, which I think I can manage.

(Yes, I have used search, Yes, I found some results, but no did I find one that was efficient.)
Just looking for a more practical approach to do this.

Cheers,
Deal.
Reply
#2

A more practical approach than what exactly?

Just set the plate and save it, i don't think it gets much better than that.
Reply
#3

A more practical approach than 300 lines of code.

Yes, but it's a number plate, everyone has to be different.
How am I able to make this number plate randomised and then make sure that there isn't going to be duplicates?
Reply
#4

do a loop that check if the new number is the same as any other of the number plates.
Reply
#5

Nevermind -.-
Reply
#6

I created an array of about 20 random groups of 3 letter strings. Then I just created a function to choose one of the random strings of 3 letters, then add three random numbers afterwards then format() it with the hyphen. I have a stock Random() function that lets me specify a minimum and maximum number, so I would do something like this:

pawn Code:
new PlateLetters[24][] = {
"BAP",
"BAN",
"BAM",
"CAN",
"CAM",
"CDL",
"CDW",
"CBA",
"DIJ",
"DNM",
"DQN",
"EGN",
"FUB",
"FIN",
"FQE",
"HAM",
"KNA",
"LBV",
"NAB",
"NAS",
"NSN",
"NSQ",
"QUA",
"KBN"
};
pawn Code:
public SetRandomPlate(vehicleid) {

    new RandomLetterGroup = Random(1,24);

    new number1, number2, number3;
   
    number1 = Random(1,9);
    number2 = Random(1,9);
    number3 = Random(1,9);
   
    new FinalPlate[8]
   
        format(FinalPlate, sizeof(FinalPlate), "%s-%i%i%i", PlateLetters[RandomLetterGroup], number1, number2, number3);
   
        SetVehicleNumberPlate(vehicleid, FinalPlate);
   
    return 1;
   
}
And here's my stock random function, although this was not written by me:

pawn Code:
stock Random(min, max) return random(max - min+1) + min;
Hopefully this helps. It's untested and a little messy but I think I might be the only one replying that knows what you're trying to do. Now, depending on how you save your data (INI or MySQL) you'll need to make a check to make sure the newly random generated plate is not the same as any other plate in the database before you actually SetVehicleNumberPlate(); That way every one is unique and you have no duplicates. (Though it would be rare)
Reply
#7

pawn Code:
RandomEx(minimum, maximum)
{
    return random(maximum, minimum + 1) + minimum;
}

GenerateRandomPlate()
{
    new randomPlate[10];
    format(randomPlate, sizeof(randomPlate), "%c%c%c-%d%d%d", RandomEx('A', 'z'), RandomEx('A', 'z'), RandomEx('A', 'z'), random(10), random(10), random(10));
    return randomPlate;
}

Untested, may not work. I haven't used %c before in format.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)