Load vehicle sqlite problem
#1

pawn Код:
LoadVehicle()
{
    new query[2048];
    Result = db_query(USERDB,"SELECT * FROM `Vehicles`");
    for(new a;a<db_num_rows(Result);a++)
    {
        db_get_field_assoc(Result,"Model",query,sizeof(query));
        V_Data[a][Model]=strval(query);
        db_get_field_assoc(Result,"Plate",query,sizeof(query));
        V_Data[a][Plate]=strval(query);
        db_get_field_assoc(Result,"PosX",query,sizeof(query));
        V_Data[a][vPosX]=strval(query);
        db_get_field_assoc(Result,"PosY",query,sizeof(query));
        V_Data[a][vPosY]=strval(query);
        db_get_field_assoc(Result,"PosZ",query,sizeof(query));
        V_Data[a][vPosZ]=strval(query);
        db_get_field_assoc(Result,"Rot",query,sizeof(query));
        V_Data[a][vRot]=strval(query);
        V_Data[a][ID] = AddStaticVehicleEx(V_Data[a][Model],V_Data[a][vPosX],V_Data[a][vPosY],V_Data[a][vPosZ],V_Data[a][vRot],1,1,-1);
        SetVehicleNumberPlate(V_Data[a][ID],V_Data[a][Plate]);
        db_next_row(Result);
    }
    return 1;
}

The only one that loaded correctly just "V_Data[a][Model]". "V_Data[a][vPosX]" return "1283.000000" instead "1283.733276" (Same as "V_Data[a][vPosY]" "V_Data[a][vPosZ]" "V_Data[a][vRot]"). It won't load numbers after dot(.)
Also it won't load the plate.
Reply
#2

pawn Код:
format(Query, sizeof(Query), "SELECT * FROM `VEHICLES` WHERE `CARID` = '%d'", cID);
Result = db_query(Database,Query);
if(db_num_rows(Result))
{
    new Field[20];
    db_get_field_assoc(Result, "CARID", Field, 30);
    gVehicleData[cID][E_CARID] = strval(Field);
}
I usally do it like this, I have never used your way of loading before though mine works perfectly
Reply
#3

What's the different between yours and mine?
Reply
#4

The reason it is not saving the information after the dot(.) is because you are using the strval function to retrieve floats. strval saves the string as an integer. Try using the function floatstr for your floats instead. That should read the string and save them as floats. You can see an example of it in action in the wiki here: https://sampwiki.blast.hk/wiki/Floatstr

Also, if the value you are retrieving from the database is to be stored as a string (which it looks like your Plate should be), you can store it into a string variable using the format function.

With these changes, your code should look something like this:
pawn Код:
LoadVehicle()
{
    new query[2048];
    Result = db_query(USERDB,"SELECT * FROM `Vehicles`");
    for(new a;a<db_num_rows(Result);a++)
    {
        db_get_field_assoc(Result,"Model",query,sizeof(query));
        V_Data[a][Model]=strval(query);
        db_get_field_assoc(Result,"Plate",query,sizeof(query));
        format(V_Data[a][Plate], sizeof(V_Data[a][Plate]), "%s", query);
        db_get_field_assoc(Result,"PosX",query,sizeof(query));
        V_Data[a][vPosX]=floatstr(query);
        db_get_field_assoc(Result,"PosY",query,sizeof(query));
        V_Data[a][vPosY]=floatstr(query);
        db_get_field_assoc(Result,"PosZ",query,sizeof(query));
        V_Data[a][vPosZ]=floatstr(query);
        db_get_field_assoc(Result,"Rot",query,sizeof(query));
        V_Data[a][vRot]=floatstr(query);
        V_Data[a][ID] = AddStaticVehicleEx(V_Data[a][Model],V_Data[a][vPosX],V_Data[a][vPosY],V_Data[a][vPosZ],V_Data[a][vRot],1,1,-1);
        SetVehicleNumberPlate(V_Data[a][ID],V_Data[a][Plate]);
        db_next_row(Result);
    }
    return 1;
}
Give that a go and see if you get it any closer to working. Good luck!
Reply
#5

Bump for more problem. (I hate make another thread)

I have this
pawn Код:
db_get_field_assoc(Result,"MDCname",query,sizeof(query));
format(V_Data[a][MDCname],MAX_PLAYER_NAME,"%s",query);
But why it's only load the first letter. Example: Jayden Horse. it's only load "J".

NVM, wiki lead my way.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)