[SQLite] Cameras not loading at their position
#1

The same problem I had with House saving/loading.
The cameras are being loaded at the position "0 0 0".
When i view the info via SQLite browser, the X, Y, Z and Angle is in the original/needed spot, but it just loads/spawns at 0 0 0

I use these functions;
pawn Код:
stock SaveCameras()
{
    new Query[120];
    new DBResult:Result;
    for (new CamID = 1; CamID < MAX_CAMERAS; CamID++)
    {
        format(Query, sizeof(Query), "SELECT * FROM `CAMERAS` WHERE `ID` = '%d'", CamID);
        Result = db_query(CnR, Query);
        if(db_num_rows(Result))
        {
            format(Query,sizeof(Query),"UPDATE `CAMERAS` SET `X` = '%.4f', `Y` = '%.4f', `Z` = '%.4f', `ANGLE` = '%.4f', `SPEED` = '%d' WHERE `ID` = '%d'",
            ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ], ACameras[CamID][CamAngle], ACameras[CamID][CamSpeed], ACameras[CamID][ID]);
            Result = db_query(CnR, Query);
           
            printf("[debug] saved camera %d", CamID);
        }
    }
}
stock LoadCameras()
{
    new Query[92], Field[70], string[90];
    new DBResult:Result;
    new
        Float:X,
        Float:Y,
        Float:Z,
        Float:Angle,
        MaxSpeed
    ;
    for (new CamID = 1; CamID < MAX_CAMERAS; CamID++)
    {
        format(Query, sizeof(Query), "SELECT * FROM `CAMERAS` WHERE `ID` = '%d'", CamID);
        Result = db_query(CnR, Query);
        if(db_num_rows(Result))
        {
            db_get_field_assoc(Result, "ID", Field, 2); ACameras[CamID][ID] = strval(Field);
            db_get_field_assoc(Result, "X", Field, 10); ACameras[CamID][CamX] = floatstr(Field);
            db_get_field_assoc(Result, "Y", Field, 10); ACameras[CamID][CamY] = floatstr(Field);
            db_get_field_assoc(Result, "Z", Field, 10); ACameras[CamID][CamZ] = floatstr(Field);
            db_get_field_assoc(Result, "ANGLE", Field, 10); ACameras[CamID][CamAngle] = floatstr(Field);
            db_get_field_assoc(Result, "SPEED", Field, 3); ACameras[CamID][CamSpeed] = strval(Field);
           
            ACameras[CamID][CamX] = X;
            ACameras[CamID][CamY] = Y;
            ACameras[CamID][CamZ] = Z;
            ACameras[CamID][CamAngle] = Angle;
            ACameras[CamID][CamSpeed] = MaxSpeed;
           
            SetupSpeedCamera(CamID, X, Y, Z, Angle, MaxSpeed);
            format(string, sizeof(string), "{00C0FF}Speed-Camera\n{FFCC66}Speed limit: %i", MaxSpeed);
            CamSpeedText[CamID] = Create3DTextLabel(string, -1, X, Y, Z+5, Angle, 0, 0);
           
            printf("[debug] loaded and set camera %d", CamID);
        }
    }
}

SetupSpeedCamera(CamID, Float:x, Float:y, Float:z, Float:rot, MaxSpeed)
{
    ACameras[CamID][CamX] = x;
    ACameras[CamID][CamY] = y;
    ACameras[CamID][CamZ] = z;
    ACameras[CamID][CamAngle] = rot;
    ACameras[CamID][CamSpeed] = MaxSpeed;
    ACameras[CamID][CamObj1] = CreateObject(18880, x, y, z, 0.0, 0.0, rot);
    ACameras[CamID][CamObj2] = CreateObject(18880, x, y, z, 0.0, 0.0, rot + 180.0);
}
Reply
#2

pawn Код:
db_get_field_assoc(Result, "ID", Field, 2); ACameras[CamID][ID] = strval(Field);
            db_get_field_assoc(Result, "X", Field, 10); ACameras[CamID][CamX] = floatstr(Field);
            db_get_field_assoc(Result, "Y", Field, 10); ACameras[CamID][CamY] = floatstr(Field);
            db_get_field_assoc(Result, "Z", Field, 10); ACameras[CamID][CamZ] = floatstr(Field);
            db_get_field_assoc(Result, "ANGLE", Field, 10); ACameras[CamID][CamAngle] = floatstr(Field);
            db_get_field_assoc(Result, "SPEED", Field, 3); ACameras[CamID][CamSpeed] = strval(Field);
           
            ACameras[CamID][CamX] = X; // delete from this one to the end..
            ACameras[CamID][CamY] = Y;
            ACameras[CamID][CamZ] = Z;
            ACameras[CamID][CamAngle] = Angle;
            ACameras[CamID][CamSpeed] = MaxSpeed;
You stored them fine to ACameras array so why do you assign the values of X, Y, Z, Angle and MaxSpeed after that which are by default 0? Just remove them.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
db_get_field_assoc(Result, "ID", Field, 2); ACameras[CamID][ID] = strval(Field);
            db_get_field_assoc(Result, "X", Field, 10); ACameras[CamID][CamX] = floatstr(Field);
            db_get_field_assoc(Result, "Y", Field, 10); ACameras[CamID][CamY] = floatstr(Field);
            db_get_field_assoc(Result, "Z", Field, 10); ACameras[CamID][CamZ] = floatstr(Field);
            db_get_field_assoc(Result, "ANGLE", Field, 10); ACameras[CamID][CamAngle] = floatstr(Field);
            db_get_field_assoc(Result, "SPEED", Field, 3); ACameras[CamID][CamSpeed] = strval(Field);
           
            ACameras[CamID][CamX] = X; // delete from this one to the end..
            ACameras[CamID][CamY] = Y;
            ACameras[CamID][CamZ] = Z;
            ACameras[CamID][CamAngle] = Angle;
            ACameras[CamID][CamSpeed] = MaxSpeed;
You stored them fine to ACameras array so why do you assign the values of X, Y, Z, Angle and MaxSpeed after that which are by default 0? Just remove them.
I remember seeing one tutorial/script having that d:
Anyways, removed and it works now, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)