Mysql Vehicle Load Issue/bug
#1

Well, I can't figure out this issue in this code, so hopefully someone on these forums could.

Here's the debug log, it shows that it's working:

pawn Код:
CMySQLHandler::FetchRow() - Return: 1|TWF-6561|560|103.146|1.17058|0.797754|0|1|1|State|42
Here's the loading:

pawn Код:
stock LoadCars()
{
    new Query[255];
    for(new id; id < MAX_CARS; id++)
    {
        format(Query, sizeof(Query), "SELECT * FROM Vehicles WHERE ID = %d", id);
        mysql_query(Query);
        mysql_store_result();
        if(mysql_num_rows())
        if(mysql_fetch_row_format(Query,"|"))
        {
            sscanf(Query, "p<|>e<iffff>", Vehicles[id]);
             printf("Model = %i",Vehicles[id][Model]);
            CreateVehicle(Vehicles[id][Model],Vehicles[id][Posx],Vehicles[id][Posy],Vehicles[id][Posz],Vehicles[id][Posa],1,1, 60*10000);
            printf("Model = %i",Vehicles[id][Model]);
           
        }
    }
}

On the printf it says:

pawn Код:
12:16:18] Model = 0
[12:16:18] Model = 0
[12:16:24] Server has been started.
[12:16:24] Number of vehicle models: 0
It shows no vehicles models, and the model comes out as 0 on there, which I can't understand.

Here's my enum:

pawn Код:
enum cars            
{
    Plate[12],
    Model,
    Float:Posx,
    Float:Posy,
    Float:Posz,
    Float:Posa,
    Color1,
    Color2,
    Owner[32],
    Fuel
};

Thanks in advance to anyone who posts.
Reply
#2

id++;
Reply
#3

Quote:
Originally Posted by gabitzu4ever
Посмотреть сообщение
id++;
What?
Reply
#4

I think its because the sscanf specifiers don't match your enum. There is an array before the int and floats. I've never used sscanf with enums before so i'm not sure.
Reply
#5

pawn Код:
sscanf(Query, "p<|>e<is[32]iffffiis[24]i>", Vehicles[id]);

enum cars            
{
    cID,
    Plate[32],
    Model,
    Float:Posx,
    Float:Posy,
    Float:Posz,
    Float:Posa,
    Color1,
    Color2,
    Owner[MAX_PLAYER_NAME],
    Fuel
};
I'm not 100% sure this will work because I don't know what do you have in your table.
Reply
#6

Quote:
Originally Posted by fordawinzz
Посмотреть сообщение
pawn Код:
sscanf(Query, "p<|>e<is[32]iffffiis[24]i>", Vehicles[id]);

enum cars            
{
    cID,
    Plate[32],
    Model,
    Float:Posx,
    Float:Posy,
    Float:Posz,
    Float:Posa,
    Color1,
    Color2,
    Owner[MAX_PLAYER_NAME],
    Fuel
};
Thats how it should be but your query doesn't return data in that order

EDIT: oops it does if you use that^^ enum.
Reply
#7

Yeah, it will do because he uses the 'ID' row in his table but it is not in his enum, that's why his system won't work

EDIT: Try using my code, it should work.
Reply
#8

pawn Код:
ID
Plate  
Model
Posx
Posy
Posz
Posa   
Color1
Color2
Owner
Fuel
That's my table on PHP
Reply
#9

Yeah i edited my post 3 secs after posting it . Use fordawinzz enum and sscanf line, should work.
Reply
#10

Thanks guys, It worked this time =]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)