Y_Ini tag
#1

I have a house system working with y_ini, i need to save the bought vehicles into the same house file that the player owned.

Currently there is only one tag named data to hold the house data in the house file like:

Код:
[data]
HouseName = {FFFFFF}House of Oxide
HouseX = 1457.890014
HouseY = 1013.313598
HouseZ = 10.820310
HouseLevel = 1 etc...
My question is, if i add another tag after the house data called [vehicles] like:

Код:
[data]
HouseName = {FFFFFF}House of Oxide
HouseX = 1457.890014
HouseY = 1013.313598
HouseZ = 10.820310
HouseLevel = 1 etc...

[vehicles]
Model = 520
Paint = 1
Nitro = 1
Color1 = 21
color2 = 55 etc...
How would i load those 2 tags separately? I mean the first tag [data] is used to load the houses in OnGameModeInit, and i need the second tag [vehicles] to be loaded in OnPlayerConnect callback. But i have no idea how to do it. Can someone explain me? The saving system works fine but i got problem while loading them.

I would make separate files for the vehicles but since i already have other files i.e bank, businesses, and so on, i thought of adding the vehicles inside the house file to reduce the gamemode size.
Reply
#2

I'm not sure how will you set the files name. If it's named after a player(like name.ini) you won't be able to get the file name OnGameModeInit. One workaround is to have a file with all registerer player names(not even y_ini, but native file functions).

As for loading data under "data" tag, use INI_ParseFile.
pawn Код:
INI_ParseFile(filename, "ini_%s");
// And then add a public function, assuming the tag is called "data" as in your example.
forward ini_data(name[], value[]);
public ini_data(name[], value[])
{
  // load it here.
}
Reply
#3

File names are set like House1.ini, House2.ini and so on, since i have looped through MAX_HOUSES from 1 while saving them.

And i am not saying houses aren't loading, they load just fine under OnGameModeInit. I am asking how would i load 2 tags separately? For example, [data] tag should only load in OnGameModeInit and [vehicles] tag should only load in OnPlayerConnect callack.

Currently i have something like this in OnPlayerConnect:

pawn Код:
public OnPlayerConnect(playerid)
{
    new
        HouseID;

    HouseID = pInfo[playerid][pHouse_ID];
   
    if(HouseID != 0)
    {
        //Here i need to load the vehicle data from the second tag in the house file
    }
    return 1;
}
Reply
#4

/Bump D:
Reply
#5

pawn Код:
INI_Load("FileDirectory"); //under ongamemodeint

//somewhere
INI:FileDirectory[TAG](name[], value[])
{
    INI_Int("VARNAME", VARLOAD);
    return 0;
}
Reply
#6

Well, that didn't work. I guess you guys still didn't understand what i am actually trying to say.

For example:

Suppose i have these data

Код:
[house_data]
Owner = Oxide
Price = 1000000
Level = 5
Insurance = true

[vehicle_data]
Model = 525
sX = 522.55
sY = -255.6520
sZ = 622.67
sRot = 526.6787
in one file called House5.ini

Now, what i am saying is, how would i load those 2 tags SEPARATELY. Like, [house_data] should only load inside OnGameModeInit but not [vehicle_data] and [vehicle_data] should only load in OnPlayerConnect but not [house_data]. I don't know if its even possible to do it with y_ini or not but i need something like that to make the vehicle system working :/
Reply
#7

use INI_SetTag like this.
Код:
new
    INI: ini = INI_Open( "MyIniFile.ini" );
INI_SetTag(ini, "House");
INI_WriteString(ini, "Owner", "TheRoW");
INI_SetTag(ini, "Veh" );
INI_WriteInt(ini, "Value", 500000);
INI_Close(ini);
Reply
#8

Omg... -.-

I already did set the tag like that. I am talking about how to load them separately in two different callbacks!
Reply
#9

Ok, after reading that i have tried doing it like this

While saving:
pawn Код:
HouseFile_Save(HouseID)
{
    new
        INI:HFile = INI_Open(House_Directory(HouseID)),
        vid
    ;

    INI_SetTag(HFile, "@@House-data");
    INI_WriteString(HFile, "HouseName", gHouseData[HouseID][HouseName]);
    INI_WriteFloat(HFile, "HouseX", gHouseData[HouseID][HouseX]);
    INI_WriteFloat(HFile, "HouseY", gHouseData[HouseID][HouseY]);
    //more bellow
    for (new v_index; v_index < 10; v_index++)
    {
        if (gHouseData[HouseID][VehicleIDs][v_index] != 0)
        {
            vid = gHouseData[HouseID][VehicleIDs][v_index];
            INI_SetTag(HFile, "@@Vehicles-data");
            INI_WriteInt(HFile, "VehicleModel", gVehicleInfo[vid][Model]);
            INI_WriteInt(HFile, "Fuel", gVehicleInfo[vid][Fuel]);
            INI_WriteInt(HFile, "VehiclePaintJob", gVehicleInfo[vid][PaintJob]);
            INI_WriteInt(HFile, "VehicleSpoiler", gVehicleInfo[vid][Components][0]);
            //more bellow
        }
    }
    INI_Close(HFile);
}
pawn Код:
//This goes under OnGameModeInit()
Housing_LoadAll()
{
    for(new HouseID = 1; HouseID < MAX_HOUSES; HouseID++)
    {
        if(fexist(House_Directory(HouseID)))
        {
            INI_ParseFile(House_Directory(HouseID), "LoadHouse_%s", .bExtra = true, .extra = HouseID, .bFilter = true, .filter = "House");
            House_CreateEntrance(HouseID);
            gHouseData[HouseID][HouseOpened] = false;
            TotalHouses++;
        }
    }
}
pawn Код:
//This goes under OnPlayerConnect
    new
        house_id = pInfo[playerid][pHouse_ID];

    if (house_id != 0)
    {
        if(fexist(House_Directory(house_id)))
        {
            INI_ParseFile(House_Directory(house_id), "LoadHouse_%s", .bExtra = true, .extra = house_id, .bFilter = true, .filter = "Vehicles");

            for (new v_index; v_index < 10; v_index++)
            {
                if(gHouseData[house_id][VehicleIDs][v_index] != 0)
                {
                    vid = gHouseData[house_id][VehicleIDs][v_index];

                    House_AddVehicle(house_id,  gVehicleInfo[vid][Model], gVehicleInfo[vid][PaintJob], gVehicleInfo[vid][Components], gVehicleInfo[vid][SpawnX], gVehicleInfo[vid][SpawnY], gVehicleInfo[vid][SpawnZ], gVehicleInfo[vid][SpawnRot],  gVehicleInfo[vid][Color1], gVehicleInfo[vid][Color2]);
                    gVehicleInfo[vid][Clamped] = gVehicleInfo[vid][Clamped];

                    if (gVehicleInfo[vid][Fuel] == -1)
                        gVehicleInfo[vid][Fuel] = MAX_FUEL;
                    else
                        gVehicleInfo[vid][Fuel] = gVehicleInfo[vid][Fuel];
                }
            }
        }
    }
But these code didn't work. House loads fine but not the vehicles. Is there something wrong? Help please. And sorry for posting huge stuffs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)