Saving Plate
#1

Hello, i'm trying a script to save the licenses plates, i've took SetVehicleRandomPlate(vehicleid) but doesnt works in .ini files.

registering

Код:
format(var, 32, "Plate1=%d\n",PlayerInfo[playerid][pPlate1]);fwrite(hFile, var);
saving

Код:
format(var, 32, "Plate1=%d\n",PlayerInfo[playerid][pPlate1]);fwrite(hFile, var);

// on player create vehicle
new vehid = GetPlayerVehicleID(playerid);
PlayerInfo[playerid][pPlate1] = SetVehicleRandomPlate(vehid);
login

Код:
if( strcmp( key , "Plate1" , true) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pPlate1] = strvalEx( val ); }
I want numbers! not letters!
Код:
stock GetLetter(number)
{
        new letter[5];
        if(number == 1){letter="1";}if(number == 2){letter="2";}if(number == 3){letter="3";}if(number == 4){letter="4";}if(number == 5){letter="5";}if(number == 6){letter="6";}if(number == 7){letter="7";}if(number == 8){letter="8";}
        if(number == 9){letter="9";}if(number == 10){letter="0";}if(number == 11){letter="K";}if(number == 12){letter="L";}if(number == 13){letter="M";}if(number == 14){letter="N";}if(number == 15){letter="O";}if(number == 16){letter="P";}
        if(number == 17){letter="Q";}if(number == 18){letter="R";}if(number == 19){letter="S";}if(number == 20){letter="T";}if(number == 21){letter="U";}if(number == 22){letter="V";}if(number == 23){letter="W";}if(number == 24){letter="X";}
        if(number == 25){letter="Y";}if(number == 26){letter="Z";} return letter;
}
Код:
stock SetVehicleRandomPlate(vehicleid)
{
        new letter[4],
            number[15],
            plate[15];
        letter[0] = random(9)+1; letter[2] = random(9)+1; letter[3] = random(9)+1;
        new rnumber = random(10);
        new rnumber2 = random(10);
        new rnumber3 = random(10);
        format(number, 15, "%d%d%d", rnumber, rnumber2, rnumber3);
        format(plate, 15, "%d%d%d%d%d", GetLetter(letter[0]), GetLetter(letter[1]), GetLetter(letter[2]), GetLetter(letter[3]),number);
        SetVehicleNumberPlate(vehicleid, plate);
        //VehicleRandomPlate[vehicleid] = plate;
        //VehicleUsingRandomPlate[vehicleid] = 1;
        return 1;
}
RESULT (in my ini file) :
Код:
Plate1=1
Reply
#2

That GetLetter function is seriously cringe worthy. By the looks of it you replaced A through J with the number 0 through 9, but even the original function was really, really bad.

Anyway, if the only thing you want is 5 numbers then you can get away with just this:
PHP код:
format(platesizeof(plate), "%05d"random(100000)); 
Note that it is still a string and as such must be saved as string.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
That GetLetter function is seriously cringe worthy. By the looks of it you replaced A through J with the number 0 through 9, but even the original function was really, really bad.

Anyway, if the only thing you want is 5 numbers then you can get away with just this:
PHP код:
format(platesizeof(plate), "%05d"random(100000)); 
Note that it is still a string and as such must be saved as string.
it saves again this result :
Код:
Plate1=1
if i change %d to %s will save right?

@edit : changed %d to %s but it saves Plate1= (white space)
Reply
#4

Reply
#5

You are always returning 1 after the function, that's why the plate will always be 1. That's what you should do:

PHP код:
stock SetVehicleRandomPlate(vehicleid)
{
        new 
letter[4],
            
number[15],
            
plate[15];
        
letter[0] = random(9)+1letter[2] = random(9)+1letter[3] = random(9)+1;
        new 
rnumber random(10);
        new 
rnumber2 random(10);
        new 
rnumber3 random(10);
        
format(number15"%d%d%d"rnumberrnumber2rnumber3);
        
format(plate15"%d%d%d%d%d"GetLetter(letter[0]), GetLetter(letter[1]), GetLetter(letter[2]), GetLetter(letter[3]),number);
        
SetVehicleNumberPlate(vehicleidplate);
        
//VehicleRandomPlate[vehicleid] = plate;
        //VehicleUsingRandomPlate[vehicleid] = 1;
        
return plate;

Reply
#6

PHP код:
stock GetLetter(number){
    new 
letter[5];
    switch(
number){
        case 
1letter="1";
        case 
2letter="2";
        case 
3letter="3";
        case 
4letter="4";
        case 
5letter="5";
        case 
6letter="6";
        case 
7letter="7";
        case 
8letter="8";
        case 
9letter="9";
        case 
10letter="0";
        case 
11letter="K";
        case 
12letter="L";
        case 
13letter="M";
        case 
14letter="N";
        case 
15letter="O";
        case 
16letter="P";
        case 
17letter="Q";
        case 
18letter="R";
        case 
19letter="S";
        case 
20letter="T";
        case 
21letter="U";
        case 
22letter="V";
        case 
23letter="W";
        case 
24letter="X";
        case 
25letter="Y";
        case 
26letter="Z";
    }
    return 
letter;
}
format(platesizeof(plate), "%s%s%s%s%d"GetLetter(letter[0]), GetLetter(letter[1]), GetLetter(letter[2]), GetLetter(letter[3]),number); 
Reply
#7

error
Код:
(6298) : error 006: must be assigned to an array
 
line 6298: PlayerInfo[playerid][pPlate1] = SetVehicleRandomPlate(vehid);
Reply
#8

SetVehicleRandomPlate(vehicleid) <-- return sring

in PlayerInfo enum

pPlate1[15]
Reply
#9

If you want to be just numbers, use mine, if you want to have letters create the pPlate like that:

enum pInfo
{
pPlate1[15];
}
new PlayerInfo[MAX_PLAYERS][pInfo];

after that, the correct way to set the pPlate1 value is this:

format(PlayerInfo[playerid][pPlate1], 15, "%s%s%s%s%d", GetLetter(letter[0]), GetLetter(letter[1]), GetLetter(letter[2]), GetLetter(letter[3]),number);
Reply
#10

again this result on my ini file
Код:
Plate1=
(nothing)

saving is
Код:
format(var, 32, "Plate1=%s\n",PlayerInfo[playerid][pPlate1]);fwrite(hFile, var);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)