[HELP]Saving License Plate
#1

Hi,
Can somenody help me doing this right:
I have a saving/loading License Plate system.
The LoadPlate() function is working fine, but the SavePlate not.
It make it like this
268, Nick
268, asdfg
268, 132
.
.
.
I just want that the Vehicle Id won't repeat anymore, but update.
Here is my LoadPlate func :
PHP код:
public LoadPlate()
{
    new 
arrCoords[20][64];
    new 
strFromFile2[256];
    new 
cplate[512];
    new 
cid[512];
    new 
File:file fopen("CarPlate/carplate.cfg"io_read);
    if (
file)
    {
        new 
idx;
        while (
idx 256)
        {
            
fread(filestrFromFile2);
            
Split(strFromFile2arrCoords',');
            
strmid(cid[idx], arrCoords[0], 0strlen(arrCoords[0]),255);
            
strmid(cplate[idx], arrCoords[1], 0strlen(arrCoords[1]),255);
            
SetVehicleNumberPlate(cid[idx],cplate[idx]);
            
idx++;
        }
        
fclose(file);
    }
    return 
1;

SavePlate:
PHP код:
public SavePlate(vinputtext[])
{
    new 
entry[256];
    
format(entrysizeof(entry), "%s,%s\n",v,inputtext);
    new 
File:hFile;
    
hFile fopen("CarPlate/carplate.cfg"io_append);
    
fwrite(hFileentry);
    
fclose(hFile);

and /carplate command:
PHP код:
    if(strcmp(cmd"/carplate"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {    new 
cid GetPlayerVehicleID(playerid);
            if(
gPlayerLogged[playerid] == 0)
            {
                
SendClientMessage(playeridCOLOR_GREY"   You havent logged in yet !");
                return 
1;
            }
            if(
PlayerInfo[playerid][pCarKey] == 0)
            {
                
SendClientMessage(playeridCOLOR_GRAD2"You don't own a car");
                return 
1;
            }
            
//GetPlayerName(playerid, sendername, sizeof(sendername));
            
new length strlen(cmdtext);
            while ((
idx length) && (cmdtext[idx] <= ' '))
            {
                
idx++;
            }
            new 
offset idx;
            new 
result[64];
            while ((
idx length) && ((idx offset) < (sizeof(result) - 1)))
            {
                
result[idx offset] = cmdtext[idx];
                
idx++;
            }
            
result[idx offset] = EOS;
            if(!
strlen(result))
            {
                
SendClientMessage(playeridCOLOR_GRAD2"USAGE: /carplate [plate]");
                return 
1;
            }
            if(
PlayerInfo[playerid][pCarKey]==&& PlayerInfo[playerid][pAdmin] < 1337)
            {
                
SendClientMessage(playeridCOLOR_GRAD2" You don't own a car! ");
                return 
1;
            }
            
format(stringsizeof(string), "Your new carplate is: %s",result);
            
SendClientMessage(playeridCOLOR_WHITEstring);
            
SetVehicleNumberPlate(cidresult);
            
SavePlate(cid,result);
            
/*new query[64];
            format(query, sizeof(query),"INSERT INTO plate (VehicleID, CarPlate) VALUES ('%d', '%s')", cid,result);
            samp_mysql_query(query);*/
        
}
        return 
1;
    } 
Thank you!
Reply
#2

If you want to call the vehicle ID again and again it might be the fastest way to let the server create a new file for each vehicle ID and just save the carplate in there. So each vehicle will have it's own file.
Then you can just delete and re-create the file with the new carplate.

Jeffry
Reply
#3

And how do i do that?
Reply
#4

When you save you save only that.. you have to loop all cars in your code.
Reply
#5

pawn Код:
public SavePlate(v, inputtext[])
{
    new entry[256];
    format(entry, sizeof(entry), "CarPlate/carplate%d.cfg",v);
    new File:test;
    if(!fexist(entry)) test = fopen(entry, io_readwrite), fclose(test);
    new File:hFile;
    hFile = fopen(entry, io_write);
    fwrite(hFile, inputtext);
    fclose(hFile);
}
Then you need to add a loop at LoadCars, know how to do that?
Reply
#6

for(new i = 0; i < MAX_VEHICLES; i++)
{
// Do stuff here
}

Like this?
Reply
#7

Yes, excatly.
If you need any help, I can give you the code for the LoadCars, in 1 or two days, because I am very busy.
Reply
#8

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Yes, excatly.
If you need any help, I can give you the code for the LoadCars, in 1 or two days, because I am very busy.
I tried to make it but it doesen't work xd, can you make that for me,please?
Reply
#9

pawn Код:
public LoadPlate()
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        new arrCoords[20][64];
        new strFromFile2[256];
        new cplate[512];
        new cid[512];
        new path[70];
        format(path, sizeof(path),"CarPlate/carplate%d.cfg", i);
        if(fexist(path))
        {
            new File:file = fopen(path, io_read);
            if(file)
            {
                new idx;
                fread(file, strFromFile2);
                SetVehicleNumberPlate(i,strFromFile2);
                fclose(file);
            }
        }
    }
    return 1;
}
Should work.
Reply
#10

Hi, i found this thread and i have a little question about it, how to do so, that after server restarts and loads these license plates.

Sorry for my bad english.
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)