SA-MP Forums Archive
Random Letters and Numbers - 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: Random Letters and Numbers (/showthread.php?tid=308961)



Random Letters and Numbers - Abreezy - 05.01.2012

How could you make a thing for random letters? I'm using this for plate system, so i want it to spawn random plates for example:

abc-1234

Thats the format I want it in, any ideas? Thanks in advance. Yes i searched before posting.


Re: Random Letters and Numbers - Norck - 05.01.2012

I'm not sure that it will work, but you should try it:
pawn Code:
new num_plate[9];
for(new i; i < 3; i++) // 1,2,3 pos are letters
    num_plate[i] = 'a'+random('z'-'a');
num_plate[3] = '-';  // 4 pos is '-'
for(new i=4; i < sizeof(num_plate); i++) // 5,6,7,8 pos are numbers
    num_plate[i] = '0'+random('9'-'0');



Re: Random Letters and Numbers - Mrki_Drakula - 05.01.2012

PHP Code:
        new string[32];
        new 
randnumb random(9);
        
format(stringsizeof(string),"Text-%d%d%d",randnumb,randnumb,randnumb);
        
SetVehicleNumberPlate(vehicleidstring);
        
SetVehicleToRespawn(vehicleid); 
That should work too.


Re: Random Letters and Numbers - Abreezy - 05.01.2012

Quote:
Originally Posted by Mrki_Drakula
View Post
PHP Code:
        new string[32];
        new 
randnumb random(9);
        
format(stringsizeof(string),"Text-%d%d%d",randnumb,randnumb,randnumb);
        
SetVehicleNumberPlate(vehicleidstring);
        
SetVehicleToRespawn(vehicleid); 
That should work too.
I want it to also have the 3 random letters infront. How do i get a random letter


Re: Random Letters and Numbers - thiaZ_ - 05.01.2012

You could try:

pawn Code:
stock getRandomLetter() {
    return 65 + random(52); // ASCII Code of capital A is 65 + 2 * 26 for all other chars in alphabet.
}

//...
format(someString, 128, "%c, %c, %c", getRandomLetter(), getRandomLetter(), getRandomLetter());
I'm not sure how number plates are shown, if there are capital letters only you could change the max. random value to 26 again.


Re: Random Letters and Numbers - Abreezy - 05.01.2012

pawn Code:
SetVehicleNumberPlate(cCar, string);
VehicleInfo[Total_Veh_Created][vPlate]  = string;
SetVehicleToRespawn(cCar);
How could i save the plate like that? It says "666) : error 006: must be assigned to an array" for the second line.


Re: Random Letters and Numbers - vincee - 05.01.2012

Create a complete new function.

have this with your "new" shit,

pawn Code:
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"
};
this with the stock shit...

pawn Code:
stock SetVehicleRandomNumberPlate(vehicleid)
{
    new string[10];
    format(string, sizeof(string), "%s%s%s%s %d%d%d", LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], LetterList[random(sizeof(LetterList))], random(10), random(10), random(10));
    SetVehicleNumberPlate(vehicleid, string);
    return 1;
}
and ongamemodeinit

have

pawn Code:
for(new i=0;i<MAX_VEHICLES;i++)
    {
        new engine, lights, alarm, doors, bonnet, boot, objective; //This is defining the vehicles current items.
        SetVehicleRandomNumberPlate(i);
return 1;
}[/pawn


Re: Random Letters and Numbers - thiaZ_ - 05.01.2012

pawn Code:
// (By ******)
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

strcpy(VehicleInfo[Total_Veh_Created][vPlate], string, sizeof(VehicleInfo[Total_Veh_Created][vPlate]));

//or...
format(VehicleInfo[Total_Veh_Created][vPlate], sizeof(VehicleInfo[Total_Veh_Created][vPlate]), string);



Re: Random Letters and Numbers - vincee - 05.01.2012

Credits (sgtveh.inc)