10.03.2015, 19:32
(
Last edited by Ciarannn; 14/03/2015 at 04:27 PM.
)
VEHICLE NUMBER PLATE
GENERATING SYSTEM
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;
}
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
}
pawn Code:
CMD:registration(playerid, params[])
{
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();
pawn Code:
new string[128];
pawn Code:
new vehicleid = GetPlayerVehicleID(playerid);
pawn Code:
//Reg Formatting
format(string, sizeof(string), "15 LV %d", registration);
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);
pawn Code:
// Confirmation message
format(string, sizeof(string), "Your license plate was set to {FF9900}%s{AFAFAF}.", string);
SendClientMessage(playerid, COLOR_GREY, string);
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
}