Vehicles loading from DB but not spawning?
#1

Basically put, I load my vehicles from the database and they do load as found in the log (see below) but they don't actually spawn? Strange right?

Quote:

[19:03:42] >> mysql_query( Connection handle: 1 )

[19:03:42] CMySQLHandler::Query(SELECT * FROM vehicles WHERE ID = '0') - Successfully executed.

[19:03:42] >> mysql_store_result( Connection handle: 1 )

[19:03:42] CMySQLHandler::StoreResult() - Result was stored.

[19:03:42] >> mysql_retrieve_row( Connection handle: 1 )

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("ID") - 0

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("Model") - 560

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("PosX") - 1582.21

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("PosY") - -1303.5

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("PosZ") - 17.3694

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("Angle") - 0

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("Interior") - 0

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("World") - 0

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("Color1") - 1

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("Color2") - 1

[19:03:42] >> mysql_fetch_field_row( Connection handle: 1 )

[19:03:42] CMySQLHandler::FetchField("Faction") - 0

[19:03:42] >> mysql_free_result( Connection handle: 1 )

[19:03:42] CMySQLHandler::FreeResult() - Result was successfully free'd.

And my load vehicle function:

pawn Код:
public LoadVehicles(vehid)
{
    format(mainstring,sizeof(mainstring),"SELECT * FROM vehicles WHERE ID = '%d'",vehid);
    mysql_query(mainstring);
    mysql_store_result();
    new result[64];
    if(mysql_retrieve_row())
    {
        mysql_fetch_field_row(result,"ID");
        VehicleInfo[vehid][cID] = strval(result);
        mysql_fetch_field_row(result,"Model");
        VehicleInfo[vehid][cID] = strval(result);
        mysql_fetch_field_row(result,"PosX");
        VehicleInfo[vehid][cPosX] = floatstr(result);
        mysql_fetch_field_row(result,"PosY");
        VehicleInfo[vehid][cPosY] = floatstr(result);
        mysql_fetch_field_row(result,"PosZ");
        VehicleInfo[vehid][cPosZ] = floatstr(result);
        mysql_fetch_field_row(result,"Angle");
        VehicleInfo[vehid][cAngle] = floatstr(result);
        mysql_fetch_field_row(result,"Interior");
        VehicleInfo[vehid][cInterior] = strval(result);
        mysql_fetch_field_row(result,"World");
        VehicleInfo[vehid][cWorld] = strval(result);
        mysql_fetch_field_row(result,"Color1");
        VehicleInfo[vehid][cColor1] = strval(result);
        mysql_fetch_field_row(result,"Color2");
        VehicleInfo[vehid][cColor2] = strval(result);
        mysql_fetch_field_row(result,"Faction");
        VehicleInfo[vehid][cFaction] = strval(result);
        VehicleInfo[vehid][cAlarm] = 0;
        VehicleInfo[vehid][cEngine] = 0;
        VehicleInfo[vehid][cFuel] = 100.0;
        AddStaticVehicle(VehicleInfo[vehid][cModel],VehicleInfo[vehid][cPosX],VehicleInfo[vehid][cPosY],VehicleInfo[vehid][cPosZ],VehicleInfo[vehid][cAngle],VehicleInfo[vehid][cColor1],VehicleInfo[vehid][cColor2]);
        LinkVehicleToInterior(vehid,VehicleInfo[vehid][cInterior]);
        SetVehicleVirtualWorld(vehid,VehicleInfo[vehid][cWorld]);
    }
    mysql_free_result();
    return 1;
}
Reply
#2

pawn Код:
public LoadVehicles()
{
    mysql_query("SELECT * FROM vehicles");
    mysql_store_result();
    new result[64], vehid;
    while(mysql_retrieve_row())
    {
        vehid ++;
        mysql_fetch_field_row(result,"ID");
        VehicleInfo[vehid][cID] = strval(result);
        mysql_fetch_field_row(result,"Model");
        VehicleInfo[vehid][cID] = strval(result);
        mysql_fetch_field_row(result,"PosX");
        VehicleInfo[vehid][cPosX] = floatstr(result);
        mysql_fetch_field_row(result,"PosY");
        VehicleInfo[vehid][cPosY] = floatstr(result);
        mysql_fetch_field_row(result,"PosZ");
        VehicleInfo[vehid][cPosZ] = floatstr(result);
        mysql_fetch_field_row(result,"Angle");
        VehicleInfo[vehid][cAngle] = floatstr(result);
        mysql_fetch_field_row(result,"Interior");
        VehicleInfo[vehid][cInterior] = strval(result);
        mysql_fetch_field_row(result,"World");
        VehicleInfo[vehid][cWorld] = strval(result);
        mysql_fetch_field_row(result,"Color1");
        VehicleInfo[vehid][cColor1] = strval(result);
        mysql_fetch_field_row(result,"Color2");
        VehicleInfo[vehid][cColor2] = strval(result);
        mysql_fetch_field_row(result,"Faction");
        VehicleInfo[vehid][cFaction] = strval(result);
        VehicleInfo[vehid][cAlarm] = 0;
        VehicleInfo[vehid][cEngine] = 0;
        VehicleInfo[vehid][cFuel] = 100.0;
        AddStaticVehicle(VehicleInfo[vehid][cModel],VehicleInfo[vehid][cPosX],VehicleInfo[vehid][cPosY],VehicleInfo[vehid][cPosZ],VehicleInfo[vehid][cAngle],VehicleInfo[vehid][cColor1],VehicleInfo[vehid][cColor2]);
        LinkVehicleToInterior(vehid,VehicleInfo[vehid][cInterior]);
        SetVehicleVirtualWorld(vehid,VehicleInfo[vehid][cWorld]);
    }
    mysql_free_result();
    return 1;
}
Do that instead
Reply
#3

