MySQL Load Issue
#1

I have this code:

pawn Код:
forward loadPlayerVehiclesSQL(playerid);
public loadPlayerVehiclesSQL(playerid)
{
    new rows, fields, vehicleid=-1;
   
    cache_get_data(rows, fields, sqlConnection);
   
    for(new i = 0; i < rows && i < 3; i++)
    {
        vehicleid = CreateVehicle(cache_get_field_content_int(0, "Model", sqlConnection), cache_get_field_content_float(0, "X", sqlConnection), cache_get_field_content_float(0, "Y", sqlConnection), cache_get_field_content_float(0, "Z", sqlConnection), cache_get_field_content_float(0, "A", sqlConnection), cache_get_field_content_int(0, "Color1", sqlConnection), cache_get_field_content_int(0, "Color2", sqlConnection), -1);

        PlayerVehicles[vehicleid][pVehicleID] = cache_get_field_content_int(0, "ID", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleModel] = cache_get_field_content_int(0, "Model", sqlConnection);

        cache_get_field_content(0, "Owner", PlayerVehicles[vehicleid][pVehicleOwner], sqlConnection, 24);

        PlayerVehicles[vehicleid][pVehicleColor][1] = cache_get_field_content_int(0, "Color1", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleColor][2] = cache_get_field_content_int(0, "Color2", sqlConnection);

        PlayerVehicles[vehicleid][pVehiclePos][1] = cache_get_field_content_float(0, "X", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][2] = cache_get_field_content_float(0, "Y", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][3] = cache_get_field_content_float(0, "Z", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][4] = cache_get_field_content_float(0, "A", sqlConnection);

        cache_get_field_content(0, "Plate", PlayerVehicles[vehicleid][pVehiclePlate], sqlConnection, 10);

        SetVehicleNumberPlate(vehicleid, PlayerVehicles[vehicleid][pVehiclePlate]);
        SetVehicleToRespawn(vehicleid);

        ChangeVehiclePaintjob(vehicleid, 3);
        ChangeVehicleColor(vehicleid, PlayerVehicles[vehicleid][pVehicleColor][1], PlayerVehicles[vehicleid][pVehicleColor][2]);

        printf("Vehicle %s loaded (%d) from the database.", GetVehicleName(vehicleid), PlayerVehicles[vehicleid][pVehicleID]);
    }
    return 1;
}
It loads the vehicles just right, well - kind of right. It only loads 1, two times.

I have two vehicles in the database (`playervehicles`) table, one which is an Infernus (ID 400) and one which is a Landstalker (ID 401), it's currently loading the Landstalker two times and not touching the Infernus at all.


The system is designed to call upon a player logging in, which would ensure that the vehicles aren't being flooded at all times. Meaning, once logged in - this SQL is called and the vehicles which have the owner of my name are being loaded, then upon logging out, they're destroying. The whole thing is working perfectly, apart from the loading sector of it which is only loading one model, twice.

Any help is appreciated.
Reply
#2

pawn Код:
stock LoadPlayerVehicles(playerid)
{
    new query[128];
    mysql_format(sqlConnection, query, sizeof(query), "SELECT * FROM `playervehicles` WHERE `Owner`='%e'", playerName(playerid));
    mysql_function_query(sqlConnection, query, false, "loadPlayerVehiclesSQL", "i", playerid);
    return 1;
}
Here is the load function, anyone?
Reply
#3

Quote:
Originally Posted by RedCounty
Посмотреть сообщение
pawn Код:
for(new i = 0; i < rows && i < 3; i++)
This part of the loop is most likely causing the issue:

pawn Код:
i < 3;
Try changing the operator to "<=" instead of "<".


EDIT: I just re-read your post and realize how illogical my solution sounds. Either way, it's still worth a try.
Reply
#4

I don't know why are you making a loop as you're not even using it,

try this
pawn Код:
forward loadPlayerVehiclesSQL(playerid);
public loadPlayerVehiclesSQL(playerid)
{
    new rows, fields, vehicleid=-1;

    cache_get_data(rows, fields, sqlConnection);

    for(new i; i < rows; i++)
    {
        vehicleid = CreateVehicle(cache_get_field_content_int(i, "Model", sqlConnection), cache_get_field_content_float(i, "X", sqlConnection), cache_get_field_content_float(i, "Y", sqlConnection), cache_get_field_content_float(i, "Z", sqlConnection), cache_get_field_content_float(i, "A", sqlConnection), cache_get_field_content_int(i, "Color1", sqlConnection), cache_get_field_content_int(i, "Color2", sqlConnection), -1);

        PlayerVehicles[vehicleid][pVehicleID] = cache_get_field_content_int(i, "ID", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleModel] = cache_get_field_content_int(i, "Model", sqlConnection);

        cache_get_field_content(i, "Owner", PlayerVehicles[vehicleid][pVehicleOwner], sqlConnection, 24);
        cache_get_field_content(i, "Plate", PlayerVehicles[vehicleid][pVehiclePlate], sqlConnection, 10);

        PlayerVehicles[vehicleid][pVehicleColor][1] = cache_get_field_content_int(i, "Color1", sqlConnection);
        PlayerVehicles[vehicleid][pVehicleColor][2] = cache_get_field_content_int(i, "Color2", sqlConnection);

        PlayerVehicles[vehicleid][pVehiclePos][1] = cache_get_field_content_float(i, "X", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][2] = cache_get_field_content_float(i, "Y", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][3] = cache_get_field_content_float(i, "Z", sqlConnection);
        PlayerVehicles[vehicleid][pVehiclePos][4] = cache_get_field_content_float(i, "A", sqlConnection);

        SetVehicleNumberPlate(vehicleid, PlayerVehicles[vehicleid][pVehiclePlate]);
        SetVehicleToRespawn(vehicleid);
       
        ChangeVehiclePaintjob(vehicleid, 3);
        ChangeVehicleColor(vehicleid, PlayerVehicles[vehicleid][pVehicleColor][1], PlayerVehicles[vehicleid][pVehicleColor][2]);

        printf("Vehicle %s loaded (%d) from the database.", GetVehicleName(vehicleid), PlayerVehicles[vehicleid][pVehicleID]);
    }
    return 1;
}
and if it didn't work please show me how do you save cars.
Reply
#5

I found the issue out as you posted above, it's because I didn't have it looping lol.

Thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)