Letters converted into numbers.
#2

Every character is an ASCII number, you don't need a switch statement to get it.
pawn Код:
for(new i; i < strlen(string);i++)
{
     printf("%c = %d",string[i],string[i]);
}
Then you just have to create a formula to create a large number from these small numbers ( easier said than done )

If you want to create a unique random account number for each player, you can try this
pawn Код:
stock returnnewcarid()
{
    new carfile[9],carstring[128];
    for(new i = 0; i <= 8; i++)
    {
        carfile[i] = random(9)+1;
    }
    format(carstring,sizeof(carstring), "%s%d%d%d%d%d%d%d%d%d.ini",CARS_PATH,carfile[0],carfile[1],carfile[2],carfile[3],carfile[4],carfile[5],carfile[6],carfile[7],carfile[8]);
    while(fexist(carstring))
    {
        for(new i = 0; i <= 8; i++)
        {
            carfile[i] = random(9)+1;
        }
        format(carstring,sizeof(carstring), "%s%d%d%d%d%d%d%d%d%d.ini",CARS_PATH,carfile[0],carfile[1],carfile[2],carfile[3],carfile[4],carfile[5],carfile[6],carfile[7],carfile[8]);
    }
    new regstring[12],new_code;
    format(regstring,sizeof(regstring),"%d%d%d%d%d%d%d%d%d",carfile[0],carfile[1],carfile[2],carfile[3],carfile[4],carfile[5],carfile[6],carfile[7],carfile[8]);
    new_code = strval(regstring);
    return new_code;
}
Its written for a car registration system, but you can modify it for your purposes. Just change CAR_PATH to a directory in scriptfiles, and create a new file there for every account number you create ( this will ensure each account number is unique )

I know it seems like a very long way to do this, but I wanted to create a unique 9 digit number with no zeros in it, and thats how I did it. Now that I look at it, there are better ways to do this, but :effort:

[edit] You could also use AUTO_INCREMENT in an sql table
Reply


Messages In This Thread
Letters converted into numbers. - by Giacomand - 19.12.2010, 04:55
Re: Letters converted into numbers. - by Rachael - 19.12.2010, 06:32
Re: Letters converted into numbers. - by Giacomand - 19.12.2010, 16:18
Re: Letters converted into numbers. - by Rachael - 19.12.2010, 16:23

Forum Jump:


Users browsing this thread: 1 Guest(s)