[HELP] How to use Y_INI
#1

Hey guys, ive googeled a lot on this already, and also used SA-MP forums to search for it, but i have no idea how to read data out of a file putting it in to a string.

All i find are very weird functions like
Код:
INI:myini[](name[], value[])
{
    INI_String("a", gA);
    INI_String("b", gB);
    INI_String("c", gC);
    return 0; // This is now required.
}
INI_Load("myini.ini");
But what to do i need to do with that ?, where do i need to place it ? is it even a function ?,what if i put the file in a subfolder, is it then still INI:filename ?, and why can dini do it with 1 line of text and y_ini not ?
I hope someone can be a bit more clear to me how to actually get data from a file, because writing data seems to be very easy in Y_INI, but reading it is very weird/unclear.

I have the following function that i would like to have converted, so please give me an example how to do this with Y_INI:

Example with DINI:
pawn Код:
stock LoadVehicles()
{
    new file[96];
    for(new i = 0;i<MAX_LOADED_VEHICLES;i++)
    {
        format(file,sizeof file,"/PrivateVehicles/Vehicles/%i.ini",i);
        if(dini_Exists(file) )
        {
            VehicleInfo[i][Model] = dini_Int(file,"Model");
            VehicleInfo[i][X] = dini_Float(file,"X");
            VehicleInfo[i][Y] = dini_Float(file,"Y");
            VehicleInfo[i][Z] = dini_Float(file,"Z");
            VehicleInfo[i][Rot] = dini_Float(file,"Rot");
            VehicleInfo[i][Color1] = dini_Int(file,"Color1");
            VehicleInfo[i][Color2] = dini_Int(file,"Color2");
            format(VehicleInfo[i][Plate],32,"%s",dini_Get(file,"Plate"));
            format(VehicleInfo[i][Owner],MAX_PLAYER_NAME,"%s",dini_Get(file,"Owner"));
            VehicleInfo[i][Lender] = -1;

            VehicleInfo[i][Id] = AddStaticVehicle(VehicleInfo[i][Model],VehicleInfo[i][X],VehicleInfo[i][Y],VehicleInfo[i][Z],VehicleInfo[i][Rot],VehicleInfo[i][Color1],VehicleInfo[i][Color2]);
            SetVehicleNumberPlate(VehicleInfo[i][Id],VehicleInfo[i][Plate]);
            SetVehicleToRespawn(VehicleInfo[i][Id]);
            loaded_vehicles++;

        }
    }
    return 1;
}
Reply
#2

*BUMP*

Edit:
Well nvm then, im using djson now
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
pawn Код:
#include <YSI\y_stringhash>
#include <YSI\y_utils>

forward VehicleLoad(vid, name[], value[]);

public VehicleLoad(vid, name[], value[])
{
    // Switch on strings (requires y_stringhash).  These are case-insensitive.
    // Note that this requires the LATEST version of y_stringhash from:
    // http://pastebin.com/xhNGu8q7
    switch (YHash(name))
    {
        case _I<model>:
        {
            // Save the model data.
            VehicleInfo[vid][Model] = strval(value);
        }
        case _I<x>:
        {
            VehicleInfo[vid][X] = floatstr(value);
        }
        case _I<y>:
        {
            VehicleInfo[vid][Y] = floatstr(value);
        }
        case _I<z>:
        {
            VehicleInfo[vid][Z] = floatstr(value);
        }
        case _I<rot>:
        {
            VehicleInfo[vid][Rot] = floatstr(value);
        }
        case _I<color1>:
        {
            VehicleInfo[vid][Color1] = strval(value);
        }
        case _I<color2>:
        {
            VehicleInfo[vid][Color2] = strval(value);
        }
        case _I<plate>:
        {
            strcpy(VehicleInfo[vid][Plate], value, 32);
        }
        case _I<owner>:
        {
            strcpy(VehicleInfo[vid][Owner], value, MAX_PLAYER_NAME);
        }
    }
    return 0; // This is now required.
}

stock LoadVehicles()
{
    new file[96];
    for (new i = 0;i<MAX_LOADED_VEHICLES;i++)
    {
        // Get the filename.
        format(file,sizeof file,"/PrivateVehicles/Vehicles/%i.ini",i);
        // Load the file, always using the "VehicleLoad" function, not one
        // based on the file's name.  Also, pass the vehicle ID.
        INI_ParseFile(file, "VehicleLoad", .bExtra = true, .extra = i);
        // The other bits.
        VehicleInfo[i][Id] = AddStaticVehicle(VehicleInfo[i][Model], VehicleInfo[i][X], VehicleInfo[i][Y], VehicleInfo[i][Z], VehicleInfo[i][Rot], VehicleInfo[i][Color1], VehicleInfo[i][Color2]);
        SetVehicleNumberPlate(VehicleInfo[i][Id], VehicleInfo[i][Plate]);
        SetVehicleToRespawn(VehicleInfo[i][Id]);
        ++loaded_vehicles;
    }
    return 1;
}
Comments are in the file. And it's more complex to use than dini because it's more powerful and faster.
Now thats a good example!, thanks ******
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)