How to load multiple files using Y_Ini?
#1

As topic says.. using Parsing file method.

pawn Код:
stock SaveObjects()
{
    for(new i = 0; i < MAX_CREATED_OBJECTS; i++)
    {
        new INI:Objects = INI_Open(ObjectFile(i));
        INI_WriteFloat  (Objects,   "oX",           ObjectInfo[i][oX]);
        INI_WriteFloat  (Objects,   "oY",           ObjectInfo[i][oY]);
        INI_WriteFloat  (Objects,   "oZ",           ObjectInfo[i][oZ]);
        INI_WriteFloat  (Objects,   "rX",           ObjectInfo[i][oRX]);
        INI_WriteFloat  (Objects,   "rY",           ObjectInfo[i][oRY]);
        INI_WriteFloat  (Objects,   "rZ",           ObjectInfo[i][oRZ]);
        INI_Close(Objects);
        break;
    }
    return true;
}

stock LoadObjects()
{
    for(new i = 1; i < MAX_CREATED_OBJECTS; i++)
    {
        INI_ParseFile(ObjectFile(i), "LoadCreatedObjects", .bExtra = true, .extra = i);
        CreateObjectEx(ObjectInfo[i][oModelID], ObjectInfo[i][oX], ObjectInfo[i][oY], ObjectInfo[i][oZ]);
        ObjectInfo[i][oDescriptionLabel] = Create3DTextLabel(ObjectInfo[i][oDescription], COLOR_NICK, ObjectInfo[i][oX], ObjectInfo[i][oY], ObjectInfo[i][oZ], 100.0, 0);
    }
    return true;
}

forward LoadCreatedObjects(playerid, name[], value[]);
public LoadCreatedObjects(playerid, name[], value[])
{
    for(new i = 1; i < MAX_CREATED_OBJECTS; i++)
    {
        if(!strcmp(name, "ModelID"))        ObjectInfo[i][oModelID]     = strval(value);
        if(!strcmp(name, "oX"))             ObjectInfo[i][oX]           = floatstr(value);
        if(!strcmp(name, "oY"))             ObjectInfo[i][oY]           = floatstr(value);
        if(!strcmp(name, "oZ"))             ObjectInfo[i][oZ]           = floatstr(value);
        if(!strcmp(name, "rX"))             ObjectInfo[i][oRX]          = floatstr(value);
        if(!strcmp(name, "rY"))             ObjectInfo[i][oRY]          = floatstr(value);
        if(!strcmp(name, "rZ"))             ObjectInfo[i][oRZ]          = floatstr(value);

        ObjectInfo[i][oObjectID] = CreateObjectEx(ObjectInfo[i][oModelID], ObjectInfo[i][oX], ObjectInfo[i][oY], ObjectInfo[i][oZ]);
    }
    return true;
}
Reply
#2

Hello?! 10th page..
Reply
#3

You had a break in the saving loop and you were trying to parse every objects' data from 1 object file.

I tried to fix it:
pawn Код:
stock SaveObjects()
{
    for(new i = 0, INI:Objects; i < MAX_CREATED_OBJECTS; i++)
    {
        Objects = INI_Open(ObjectFile(i));
        INI_WriteFloat  (Objects,   "oX",           ObjectInfo[i][oX]);
        INI_WriteFloat  (Objects,   "oY",           ObjectInfo[i][oY]);
        INI_WriteFloat  (Objects,   "oZ",           ObjectInfo[i][oZ]);
        INI_WriteFloat  (Objects,   "rX",           ObjectInfo[i][oRX]);
        INI_WriteFloat  (Objects,   "rY",           ObjectInfo[i][oRY]);
        INI_WriteFloat  (Objects,   "rZ",           ObjectInfo[i][oRZ]);
        INI_Close(Objects);
    }
    return true;
}

stock LoadObjects()
{
    for(new i = 0; i < MAX_CREATED_OBJECTS; i++)
    {
        INI_ParseFile(ObjectFile(i), "LoadCreatedObjects", .bExtra = true, .extra = i);
       
        ObjectInfo[i][oObjectID] = CreateObjectEx(ObjectInfo[i][oModelID], ObjectInfo[i][oX], ObjectInfo[i][oY], ObjectInfo[i][oZ]);
        ObjectInfo[i][oDescriptionLabel] = Create3DTextLabel(ObjectInfo[i][oDescription], COLOR_NICK, ObjectInfo[i][oX], ObjectInfo[i][oY], ObjectInfo[i][oZ], 100.0, 0);
    }
    return true;
}

forward LoadCreatedObjects(i, name[], value[]);
public LoadCreatedObjects(i, name[], value[])
{
    if(!strcmp(name, "ModelID"))        ObjectInfo[i][oModelID]     = strval(value);
    if(!strcmp(name, "oX"))             ObjectInfo[i][oX]           = floatstr(value);
    if(!strcmp(name, "oY"))             ObjectInfo[i][oY]           = floatstr(value);
    if(!strcmp(name, "oZ"))             ObjectInfo[i][oZ]           = floatstr(value);
    if(!strcmp(name, "rX"))             ObjectInfo[i][oRX]          = floatstr(value);
    if(!strcmp(name, "rY"))             ObjectInfo[i][oRY]          = floatstr(value);
    if(!strcmp(name, "rZ"))             ObjectInfo[i][oRZ]          = floatstr(value);
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)