License Plate System
#1

Код:
public OnGameModeInit ( )
{
    new vehicle_id, Text3D:vehicle3Dtext;
    vehicle3Dtext = Create3DTextLabel( "Plate #", 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
    vehicle_id = CreateVehicle( 510, 0.0. 0.0, 15.0, 5, 0, 120 );
    Attach3DTextLabelToVehicle( vehicle3Dtext, vehicle_id, 0.0, 0.0, 2.0);
}
Ok, So yea. I want to create a vehicle license plate system, what I mean is that every vehicle in the server has a random license plate number and saves, the only cars that doesn't have a random number is the LSPD cars, I want to set a number for each car, can anyone help me out

Oh I also have a vehicle ownership system, so how would I make it assign the car a number when they buy one.
Reply
#2

Use random.

Let's say you want the format "<letter><letter><number><number><number>" (2 letters, 3 numbers)
You'd do something like this:
pawn Код:
//on top
new
    letters[ 26 ][ 2 ] =
    {
        "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M",
        "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
    };
new
    nums[ 10 ][ 2 ] =
    {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    };
pawn Код:
new str[ 6 ];
new rand[ 5 ];
rand[ 0 ] = random( sizeof( letters ));
rand[ 1 ] = random( sizeof( letters ));
rand[ 2 ] = random( sizeof( nums ));
rand[ 3 ] = random( sizeof( nums ));
rand[ 4 ] = random( sizeof( nums ));

format( str, sizeof( str ), "%s%s%d%d%d", letters[ rand[ 0 ]], letters[ rand[ 1 ]], nums[ rand[ 2 ]], nums[ rand[ 3 ]], nums[ rand[ 4 ]] );
You should probably save all license plates into a file, or a var, to make sure of no one gets the same license plate.
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
So no! There was a discussion about this recently here:

pawn Код:
static const
    sLetters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
    sNumbers[] = "0123456789";

#define RND(%0) %0[random(sizeof (%0))]

new
    str[6] =
        {
            RND(sLetters),
            RND(sLetters),
            RND(sNumbers),
            RND(sNumbers),
            RND(sNumbers),
            '\0'
        };

#undef RND
Sorry, I'm no pro >.<
Thank you for showing me wrong though. *learning in progression*

EDIT: ******, can you please explain why use use static and const for the letters and numbers?
I know static sorta remembers the value or something like that (cba to "explain" what I think), but what does const do? I could ****** it or search through pawn-lang, but I believe (after som experience) that you are able to explain better than the PDF.
Ty in advance
Reply
#4

Ah ok, ty for explaining. ^^ (const = aka. constant(ly) ?)
Reply
#5

So Y Less, Your code will give each vehicle and random license plate and when someone buys one also?

Edit: This is some sort of a RCON password changer. The code you gave me crashed my Pawno Y Less
Reply
#6

If you use the exact code as ****** gave you, use "str" for licenseplates.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)