Problem loading object data with y_ini
#1

I have converted this speed camera system from default samp file saving/loading system to Y_INI

Everything works fine, the camera's data are saved in a ini file, but when the gamemode is started, cameras aren't loading, i can still see the saved ini files but they aren't loading ingame. Whats wrong with it?

pawn Код:
CMD:addcam(playerid, params[])
{
    new
        Float:x,
        Float:y,
        Float:z,
        Float:Angle,
        MaxSpeed,
        string[70]
    ;

    if (pInfo[playerid][AdminLevel] < 4)
        return 0;

    if (sscanf(params, "i", MaxSpeed)) return SCM(playerid, GRAY, "Usage: /addcam <Max Speed>");
    if(MaxSpeed > 120 || MaxSpeed < 60) return SCM(playerid, RED, "Please use the Max-Speed between 60 to 120.");
    GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, Angle); z = z - 1.0;
    SetPlayerPos(playerid, x, y + 1.0, z + 1.0);
    for (new CamID; CamID < MAX_CAMERAS; CamID++)
    {
        if (gCameras[CamID][CamSpeed] == 0)
        {
            SetupSpeedCamera(CamID, x, y, z, Angle, MaxSpeed);
            new INI:CamFile = INI_Open(Camera_Path(CamID));
            INI_SetTag(CamFile, "data");
            INI_WriteFloat(CamFile, "CamX", x);
            INI_WriteFloat(CamFile, "CamY", y);
            INI_WriteFloat(CamFile, "CamZ", z);
            INI_WriteFloat(CamFile, "CamAngle", Angle);
            INI_WriteInt(CamFile, "CamSpeed", MaxSpeed);
            INI_Close(CamFile);
            format(string, sizeof(string), "You've created a speed camera with ID: %i.", CamID);
            SCM(playerid, AD_COLOR_ACTION, string);
            SendAdminCmd(playerid, "ADDCAM", params);
            return 1;
        }
    }
    format(string, sizeof(string), "You cannot create more than %i speedcameras.", MAX_CAMERAS);
    SCM(playerid, RED, string);
    return 1;
}

//In OnGameModeInit()
for (new CamID; CamID < MAX_CAMERAS; CamID++)
    if(fexist(Camera_Path(CamID)))
        INI_ParseFile(Camera_Path(CamID), "LoadCamera_%s", .bExtra = true, .extra = CamID);
       
forward LoadCamera_data(CamID, name[], value[]);
public LoadCamera_data(CamID, name[], value[])
{
    new INI:CamFile = INI_Open(Camera_Path(CamID));
    new Float:x, Float:y, Float:z, Float:rot, MaxSpeed;

    INI_Float("CamX", x);
    INI_Float("CamY", y);
    INI_Float("CamZ", z);
    INI_Float("CamAngle", rot);
    INI_Int("CamSpeed", MaxSpeed);
    INI_Close(CamFile);
    SetupSpeedCamera(CamID, x, y, z, rot, MaxSpeed);
    TotalCameras++;
    return 1;
}

stock Camera_Path(CamID)
{
    new string[40];
    format(string, sizeof(string), "/Cameras/Cam%i.ini", CamID);
    return string;
}

SetupSpeedCamera(CamID, Float:x, Float:y, Float:z, Float:rot, MaxSpeed)
{
    gCameras[CamID][CamX] = x;
    gCameras[CamID][CamY] = y;
    gCameras[CamID][CamZ] = z;
    gCameras[CamID][CamAngle] = rot;
    gCameras[CamID][CamSpeed] = MaxSpeed;
    gCameras[CamID][CamObj1] = CreateDynamicObject(3335, x, y, z, 0.0, 0.0, rot);
    gCameras[CamID][CamObj2] = CreateDynamicObject(3335, x, y, z, 0.0, 0.0, rot + 180.0);
    new cam_text[50];
    format(cam_text, sizeof(cam_text), "Slow down!\nMax Speed: %i KPH", MaxSpeed);
    gCameras[CamID][SpeedText] = Create3DTextLabel(cam_text, YELLOW,  x, y, z + 2.3, 80.0,0);
}
Someone please help fast, i need to fix this asap.
Reply
#2

/Bump

Someone help me to fix it.
Reply
#3

It's been almost an year since I've used y_INI, I'm not quite sure about this but I guess the mistake you did was over INI_ParseFile. The loading callback is "LoadCamera_data" and on INI_ParseFile, the output looks like "LoadCamera_1" (if CamID = 1). It should be :
pawn Код:
INI_ParseFile(path, "LoadCamera_data", .bExtra = true, .extra = camID)
camID would fill the camID parameter under the callback : LoadCamera_data. My apologies if this is wrong, feel free to correct me.
Reply
#4

Nope, that didn't work as well :/ still same thing, cameras aren't loading but they are saved.

I have tried every possible ways that i know of Y_ini so far, but no luck. Any more help?
Reply
#5

/Bump again, sorry for bumping too earlier but i need to fix this. I didn't find any other ways to get it working.
Reply
#6

pawn Код:
public OnGameModeInit()
{
    for (new CamID; CamID < MAX_CAMERAS; CamID++)
    {
        if(fexist(Camera_Path(CamID)))
        {
            INI_ParseFile(Camera_Path(CamID), "LoadCamera_%s", .bExtra = true, .extra = CamID);
            gCameras[CamID][SpeedText] = Create3DTextLabel(cam_text, YELLOW,  x, y, z + 2.3, 80.0,0);
            gCameras[CamID][CamObj1] = CreateDynamicObject(3335, x, y, z, 0.0, 0.0, rot);
            gCameras[CamID][CamObj2] = CreateDynamicObject(3335, x, y, z, 0.0, 0.0, rot + 180.0);
        }
    }
}

forward LoadCamera_data(CamID, name[], value[]);
public LoadCamera_data(CamID, name[], value[])
{
    INI_Float("CamX", gCameras[CamID][CamX]);
    INI_Float("CamY", gCameras[CamID][CamY]);
    INI_Float("CamZ", gCameras[CamID][CamZ]);
    INI_Float("CamAngle", gCameras[CamID][CamAngle]);
    INI_Int("CamSpeed", gCameras[CamID][CamSpeed]);
    return 1;
}
Reply
#7

I did something like you posted and its working now. Thanks very much.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)