SA-MP Forums Archive
[HELP] Loading data from file - Ownership - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Loading data from file - Ownership (/showthread.php?tid=197626)



[HELP] Loading data from file - Ownership - Pooh7 - 09.12.2010

Hello

I have one "problem" (?).
Here is function for loading:
pawn Код:
public UcitajVozila()
{
    new arrCoords[13][256];
    new strFromFile2[256];
    new File: file = fopen("VozilaOwnership.cfg", io_read);
    if (file)
    {
        new idx = 0;
        while (idx < sizeof(Vozilo))
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, ',');
            Vozilo[idx][hModel] = strval(arrCoords[0]);
            Vozilo[idx][hPozX] = floatstr(arrCoords[1]);
            Vozilo[idx][hPozY] = floatstr(arrCoords[2]);
            Vozilo[idx][hPozZ] = floatstr(arrCoords[3]);
            Vozilo[idx][hPozA] = floatstr(arrCoords[4]);
            Vozilo[idx][hBoja1] = strval(arrCoords[5]);
            Vozilo[idx][hBoja2] = strval(arrCoords[6]);
            strmid(Vozilo[idx][hVlasnik], arrCoords[7], 0, strlen(arrCoords[7]), 255);
            strmid(Vozilo[idx][hOpis], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            Vozilo[idx][hImaVlasnika] = strval(arrCoords[11]);
            printf("Vozilo: %d Vlasnik: %s Model: %d",idx,Vozilo[idx][hVlasnik],Vozilo[idx][hModel]);
            idx++;
        }
    }
    return 1;
}
OnGameModeInit:
pawn Код:
UcitajVozila();
    for(new i=1; i < sizeof Vozilo; i++)
    {
        Vozilo[i][ownedvehicle] = CreateVehicle(Vozilo[i][hModel], Vozilo[i][hPozX], Vozilo[i][hPozY], Vozilo[i][hPozZ], Vozilo[i][hPozA], Vozilo[i][hBoja1], Vozilo[i][hBoja2], 300000);
    }


Saving function:

