Vehicle's random license plates
#1

Im trying to make a random vehicle's plates, for the vehicles you create with a cmd.

This is how I did it.

The example of licenses plates should be "A95-N-851"
pawn Код:
// under /vehicle command
        format(vplates, sizeof(vplates), "%s%s%s-%s-%s%s%s", RandomPlate1, RandomPlate2, RandomPlate2, RandomPlate1, RandomPlate2, RandomPlate2, RandomPlate2);
        VehicleInfo[vid][vPlates] = vplates;
        SetVehicleNumberPlate(vid, VehicleInfo[vid][vPlates]);
        SetVehicleToRespawn(vid);
RandomPlate1 and RandomPlate2 looks like this:
pawn Код:
new RandomPlate1[][] =
        {
            "A",
            "B",
            "C",
            "D",
            "E",
            "F",
            "G",
            "H",
            "I",
            "J",
            "K",
            "L",
            "M",
            "N",
            "O",
            "P",
            "R",
            "S",
            "T",
            "U",
            "V",
            "Z",
            "W",
            "X",
            "Y"
        };
        new RandomPlate2[][] =
        {
            "0",
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9"
        };
and this is what I get in plates:
pawn Код:
dhlptx|€„ˆŒђ”˜œ*¤Ё¬°ґёјАДA(,048
Reply
#2

pawn Код:
format(vplates, sizeof(vplates), "%s%d%d-%s-%d%d%d", LetterList[random(sizeof(LetterList))], random(10), random(10), LetterList[random(sizeof(LetterList))], random(10), random(10), random(10));
        VehicleInfo[vid][vPlates] = vplates;
        SetVehicleNumberPlate(vid, vplates);
        SetVehicleToRespawn(vid);
Replace RandomPlate1 and RandomPlate2 with:
pawn Код:
new LetterList[26][] =
{
    "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
};
Reply
#3

An alternative is:
pawn Код:
format(vplates, sizeof(vplates), "%c%d%d-%c-%d%d%d", random(26) + 65, random(10), random(10), random(26) + 65, random(10), random(10), random(10));
        VehicleInfo[vid][vPlates] = vplates;
        SetVehicleNumberPlate(vid, vplates);
        SetVehicleToRespawn(vid);
I guess :S
Reply
#4

I have read a bit on sampwiki and found a soultion like this, works very well.
pawn Код:
new rand1 = random(sizeof(RandomPlate1));
        new rand2 = random(sizeof(RandomPlate2));
        new rand3 = random(sizeof(RandomPlate2));
        new rand4 = random(sizeof(RandomPlate1));
        new rand5 = random(sizeof(RandomPlate2));
        new rand6 = random(sizeof(RandomPlate2));
        new rand7 = random(sizeof(RandomPlate2));
       
        format(vplates, sizeof(vplates), "%s%s%s-%s-%s%s%s", RandomPlate1[rand1], RandomPlate2[rand2], RandomPlate2[rand3], RandomPlate1[rand4], RandomPlate2[rand5], RandomPlate2[rand6], RandomPlate2[rand7]);
        VehicleInfo[vid][vPlates] = vplates;
        SetVehicleNumberPlate(vid, VehicleInfo[vid][vPlates]);
        SetVehicleToRespawn(vid);
Reply
#5

That's a horrible way to do it, but alright. Whatever suits you I guess..
Reply
#6

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
That's a horrible way to do it, but alright. Whatever suits you I guess..
Horrible, but works.
Reply
#7

pawn Код:
format(vplates, sizeof(vplates), "%c%d%d-%c-%d%d%d", random(26) + 65, random(10), random(10), random(26) + 65, random(10), random(10), random(10));
        VehicleInfo[vid][vPlates] = vplates;
        SetVehicleNumberPlate(vid, vplates);
        SetVehicleToRespawn(vid);
Great, and works. Make your choice.
Reply
#8

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
pawn Код:
format(vplates, sizeof(vplates), "%c%d%d-%c-%d%d%d", random(26) + 65, random(10), random(10), random(26) + 65, random(10), random(10), random(10));
        VehicleInfo[vid][vPlates] = vplates;
        SetVehicleNumberPlate(vid, vplates);
        SetVehicleToRespawn(vid);
Great, and works. Make your choice.
Alright, I'll respect you as an High-Roller and use your way.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)