SA-MP Forums Archive
Vehicle's random license plates - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Vehicle's random license plates (/showthread.php?tid=518029)



Vehicle's random license plates - Amel_PAtomAXx - 07.06.2014

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



Re: Vehicle's random license plates - Threshold - 08.06.2014

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"
};



Re: Vehicle's random license plates - Threshold - 08.06.2014

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


Re: Vehicle's random license plates - Amel_PAtomAXx - 08.06.2014

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);



Re: Vehicle's random license plates - Threshold - 08.06.2014

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


Re: Vehicle's random license plates - Amel_PAtomAXx - 08.06.2014

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


Re: Vehicle's random license plates - Threshold - 08.06.2014

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.


Re: Vehicle's random license plates - Amel_PAtomAXx - 08.06.2014

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.