pawn Код:
public SacuvajVozila()
{
    new idx;
    new File: file2;
    while (idx < sizeof(Vozilo))
    {
        new coordsstring[256];
        format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%d\r\n",
        Vozilo[idx][hModel],
        Vozilo[idx][hPozX],
        Vozilo[idx][hPozY],
        Vozilo[idx][hPozZ],
        Vozilo[idx][hPozA],
        Vozilo[idx][hBoja1],
        Vozilo[idx][hBoja2],
        Vozilo[idx][hVlasnik],
        Vozilo[idx][hOpis],
        Vozilo[idx][hCena],
        Vozilo[idx][hImaVlasnika]);
        if(idx == 0)
        {
            file2 = fopen("VozilaOwnership.cfg", io_write);
        }
        else
        {
            file2 = fopen("VozilaOwnership.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
    return 1;
}

A couple lines from VozilaOwnership.cfg:
Код:
411,551.633239,-1263.060302,17.042186,215.000000,20,1,Autosalon,Infernus,1000000,0

411,548.76397705,-1265.01513672,17.04218674,214.99694824,20,1,Autosalon,Infernus,1000000,0

411,545.978637,-1266.909790,17.042186,214.996948,20,1,Autosalon,Infernus,1000000,0

411,543.090332,-1268.874511,17.042186,214.996948,20,1,Autosalon,Infernus,1000000,0

415,540.708251,-1270.963989,17.091709,217.000000,61,1,Autosalon,Cheetah,350000,0

415,538.409362,-1272.693847,17.091709,216.996459,61,1,Autosalon,Cheetah,350000,0

415,536.046020,-1274.463989,17.091709,216.996459,61,1,Autosalon,Cheetah,350000,0

451,534.060913,-1276.610595,17.006559,217.000000,1,1,Autosalon,Turismo,500000,0

451,531.618164,-1278.442138,17.006559,216.996459,1,1,Autosalon,Turismo,500000,0

451,529.175781,-1280.273193,17.006559,216.996459,1,1,Autosalon,Turismo,500000,0
Now, the problem is... Look at the server log:
Код:
[21:11:06] Vozilo: 0 Vlasnik: Autosalon Model: 411
[21:11:06] Vozilo: 1 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 2 Vlasnik: Autosalon Model: 411
[21:11:06] Vozilo: 3 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 4 Vlasnik: Autosalon Model: 411
[21:11:06] Vozilo: 5 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 6 Vlasnik: Autosalon Model: 411
[21:11:06] Vozilo: 7 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 8 Vlasnik: Autosalon Model: 415
[21:11:06] Vozilo: 9 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 10 Vlasnik: Autosalon Model: 415
[21:11:06] Vozilo: 11 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 12 Vlasnik: Autosalon Model: 415
[21:11:06] Vozilo: 13 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 14 Vlasnik: Autosalon Model: 451
[21:11:06] Vozilo: 15 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 16 Vlasnik: Autosalon Model: 451
[21:11:06] Vozilo: 17 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 18 Vlasnik: Autosalon Model: 451
[21:11:06] Vozilo: 19 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 20 Vlasnik: Autosalon Model: 477
[21:11:06] Vozilo: 21 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 22 Vlasnik: Autosalon Model: 477
[21:11:06] Vozilo: 23 Vlasnik: Autosalon Model: 0
[21:11:06] Vozilo: 24 Vlasnik: Autosalon Model: 477
So, you can see that is loading Model, Empty, Model, Empty, Model, Empty, Model, Empty, .........
I have 64 lines in .cfg file, so it's 64 cars.
In my enumerator, instead of new Vozilo[64][hoInfo], I must to type new Vozilo[128][hoInfo];.
Actually, it's not the problem, script don't skips any vehicle, and all vehicles are loading successfull (if amount of vehicles 128, not 64).
But, why I have that empty models
And how to fix it?


Sorry for my bad English, I hope you can understand my 'problem'.


Re: [HELP] Loading data from file - Ownership - smeti - 09.12.2010

Delete the blank line, VozilaOwnership.cfg.

pawn Код:
//wrong
411,551.633239,-1263.060302,17.042186,215.000000,20,1,Autosalon,Infernus,1000000,0 //line 1
// line 2
411,548.76397705,-1265.01513672,17.04218674,214.99694824,20,1,Autosalon,Infernus,1000000,0 //line 3
// line 4
411,545.978637,-1266.909790,17.042186,214.996948,20,1,Autosalon,Infernus,1000000,0 // line 5
Correct:
pawn Код:
411,551.633239,-1263.060302,17.042186,215.000000,20,1,Autosalon,Infernus,1000000,0 //line 1
411,548.76397705,-1265.01513672,17.04218674,214.99694824,20,1,Autosalon,Infernus,1000000,0 // line 2
411,545.978637,-1266.909790,17.042186,214.996948,20,1,Autosalon,Infernus,1000000,0 // line 3



Re: [HELP] Loading data from file - Ownership - Pooh7 - 09.12.2010

Ok, but in my cfg file there is no empty lines.
Look:
http://slike.hr/slike/untitled_1c2ac.jpg.html


Re: [HELP] Loading data from file - Ownership - smeti - 09.12.2010

Quote:
Originally Posted by Pooh7
Посмотреть сообщение
Ok, but in my cfg file there is no empty lines.
Look:
http://slike.hr/slike/untitled_1c2ac.jpg.html
What is character?
Код:
411,551.633239,-1263.060302,17.042186,215.000000,20,1,Autosalon,Infernus,1000000,0?
411,548.76397705,-1265.01513672,17.04218674,214.99694824,20,1,Autosalon,Infernus,1000000,0?
411,545.978637,-1266.909790,17.042186,214.996948,20,1,Autosalon,Infernus,1000000,0?
Please uploaded VozilaOwnership.cfg file.


Re: [HELP] Loading data from file - Ownership - Pooh7 - 09.12.2010

I'm deleted this character and now it works.
I think that character is making a new line :/