SA-MP Forums Archive
Problem with Y_INI saving and loading - 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)
+--- Thread: Problem with Y_INI saving and loading (/showthread.php?tid=390499)



Problem with Y_INI saving and loading - mSlat3r - 06.11.2012

Loading code:
pawn Код:
LoadDealerships() {

    if(!fexist("Dealerships.cfg")) return 1;

    new
        szFileStr[1024],
        File: iFileHandle = fopen("Dealerships.cfg", io_read),
        iIndex;

    while(iIndex < MAX_CARDEALERSHIPS && fread(iFileHandle, szFileStr)) {
        if(!sscanf(szFileStr, "p<|>ds[32]dfffd",
            CarDealer[iIndex][pOwned],
            CarDealer[iIndex][pOwner],
            CarDealer[iIndex][pPrice],
            CarDealer[iIndex][pVehicleSpawnX],
            CarDealer[iIndex][pVehicleSpawnY],
            CarDealer[iIndex][pVehicleSpawnZ],
            CarDealer[iIndex][pLocked])) {

            if(!isnull(CarDealer[iIndex][pOwner])) format(szFileStr, sizeof(szFileStr), "{4BB325}Vehicle Dealership\n{C4C920}[Owner: %s]\n[Price: $%d]\n\n[ID: %d]",  CarDealer[iIndex][pOwner], CarDealer[iIndex][pPrice], iIndex);
            else format(szFileStr, sizeof(szFileStr), "{4BB325}Vehicle Dealership\n{C4C920}[Owner: None(/buydealer)]\n[Price: $%d]\n\n[ID: %d]", CarDealer[iIndex][pPrice], iIndex);

            CarDealer[iIndex][pPickUp] = CreateDynamicPickup(1272, 23, CarDealer[iIndex][pVehicleSpawnX], CarDealer[iIndex][pVehicleSpawnY], CarDealer[iIndex][pVehicleSpawnZ], .worldid = 0, .interiorid = 0);
            CarDealer[iIndex][pLabel] = Create3DTextLabel(szFileStr, COLOR_WHITE, CarDealer[iIndex][pVehicleSpawnX], CarDealer[iIndex][pVehicleSpawnY], CarDealer[iIndex][pVehicleSpawnZ] + 0.5, 10.0, 0,0);
            ++iIndex;
        }
    }
    return fclose(iFileHandle);
}
Saving code:
pawn Код:
SaveDealerships() {

    new
        szFileStr[1024],
        File: fHandle = fopen("Dealerships.cfg", io_write);

    for(new iIndex; iIndex < MAX_CARDEALERSHIPS; iIndex++) {
        format(szFileStr, sizeof(szFileStr),"%d|%s|$%d|%f.2|%f.2|%f.2|%d\r\n",
            CarDealer[iIndex][pOwned],
            CarDealer[iIndex][pOwner],
            CarDealer[iIndex][pPrice],
            CarDealer[iIndex][pVehicleSpawnX],
            CarDealer[iIndex][pVehicleSpawnY],
            CarDealer[iIndex][pVehicleSpawnZ],
            CarDealer[iIndex][pLocked]
        );
        fwrite(fHandle, szFileStr);
    }
    fclose(fHandle);
    return 1;
}
Whenever I buy a dealership and what not, it will save and show my name and the co-ordinates, but after I restart the server and go to the place I made it, its gone and when I place another dealership after the restart it resets the other one


Re: Problem with Y_INI saving and loading - Glad2BeHere - 06.11.2012

pawn Код:
%f, not %f.2



Re: Problem with Y_INI saving and loading - mSlat3r - 06.11.2012

Didn't fix it ;/


Re: Problem with Y_INI saving and loading - Glad2BeHere - 06.11.2012

pawn Код:
"%d|%s|%d|%f|%f|%f|%d\r\n",



Re: Problem with Y_INI saving and loading - mSlat3r - 06.11.2012

Quote:
Originally Posted by Glad2BeHere
Посмотреть сообщение
pawn Код:
"%d|%s|%d|%f|%f|%f|%d\r\n",
Didn't make a difference


Re: Problem with Y_INI saving and loading - Glad2BeHere - 06.11.2012

post enum,save,load in 1 plz


Re: Problem with Y_INI saving and loading - mSlat3r - 07.11.2012

