MySQL License Plate
#1

Hi!
I want to make a License Plate system witch uses MySQL and when the car is created it generates random 3 character and 3 number (like ABC-123) when the car is made. How can I generate random 3 character and 3 number and how can I save it?
Reply
#2

random is the random function.

random(999) will return 0-999, random(100-999) will return 100-999 to keep the 3 numbers.

You'll want to be reading up on how to script, and how to use the MySQL plugin, with a database, to save these.


You will probably have a tricky situation trying to get 3 letters.

You could use random(26) and use that 3 times to get 3 different letters from those random numbers.


When merging the plate, bare in mind that you need them to be a string, so you'll likely use strcat to first make the 3 letter prefix, then have the 3 numbers after.
Reply
#3

You can do this easly with ascii:

We have 26 Letters..and 65 = A

So:

PHP код:
new random(26)+65//So a will be sth between A - Z
//If you want to have also a-z you do:
if(!random(2))
{
    
|= 32//This makes from an A n a or Z to z
}
//So u do this 3 times...
new random(26)+65,brandom(26)+65,crandom(26)+65,z1=random(10),z2=random(10),z3=random(10);
new 
string[16];
format(string,sizeof(string),"%c%c%c-%d%d%d",a,b,c,z1,z2,z3);
//In string is your number plate
//and its just a normal string add it to your vehicle save database and just save it as string and load it as string :D 
Hope could help you
Reply
#4

^^ That is a better method of making the plate (It also makes the whole thing more random by doing each number rather than the number as one), but also, when you do set those plates, you HAVE to set the vehicle to respawn due to it not showing unless you do.

SetVehicleToRespawn after you SetVehicleNumberPlate
Reply
#5

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
random(999) will return 0-999, random(100-999) will return 100-999 to keep the 3 numbers.
False.
random(999) will return numbers from 0 to 998.
If you need values from 0 to 999 you need random(1000).
Reply
#6

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
False.
random(999) will return numbers from 0 to 998.
If you need values from 0 to 999 you need random(1000).
Regardless, I wasn't here to paste out code for people to copy. I was here saying about what functions to use, and what to look at...
Reply
#7

Quote:
Originally Posted by Sew_Sumi
Regardless, I wasn't here to paste out code for people to copy. I was here saying about what functions to use, and what to look at...
I get that, but that doesn't mean a correction wasn't necessary.
If I would make a mistake (by accident or not), I would want to be corrected, since spreading false information is disadvantageous for someone in one way or another.

I didn't reply because I thought "Oh am I going to embarrass that guy, because he made an error".
No, I replied because there are still inexperienced coders on these forums who could read your reply (+ don't look up the wiki page) and don't know that there will be an of-by-one-error.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)