Random Letters and Numbers
#1

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.
Reply
#2

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');
Reply
#3

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.
Reply
#4

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
Reply
#5

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.
Reply
#6

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.
Reply
#7

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
Reply
#8

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);
Reply
#9

Credits (sgtveh.inc)
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)