Quote:

enum eCarDealer
{
pOwned,
pOwner[MAX_PLAYER_NAME],
Text3D: pLabel,
pPrice,
Float: pVehicleSpawn[4],
pLocked,
pPickUp
};

Loading code:
pawn Код:
LoadDealerships() {

    if(!fexist("Dealerships.cfg")) return 1;

    new
        szFileStr[1024],
        File: iFileHandle = fopen("Dealerships.cfg", io_read),
        iIndex;

    while(iIndex < MAX_CARDEALERSHIPS && fread(iFileHandle, szFileStr)) {
        if(!sscanf(szFileStr, "p<|>ds[32]dfffd",
            CarDealer[iIndex][pOwned],
            CarDealer[iIndex][pOwner],
            CarDealer[iIndex][pPrice],
            CarDealer[iIndex][pVehicleSpawnX],
            CarDealer[iIndex][pVehicleSpawnY],
            CarDealer[iIndex][pVehicleSpawnZ],
            CarDealer[iIndex][pLocked])) {

            if(!isnull(CarDealer[iIndex][pOwner])) format(szFileStr, sizeof(szFileStr), "{4BB325}Vehicle Dealership\n{C4C920}[Owner: %s]\n[Price: $%d]\n\n[ID: %d]",  CarDealer[iIndex][pOwner], CarDealer[iIndex][pPrice], iIndex);
            else format(szFileStr, sizeof(szFileStr), "{4BB325}Vehicle Dealership\n{C4C920}[Owner: None(/buydealer)]\n[Price: $%d]\n\n[ID: %d]", CarDealer[iIndex][pPrice], iIndex);

            CarDealer[iIndex][pPickUp] = CreateDynamicPickup(1272, 23, CarDealer[iIndex][pVehicleSpawnX], CarDealer[iIndex][pVehicleSpawnY], CarDealer[iIndex][pVehicleSpawnZ], .worldid = 0, .interiorid = 0);
            CarDealer[iIndex][pLabel] = Create3DTextLabel(szFileStr, COLOR_WHITE, CarDealer[iIndex][pVehicleSpawnX], CarDealer[iIndex][pVehicleSpawnY], CarDealer[iIndex][pVehicleSpawnZ] + 0.5, 10.0, 0,0);
            ++iIndex;
        }
    }
    return fclose(iFileHandle);
}
Saving code:
pawn Код:
SaveDealerships() {

    new
        szFileStr[1024],
        File: fHandle = fopen("Dealerships.cfg", io_write);

    for(new iIndex; iIndex < MAX_CARDEALERSHIPS; iIndex++) {
        format(szFileStr, sizeof(szFileStr),"%d|%s|$%d|%f.2|%f.2|%f.2|%d\r\n",
            CarDealer[iIndex][pOwned],
            CarDealer[iIndex][pOwner],
            CarDealer[iIndex][pPrice],
            CarDealer[iIndex][pVehicleSpawnX],
            CarDealer[iIndex][pVehicleSpawnY],
            CarDealer[iIndex][pVehicleSpawnZ],
            CarDealer[iIndex][pLocked]
        );
        fwrite(fHandle, szFileStr);
    }
    fclose(fHandle);
    return 1;
}



Re: Problem with Y_INI saving and loading - Glad2BeHere - 07.11.2012

pawn Код:
enum eCarDealer
{
pOwned,
pOwner[MAX_PLAYER_NAME],
Text3D: pLabel,
pPrice,
Float: pVehicleSpawn[4],
pLocked,
pPickUp
}
new CarDealer[MAX_PLAYERS][eCarDealer];



Re: Problem with Y_INI saving and loading - mSlat3r - 07.11.2012

Quote:
Originally Posted by Glad2BeHere
Посмотреть сообщение
pawn Код:
enum eCarDealer
{
pOwned,
pOwner[MAX_PLAYER_NAME],
Text3D: pLabel,
pPrice,
Float: pVehicleSpawn[4],
pLocked,
pPickUp
}
new CarDealer[MAX_PLAYERS][eCarDealer];
Already got that ^

Its something to do with the loading code


Re: Problem with Y_INI saving and loading - Glad2BeHere - 07.11.2012

the whole thing is just wrong :/ srry u going to redo the whole thing from scratch = after the enum inbox for personal help k