No carga bien [Sistema de vehiculos MySQL]
#1

Hola, estoy creando un sistema de vehiculos en MySQL pero no manejo bien la version r7, tengo esto:

pawn Код:
#define MAXIMO_VEHICULOS        (3)
#define TIEMPO_RESPAWN          (180000)

public OnGameModeInit()
{
   CargarVehiculos();
}
public OnQueryFinish(resultid, extraid, ConnectionHandle)
{
    new Rows, Field;
    if(resultid != 0)
    {
        cache_get_data(Rows, Field);
    }
    switch(resultid)
    {
        case 3:
        {
            for( new i = 1; i < MAXIMO_VEHICULOS; i++ )
            {
                new content[12];
                cache_get_field_content(0, "propietario", VehiculosInfo[i][vpropietario]);
                cache_get_field_content(0, "precio", content); VehiculosInfo[i][vprecio] = strval(content);
                cache_get_field_content(0, "modelo", content); VehiculosInfo[i][vmodelo] = strval(content);
                cache_get_field_content(0, "x", content); VehiculosInfo[i][vx] = floatstr(content);
                cache_get_field_content(0, "y", content); VehiculosInfo[i][vy] = floatstr(content);
                cache_get_field_content(0, "z", content); VehiculosInfo[i][vz] = floatstr(content);
                cache_get_field_content(0, "a", content); VehiculosInfo[i][va] = floatstr(content);
                cache_get_field_content(0, "color1", content); VehiculosInfo[i][vcolor1] = strval(content);
                cache_get_field_content(0, "color2", content); VehiculosInfo[i][vcolor2] = strval(content);
                cache_get_field_content(0, "comprable", content); VehiculosInfo[i][vcomprable] = strval(content);
                VehiculosInfo[i][vID] = i;
               
                CreateVehicle(VehiculosInfo[i][vmodelo], VehiculosInfo[i][vx], VehiculosInfo[i][vy], VehiculosInfo[i][vz], VehiculosInfo[i][va], VehiculosInfo[i][vcolor1], VehiculosInfo[i][vcolor2], TIEMPO_RESPAWN);
                new stringinfovehiculo[67+1], stringinfovehiculo2[61+1];
                if(VehiculosInfo[i][vcomprable] == 1)
                {
                    printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: Comprable", i);
                    if(!strcmp("nadie",VehiculosInfo[i][vpropietario],true))
                    {
                        format(stringinfovehiculo, sizeof(stringinfovehiculo), "{F6FF00}VEHНCULO EN VENTA\n{FFFFFF}Precio: $%d\nID: %d", VehiculosInfo[i][vprecio], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                    else
                    {
                        format(stringinfovehiculo2, sizeof(stringinfovehiculo2), "{F6FF00}Dueсo: %s\n{FFFFFF}ID: %d", VehiculosInfo[i][vpropietario], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo2, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                } else printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: No Comprable", i);
                Vehiculos_Creados++;
            }
            printf("[Vehiculos] Se han cargado %d vehiculos", Vehiculos_Creados++);
        }
    }
    return 1;
}
stock CargarVehiculos()
{
    mysql_function_query(Conexion, "SELECT * FROM vehiculos", true, "OnQueryFinish", "i", 3);
}
Tengo dos vehiculos en la base de datos y solo carga uno, lo que pasa es que supongo que es porque no pongo SELECT * FROM vehiculos WHERE id = '%d' en CargarVehiculos(), pero es que no entiendo como hacerlo con MySQL r7 ya que cuando pongo eso se me duplican, no se si me entienden, espero que alguien me pueda ayudar.

Saludos

Edit: Me carga dos autos iguales, osea me carga 2 pero con los datos de 1 solo.
Reply
#2

EDIT: El error estб en OnQueryFinish, ahora me fijo bien.
Reply
#3

Yo antes tenнa tu mismo error: їsoluciуn?
pawn Код:
#define MAXIMO_VEHICULOS        (3)
#define TIEMPO_RESPAWN          (180000)

public OnGameModeInit()
{
   CargarVehiculos();
}
public OnQueryFinish(resultid, extraid, ConnectionHandle)
{
    new Rows, Field;
    if(resultid != 0)
    {
        cache_get_data(Rows, Field);
    }
    switch(resultid)
    {
        case 3:
        {
            cache_get_data(Rows,Field, Conexion); //obtenemos los datos
            for( new i = 1; i < Rows; i++ ) //bucle por todos los vehнculos
            {
                new content[12]; //te recomiendo tenerla en 32 si queres obtener el dueсo o algo
                cache_get_field_content(0, "propietario", VehiculosInfo[i][vpropietario]);
                cache_get_field_content(0, "precio", content); VehiculosInfo[i][vprecio] = strval(content);
                cache_get_field_content(0, "modelo", content); VehiculosInfo[i][vmodelo] = strval(content);
                cache_get_field_content(0, "x", content); VehiculosInfo[i][vx] = floatstr(content);
                cache_get_field_content(0, "y", content); VehiculosInfo[i][vy] = floatstr(content);
                cache_get_field_content(0, "z", content); VehiculosInfo[i][vz] = floatstr(content);
                cache_get_field_content(0, "a", content); VehiculosInfo[i][va] = floatstr(content);
                cache_get_field_content(0, "color1", content); VehiculosInfo[i][vcolor1] = strval(content);
                cache_get_field_content(0, "color2", content); VehiculosInfo[i][vcolor2] = strval(content);
                cache_get_field_content(0, "comprable", content); VehiculosInfo[i][vcomprable] = strval(content);
                VehiculosInfo[i][vID] = i;
               
                CreateVehicle(VehiculosInfo[i][vmodelo], VehiculosInfo[i][vx], VehiculosInfo[i][vy], VehiculosInfo[i][vz], VehiculosInfo[i][va], VehiculosInfo[i][vcolor1], VehiculosInfo[i][vcolor2], TIEMPO_RESPAWN);
                new stringinfovehiculo[67+1], stringinfovehiculo2[61+1];
                if(VehiculosInfo[i][vcomprable] == 1)
                {
                    printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: Comprable", i);
                    if(!strcmp("nadie",VehiculosInfo[i][vpropietario],true))
                    {
                        format(stringinfovehiculo, sizeof(stringinfovehiculo), "{F6FF00}VEHНCULO EN VENTA\n{FFFFFF}Precio: $%d\nID: %d", VehiculosInfo[i][vprecio], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                    else
                    {
                        format(stringinfovehiculo2, sizeof(stringinfovehiculo2), "{F6FF00}Dueсo: %s\n{FFFFFF}ID: %d", VehiculosInfo[i][vpropietario], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo2, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                } else printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: No Comprable", i);
                Vehiculos_Creados++;
            }
            printf("[Vehiculos] Se han cargado %d vehiculos", Vehiculos_Creados++);
        }
    }
    return 1;
}
stock CargarVehiculos()
{
    mysql_function_query(Conexion, "SELECT * FROM vehiculos", true, "OnQueryFinish", "i", 3);
}
Me pinta que me estoy olvidando algo si es asн decime.
Reply
#4

Quote:
Originally Posted by JustBored
Посмотреть сообщение
Yo antes tenнa tu mismo error: їsoluciуn?
pawn Код:
#define MAXIMO_VEHICULOS        (3)
#define TIEMPO_RESPAWN          (180000)

public OnGameModeInit()
{
   CargarVehiculos();
}
public OnQueryFinish(resultid, extraid, ConnectionHandle)
{
    new Rows, Field;
    if(resultid != 0)
    {
        cache_get_data(Rows, Field);
    }
    switch(resultid)
    {
        case 3:
        {
            cache_get_data(Rows,Field, Conexion); //obtenemos los datos
            for( new i = 1; i < Rows; i++ ) //bucle por todos los vehнculos
            {
                new content[12]; //te recomiendo tenerla en 32 si queres obtener el dueсo o algo
                cache_get_field_content(0, "propietario", VehiculosInfo[i][vpropietario]);
                cache_get_field_content(0, "precio", content); VehiculosInfo[i][vprecio] = strval(content);
                cache_get_field_content(0, "modelo", content); VehiculosInfo[i][vmodelo] = strval(content);
                cache_get_field_content(0, "x", content); VehiculosInfo[i][vx] = floatstr(content);
                cache_get_field_content(0, "y", content); VehiculosInfo[i][vy] = floatstr(content);
                cache_get_field_content(0, "z", content); VehiculosInfo[i][vz] = floatstr(content);
                cache_get_field_content(0, "a", content); VehiculosInfo[i][va] = floatstr(content);
                cache_get_field_content(0, "color1", content); VehiculosInfo[i][vcolor1] = strval(content);
                cache_get_field_content(0, "color2", content); VehiculosInfo[i][vcolor2] = strval(content);
                cache_get_field_content(0, "comprable", content); VehiculosInfo[i][vcomprable] = strval(content);
                VehiculosInfo[i][vID] = i;
               
                CreateVehicle(VehiculosInfo[i][vmodelo], VehiculosInfo[i][vx], VehiculosInfo[i][vy], VehiculosInfo[i][vz], VehiculosInfo[i][va], VehiculosInfo[i][vcolor1], VehiculosInfo[i][vcolor2], TIEMPO_RESPAWN);
                new stringinfovehiculo[67+1], stringinfovehiculo2[61+1];
                if(VehiculosInfo[i][vcomprable] == 1)
                {
                    printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: Comprable", i);
                    if(!strcmp("nadie",VehiculosInfo[i][vpropietario],true))
                    {
                        format(stringinfovehiculo, sizeof(stringinfovehiculo), "{F6FF00}VEHНCULO EN VENTA\n{FFFFFF}Precio: $%d\nID: %d", VehiculosInfo[i][vprecio], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                    else
                    {
                        format(stringinfovehiculo2, sizeof(stringinfovehiculo2), "{F6FF00}Dueсo: %s\n{FFFFFF}ID: %d", VehiculosInfo[i][vpropietario], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo2, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                } else printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: No Comprable", i);
                Vehiculos_Creados++;
            }
            printf("[Vehiculos] Se han cargado %d vehiculos", Vehiculos_Creados++);
        }
    }
    return 1;
}
stock CargarVehiculos()
{
    mysql_function_query(Conexion, "SELECT * FROM vehiculos", true, "OnQueryFinish", "i", 3);
}
Me pinta que me estoy olvidando algo si es asн decime.
Gracias por responder, pero sigue sin funcionar .

Quote:

//te recomiendo tenerla en 32 si queres obtener el dueсo o algo

Si necesito obtener el dueсo lo obtengo directamente, no necesito utilizar el content en ese caso
Reply
#5

Tu problema es que siempres cargas el auto que estб en la primera fila debes de cambiar los 0 por la "i" del bucle, tampoco verificas si se alcanzу el maximo de vehiculos, pon esto al principio del bucle.
pawn Код:
if(i >= MAXIMO_VEHICULOS) {
    print("Se ha alcanzado el mбximo de vehiculos para cargar");
    break;
}
Reply
#6

Quote:
Originally Posted by Daniel-92
Посмотреть сообщение
Tu problema es que siempres cargas el auto que estб en la primera fila debes de cambiar los 0 por la "i" del bucle, tampoco verificas si se alcanzу el maximo de vehiculos, pon esto al principio del bucle.
pawn Код:
if(i >= MAXIMO_VEHICULOS) {
    print("Se ha alcanzado el mбximo de vehiculos para cargar");
    break;
}
Gracias por tu respueta, siguen cargando 2 autos iguales:

[Image: tet.png]

pawn Код:
case 3:
        {
            for( new i = 1; i < MAXIMO_VEHICULOS; i++ )
            {
                if(i >= MAXIMO_VEHICULOS) {
                    print("Se ha alcanzado el mбximo de vehiculos para cargar");
                    break;
                }
                new content[12];
                cache_get_field_content(0, "propietario", VehiculosInfo[i][vpropietario]);
                cache_get_field_content(0, "precio", content); VehiculosInfo[i][vprecio] = strval(content);
                cache_get_field_content(0, "modelo", content); VehiculosInfo[i][vmodelo] = strval(content);
                cache_get_field_content(0, "x", content); VehiculosInfo[i][vx] = floatstr(content);
                cache_get_field_content(0, "y", content); VehiculosInfo[i][vy] = floatstr(content);
                cache_get_field_content(0, "z", content); VehiculosInfo[i][vz] = floatstr(content);
                cache_get_field_content(0, "a", content); VehiculosInfo[i][va] = floatstr(content);
                cache_get_field_content(0, "color1", content); VehiculosInfo[i][vcolor1] = strval(content);
                cache_get_field_content(0, "color2", content); VehiculosInfo[i][vcolor2] = strval(content);
                cache_get_field_content(0, "comprable", content); VehiculosInfo[i][vcomprable] = strval(content);
                VehiculosInfo[i][vID] = i;

                CreateVehicle(VehiculosInfo[i][vmodelo], VehiculosInfo[i][vx], VehiculosInfo[i][vy], VehiculosInfo[i][vz], VehiculosInfo[i][va], VehiculosInfo[i][vcolor1], VehiculosInfo[i][vcolor2], TIEMPO_RESPAWN);
                new stringinfovehiculo[67+1], stringinfovehiculo2[61+1];
                if(VehiculosInfo[i][vcomprable] == 1)
                {
                    printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: Comprable", i);
                    if(!strcmp("nadie",VehiculosInfo[i][vpropietario],true))
                    {
                        format(stringinfovehiculo, sizeof(stringinfovehiculo), "{F6FF00}VEHНCULO EN VENTA\n{FFFFFF}Precio: $%d\nID: %d", VehiculosInfo[i][vprecio], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                    else
                    {
                        format(stringinfovehiculo2, sizeof(stringinfovehiculo2), "{F6FF00}Dueсo: %s\n{FFFFFF}ID: %d", VehiculosInfo[i][vpropietario], VehiculosInfo[i][vID]);
                        infovehiculo = Create3DTextLabel( stringinfovehiculo2, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                        Attach3DTextLabelToVehicle( infovehiculo, VehiculosInfo[i][vID], 0.0, 0.0, 0.5);
                    }
                } else printf("[Vehiculos] Se ha cargado el auto N°%d. Tipo: No Comprable", i);
                Vehiculos_Creados++;
            }
            printf("[Vehiculos] Se han cargado %d vehiculos", Vehiculos_Creados++);
        }
Reply
#7

Aun no cambias los ceros por la i.
pawn Код:
cache_get_field_content(i, "propietario", VehiculosInfo[i][vpropietario]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)