[Tutorial] Vehicle Number Plate (Reg) Generation
#1

VEHICLE NUMBER PLATE
GENERATING SYSTEM

Note: This system does use ZCMD so if you don't have experience using this include, I would not recommend reading this tutorial.


CODE

pawn Code:
enum vDetails
{
    vReg
}

CMD:registration(playerid, params[])
{
    new registration = GenerateRegistration();
    new string[128];
    new vehicleid = GetPlayerVehicleID(playerid);

    //Reg Formatting
    format(string, sizeof(string), "15 LV %d", registration);

    // Setting & Saving the number plate
    SetVehicleNumberPlate(vehicleid, string);
    format(vDetails[playerid][vReg], 64, "%s", string);

    // Confirmation message
    format(string, sizeof(string), "Your license plate was set to {FF9900}%s{AFAFAF}.", string);
    SendClientMessage(playerid, COLOR_GREY, string);
    return 1;
}
pawn Code:
stock GenerateRegistration()
{
    new registration = random(9999);
    foreach(Player, i)
    {
        if(vDetails[i][vReg] == registration || registration < 1000)
        {
            GenerateRegistration();
            return 1;
        }
    }
    return registration;
}
Just copy and paste the above and your done!
I'm joking, then it wouldn't be a tutorial.

SKIP TO "THE ACTUAL GENERATING" IF YOU ARE EXPERIENCED IN SCRIPTING.

EXPLAINING

The code below creates an enum that will store details about the vehicle, in this case the car number plate. We named it vReg for ease of usage. If you want an in-depth tutorial on what enmus are, I suggest you look HERE.
pawn Code:
enum vDetails
{
    vReg
}
This is basic ZCMD Language. It just states that when the command /registration is used, it will do the following.

pawn Code:
CMD:registration(playerid, params[])
{
I'm not going into much detail about the following three variables, mainly because that's not what the tutorial is about and it's fairly basic.

This bit of code uses the stock we will be creating in a minute to generate a random plate for us.
pawn Code:
new registration = GenerateRegistration();
This is just creating a new array to store our string in.
pawn Code:
new string[128];
This just creates a variable to store the vehicle ID in.
pawn Code:
new vehicleid = GetPlayerVehicleID(playerid);
All this code does is, it sets the start of the vehicle plate to 15 LV followed by the number we will generate. The 15 states the year and the LV states the city. You can obviously change the LV to LS or just remove the code if need be.
pawn Code:
//Reg Formatting
format(string, sizeof(string), "15 LV %d", registration);
Next is an important part of the code, it sets the vehicles plate to our generated vehicle plate, aswell as storing the plate into the enum vReg that we made above.

We use the vehicleid in SetVehicleNumberPlate to set the plate of the vehicle you are currently in. If you have a vehicle system in your server and you want to change a specific vehicle plate, you put the vehicleid here. The official samp callback is HERE.

We then use the string we stored our vehicle plate in above to set our plate to it. The string is also used at the end of saving the plate to the enum. If you want more information on formatting, click HERE.

Again, format(PlayerInfo[playerid][vReg], 64, "%s", string) isn't really relative to this tutorial so click THIS link on more information.
pawn Code:
// Setting & Saving the number plate
SetVehicleNumberPlate(vehicleid, string);
format(PlayerInfo[playerid][vReg], 64, "%s", string);
Again, this is just basic coding with strings to send the player a message on what plate was generated for them, use the links above for information on how to do it.
pawn Code:
// Confirmation message
format(string, sizeof(string), "Your license plate was set to {FF9900}%s{AFAFAF}.", string);
SendClientMessage(playerid, COLOR_GREY, string);
THE ACTUAL GENERATING
pawn Code:
stock GenerateRegistration() //states the name of the stock
{
    new registration = random(9999); //Generates a number out of 9999
    foreach(Player, i) //Searches every user in the server checking if the vehicle plate is used.
    {
        if(PlayerInfo[i][vReg] == registration || registration < 1000) // Checks if the reg is in use or if its below 1000.
        {
            GenerateRegistration(); //Regenerates a reg if the criteria is not met
            return 1;
        }
    }
    return registration; //returns the reg if the criteria is met
}
Hopefully it was of use to someone, but if not-.. well fu*k.
Reply
#2

This is basically just numbers, Number plates aren't just numbers in the UK or in the US.
Reply
#3

Quote:
Originally Posted by zT KiNgKoNg
View Post
This is basically just numbers, Number plates aren't just numbers in the UK or in the US.
Nope? It's 15 LV NUMBER... which is the exact format of a vehicle plate in Ireland.

Example:
Reply
#4

But, San Andreas isn't set in Ireland?
Reply
#5

Quote:
Originally Posted by Y_Less
View Post
No, it is a "terrible" file reader. Saying "outdated" implies there was ever a time when that wasn't the case, when in fact there were better systems about before dini even existed. Despite this, the whole point is moot since you don't even mention dini once in the actual tutorial or code...

What IS outdated, however, is this:



"foreach" stopped using that syntax about 4 years ago now, since then it has been the much more explicit (in terms of variable declaration):

pawn Code:
foreach (new i : Player)
If you are going to write a tutorial, you are responsible for giving people the best information possible, otherwise you are just spreading mis-information and bad practices. Adding a disclaimer at the top of your post that it is terrible doesn't make that fact alright.
You become very defensive if DINI is mentioned. Maybe it's because of Y_INI, maybe it's not. But you do become defensive. The only difference between YINI and DINI is the compiling speed.

There was no tutorial on the forums on how to do this so I decided to make one using my coding knowledge. You may think it's terrible, but some people might not know how to use YINI and it will help them. Thanks for the feedback, but as you said once, that is not "constructive criticism", it's just you flaming DINI at every chance you get.
Reply
#6

Quote:
Originally Posted by Ciarannn
View Post
You become very defensive if DINI is mentioned. Maybe it's because of Y_INI, maybe it's not. But you do become defensive. The only difference between YINI and DINI is the compiling speed.

There was no tutorial on the forums on how to do this so I decided to make one using my coding knowledge. You may think it's terrible, but some people might not know how to use YINI and it will help them. Thanks for the feedback, but as you said once, that is not "constructive criticism", it's just you flaming DINI at every chance you get.
The point is that you're NOT even using dini anywhere.

Plus dini is really slow compared to others, but yet you're not even using it lol.
Reply
#7

Quote:
Originally Posted by Ciarannn
View Post
You become very defensive if DINI is mentioned. Maybe it's because of Y_INI, maybe it's not. But you do become defensive. The only difference between YINI and DINI is the compiling speed.

There was no tutorial on the forums on how to do this so I decided to make one using my coding knowledge. You may think it's terrible, but some people might not know how to use YINI and it will help them. Thanks for the feedback, but as you said once, that is not "constructive criticism", it's just you flaming DINI at every chance you get.
If you dont know what are you saying, dont say anything.

He just said the true, if you dont like is your problem.


You have to many things their for an simple thing and where is the part are you using the dini their??
Reply
#8

Quote:
Originally Posted by PT
View Post
If you dont know what are you saying, dont say anything.

He just said the true, if you dont like is your problem.


You have to many things their for an simple thing and where is the part are you using the dini their??
I realised I forgot to add the part using DINI, I will add it in tomorrow.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)