Tried that bud but it's still not spawning the vehicles, unfortunately.
Reply
#4

Quote:
Originally Posted by Corello2010
Посмотреть сообщение
Tried that bud but it's still not spawning the vehicles, unfortunately.
Could you please post your MySQL log of the code I posted?
Reply
#5

Код:
19:38:46] CMySQLHandler::Query(SELECT * FROM vehicles) - Successfully executed.

[19:38:46] >> mysql_store_result( Connection handle: 1 )

[19:38:46] CMySQLHandler::StoreResult() - Result was stored.

[19:38:46] >> mysql_retrieve_row( Connection handle: 1 )

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("ID") - 1

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Model") - 560

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("PosX") - -352.641

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("PosY") - 1529.25

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("PosZ") - 75.3594

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Angle") - 0

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Interior") - 0

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("World") - 0

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Color1") - 1

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Color2") - 1

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Faction") - 0

[19:38:46] >> mysql_retrieve_row( Connection handle: 1 )

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("ID") - 0

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Model") - 560

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("PosX") - 1779.37

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("PosY") - 1454.54

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("PosZ") - 13.487

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Angle") - 0

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Interior") - 0

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("World") - 0

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Color1") - 1

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Color2") - 1

[19:38:46] >> mysql_fetch_field_row( Connection handle: 1 )

[19:38:46] CMySQLHandler::FetchField("Faction") - 0

[19:38:46] >> mysql_retrieve_row( Connection handle: 1 )

[19:38:46] >> mysql_free_result( Connection handle: 1 )

[19:38:46] CMySQLHandler::FreeResult() - Result was successfully free'd.
Reply
#6

Are you sure that there is more than 1 vehicle in the table?
Reply
#7

Reply
#8

Alright, I just added

pawn Код:
AddStaticVehicle(560,-386.8285,1544.1665,75.1139,359.9987,3,3); //
instead of the AddStaticVehicle code for the car system and it spawned two Sultans so I'm guessing there's a problem with my shit. Hm. I think I know it.
Reply
#9

You have Define MAX_VEHICLES or w/e on top of your script? if not just add
pawn Код:
public LoadVehicles()
{
    new i;
    mysql_query("SELECT * FROM vehicles");
    mysql_store_result();
    new field[128][128];
    if(mysql_num_rows() != 0)
    {
        VehicleInfo[i][cID] = strval(field[0]);
        VehicleInfo[i][cModel] = strval(field[1]);
        VehicleInfo[i][cPosX] = floatstr(field[2]);
        VehicleInfo[i][cPosY] = floatstr(field[3]);
        VehicleInfo[i][cPosZ] = floatstr(field[4]);
        VehicleInfo[i][cAngle] = floatstr(field[5]);
        VehicleInfo[i][cInterior] = strval(field[6]);
        VehicleInfo[i][cWorld] = strval(field[7]);
        VehicleInfo[i][cColor1] = strval(field[8]);
        VehicleInfo[i][cColor2] = strval(field[9]);
        VehicleInfo[i][cFaction] = strval(field[10]);
        VehicleInfo[i][cAlarm] = 0;
        VehicleInfo[i][cEngine] = 0;
        VehicleInfo[vehid][cFuel] = 100.0;
        AddStaticVehicle(VehicleInfo[i][cModel],VehicleInfo[i][cPosX],VehicleInfo[i][cPosY],VehicleInfo[i][cPosZ],VehicleInfo[i][cAngle],VehicleInfo[i][cColor1],VehicleInfo[i][cColor2]);
        LinkVehicleToInterior(i,VehicleInfo[i][cInterior]);
        SetVehicleVirtualWorld(i,VehicleInfo[i][cWorld]);
    }
    mysql_free_result();
    return 1;
}
if you do add
pawn Код:
public LoadVehicles()
{
    for(new i=1; i<MAX_VEHICLE; i++)//edit the max_vehicle to urs
    {
    mysql_query("SELECT * FROM vehicles WHERE ID = '%d'",i);
    mysql_store_result();
    new field[128][128];
    if(mysql_num_rows() != 0)
    {
        VehicleInfo[i][cID] = strval(field[0]);
        VehicleInfo[i][cModel] = strval(field[1]);
        VehicleInfo[i][cPosX] = floatstr(field[2]);
        VehicleInfo[i][cPosY] = floatstr(field[3]);
        VehicleInfo[i][cPosZ] = floatstr(field[4]);
        VehicleInfo[i][cAngle] = floatstr(field[5]);
        VehicleInfo[i][cInterior] = strval(field[6]);
        VehicleInfo[i][cWorld] = strval(field[7]);
        VehicleInfo[i][cColor1] = strval(field[8]);
        VehicleInfo[i][cColor2] = strval(field[9]);
        VehicleInfo[i][cFaction] = strval(field[10]);
        VehicleInfo[i][cAlarm] = 0;
        VehicleInfo[i][cEngine] = 0;
        VehicleInfo[vehid][cFuel] = 100.0;
        AddStaticVehicle(VehicleInfo[i][cModel],VehicleInfo[i][cPosX],VehicleInfo[i][cPosY],VehicleInfo[i][cPosZ],VehicleInfo[i][cAngle],VehicleInfo[i][cColor1],VehicleInfo[i][cColor2]);
        LinkVehicleToInterior(i,VehicleInfo[i][cInterior]);
        SetVehicleVirtualWorld(i,VehicleInfo[i][cWorld]);
    }
    mysql_free_result();
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
You have Define MAX_VEHICLES or w/e on top of your script? if not just add
pawn Код:
public LoadVehicles()
{
    new i;
    mysql_query("SELECT * FROM vehicles");
    mysql_store_result();
    new field[128][128];
    if(mysql_num_rows() != 0)
    {
        VehicleInfo[i][cID] = strval(field[0]);
        VehicleInfo[i][cModel] = strval(field[1]);
        VehicleInfo[i][cPosX] = floatstr(field[2]);
        VehicleInfo[i][cPosY] = floatstr(field[3]);
        VehicleInfo[i][cPosZ] = floatstr(field[4]);
        VehicleInfo[i][cAngle] = floatstr(field[5]);
        VehicleInfo[i][cInterior] = strval(field[6]);
        VehicleInfo[i][cWorld] = strval(field[7]);
        VehicleInfo[i][cColor1] = strval(field[8]);
        VehicleInfo[i][cColor2] = strval(field[9]);
        VehicleInfo[i][cFaction] = strval(field[10]);
        VehicleInfo[i][cAlarm] = 0;
        VehicleInfo[i][cEngine] = 0;
        VehicleInfo[vehid][cFuel] = 100.0;
        AddStaticVehicle(VehicleInfo[i][cModel],VehicleInfo[i][cPosX],VehicleInfo[i][cPosY],VehicleInfo[i][cPosZ],VehicleInfo[i][cAngle],VehicleInfo[i][cColor1],VehicleInfo[i][cColor2]);
        LinkVehicleToInterior(i,VehicleInfo[i][cInterior]);
        SetVehicleVirtualWorld(i,VehicleInfo[i][cWorld]);
    }
    mysql_free_result();
    return 1;
}
if you do add
pawn Код:
public LoadVehicles()
{
    for(new i=1; i<MAX_VEHICLE; i++)//edit the max_vehicle to urs
    {
    mysql_query("SELECT * FROM vehicles WHERE ID = '%d'",i);
    mysql_store_result();
    new field[128][128];
    if(mysql_num_rows() != 0)
    {
        VehicleInfo[i][cID] = strval(field[0]);
        VehicleInfo[i][cModel] = strval(field[1]);
        VehicleInfo[i][cPosX] = floatstr(field[2]);
        VehicleInfo[i][cPosY] = floatstr(field[3]);
        VehicleInfo[i][cPosZ] = floatstr(field[4]);
        VehicleInfo[i][cAngle] = floatstr(field[5]);
        VehicleInfo[i][cInterior] = strval(field[6]);
        VehicleInfo[i][cWorld] = strval(field[7]);
        VehicleInfo[i][cColor1] = strval(field[8]);
        VehicleInfo[i][cColor2] = strval(field[9]);
        VehicleInfo[i][cFaction] = strval(field[10]);
        VehicleInfo[i][cAlarm] = 0;
        VehicleInfo[i][cEngine] = 0;
        VehicleInfo[vehid][cFuel] = 100.0;
        AddStaticVehicle(VehicleInfo[i][cModel],VehicleInfo[i][cPosX],VehicleInfo[i][cPosY],VehicleInfo[i][cPosZ],VehicleInfo[i][cAngle],VehicleInfo[i][cColor1],VehicleInfo[i][cColor2]);
        LinkVehicleToInterior(i,VehicleInfo[i][cInterior]);
        SetVehicleVirtualWorld(i,VehicleInfo[i][cWorld]);
    }
    mysql_free_result();
    }
    return 1;
}
I know that the solution has been found, but do not do what's in that post. Looping a query is around 70 times slower than just using mysql_retrieve_row.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)