Problem getting variable from MySQL, again
#1

Hi everyone,

Again I have a problem with variable from MySQL, this time with int variable.

I have the next following code:

OnGameModeInit
pawn Код:
mysql_tquery(1, "SELECT * FROM `vehiculos`", "CargarVeh", "i", sizeof(object));
CargarVeh()
pawn Код:
forward CargarVeh(limit);
public CargarVeh(limit)
{
    new count, rows, data[50], team;
    cache_get_row_count(rows);
    for(new i; i < rows; i++)
    {
        if(count > limit)
        {
            printf("Limite de vehнculos excedido!");
            break;
        }
        for(new h; h < sizeof(object); h++)
        {

                cache_get_value_name(i, "idTeam", data); object[h][idTeam] = strval(data);
                cache_get_value_name(i, "modelo", data); object[h][modelo] = strval(data);
                cache_get_value_name(i, "posx", data); object[h][posx] = floatstr(data);
                cache_get_value_name(i, "posy", data); object[h][posy] = floatstr(data);
                cache_get_value_name(i, "posz", data); object[h][posz] = floatstr(data);
                cache_get_value_name(i, "posrot", data); object[h][posrot] = floatstr(data);
                cache_get_value_name(i, "color1", data); object[h][color1] = strval(data);
                cache_get_value_name(i, "color2", data); object[h][color2] = strval(data);

                object[h][idTeam] = AddStaticVehicle(object[h][modelo], object[h][posx], object[h][posy], object[h][posz], object[h][posrot], object[h][color1], object[h][color2]);
                printf("Vehiculo con idTeam %i, pos x: %i pos y: %i pos z: %i creado", object[h][idTeam], object[h][posx], object[h][posy], object[h][posz]);
                count++;
                break;
        }

    }
    printf("Vehiculos cargados: %d",count);
    return 1;
}
I add this printf line
pawn Код:
printf("Vehiculo con idTeam %i, pos x: %i pos y: %i pos z: %i creado", object[h][idTeam], object[h][posx], object[h][posy], object[h][posz]);
and output is:
Код HTML:
Vehiculo con idTeam 1, pos x: 1153436936 pos y: -992915778 pos z: 1096163329 creado
Vehiculo con idTeam 2, pos x: 1153397309 pos y: -992943300 pos z: 1096163329 creado
Vehiculo con idTeam 3, pos x: 1153396525 pos y: -992796630 pos z: 1096163329 creado
Vehiculo con idTeam 4, pos x: 1153387648 pos y: -992755057 pos z: 1096163329 creado
Vehiculo con idTeam 5, pos x: 1153387648 pos y: -992755057 pos z: 1096163329 creado
As you can see, object[h][idTeam] variable have an addition instead of get variable from MySQL database

SQL structure and data of 'vehiculos' table:
Код HTML:
idTeam	modelo	posx	posy	posz	posrot	color1	color2	
1	522	1536.407227	-1674.460693	13.382813	0	1	1	
1	522	1531.569946	-1671.101074	13.382813	0	1	1	
2	522	1531.474243	-1689.005127	13.382813	0	1	1	
2	522	1530.390625	-1694.079956	13.382813	0	1	1	
2	522	1530.390625	-1694.079956	13.382813	0	1	1	
Thanks you a lot in advance!
Reply
#2

pawn Код:
forward CargarVeh(limit);
public CargarVeh(limit)
{
    new h, rows, data[50], team;
    cache_get_row_count(rows);
    for(new i = 0; i < rows; i++)
    {
        if(h >= limit)
        {
            print("Limite de vehнculos excedido!");
            break;
        }
        cache_get_value_name(i, "idTeam", data); object[h][idTeam] = strval(data);
        cache_get_value_name(i, "modelo", data); object[h][modelo] = strval(data);
        cache_get_value_name(i, "posx", data); object[h][posx] = floatstr(data);
        cache_get_value_name(i, "posy", data); object[h][posy] = floatstr(data);
        cache_get_value_name(i, "posz", data); object[h][posz] = floatstr(data);
        cache_get_value_name(i, "posrot", data); object[h][posrot] = floatstr(data);
        cache_get_value_name(i, "color1", data); object[h][color1] = strval(data);
        cache_get_value_name(i, "color2", data); object[h][color2] = strval(data);

        object[h][idTeam] = AddStaticVehicle(object[h][modelo], object[h][posx], object[h][posy], object[h][posz], object[h][posrot], object[h][color1], object[h][color2]);
        printf("Vehiculo con idTeam %i, pos x: %i pos y: %i pos z: %i creado", object[h][idTeam], object[h][posx], object[h][posy], object[h][posz]);
        h++;
    }
    printf("Vehiculos cargados: %d",h);
    return 1;
}
and change %i to %f in pos
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
forward CargarVeh(limit);
public CargarVeh(limit)
{
    new h, rows, data[50], team;
    cache_get_row_count(rows);
    for(new i = 0; i < rows; i++)
    {
        if(h >= limit)
        {
            print("Limite de vehнculos excedido!");
            break;
        }
        cache_get_value_name(i, "idTeam", data); object[h][idTeam] = strval(data);
        cache_get_value_name(i, "modelo", data); object[h][modelo] = strval(data);
        cache_get_value_name(i, "posx", data); object[h][posx] = floatstr(data);
        cache_get_value_name(i, "posy", data); object[h][posy] = floatstr(data);
        cache_get_value_name(i, "posz", data); object[h][posz] = floatstr(data);
        cache_get_value_name(i, "posrot", data); object[h][posrot] = floatstr(data);
        cache_get_value_name(i, "color1", data); object[h][color1] = strval(data);
        cache_get_value_name(i, "color2", data); object[h][color2] = strval(data);

        object[h][idTeam] = AddStaticVehicle(object[h][modelo], object[h][posx], object[h][posy], object[h][posz], object[h][posrot], object[h][color1], object[h][color2]);
        printf("Vehiculo con idTeam %i, pos x: %i pos y: %i pos z: %i creado", object[h][idTeam], object[h][posx], object[h][posy], object[h][posz]);
        h++;
    }
    printf("Vehiculos cargados: %d",h);
    return 1;
}
and change %i to %f in pos
Hi again!, with your code the result is same

Final code with integers changed to floats
pawn Код:
forward CargarVeh(limit);
public CargarVeh(limit)
{
    new h, rows, data[50];
    cache_get_row_count(rows);
    for(new i = 0; i < rows; i++)
    {
        if(h >= limit)
        {
            print("Limite de vehiculos excedido!");
            break;
        }
        cache_get_value_name(i, "idTeam", data); object[h][idTeam] = strval(data);
        cache_get_value_name(i, "modelo", data); object[h][modelo] = strval(data);
        cache_get_value_name(i, "posx", data); object[h][posx] = floatstr(data);
        cache_get_value_name(i, "posy", data); object[h][posy] = floatstr(data);
        cache_get_value_name(i, "posz", data); object[h][posz] = floatstr(data);
        cache_get_value_name(i, "posrot", data); object[h][posrot] = floatstr(data);
        cache_get_value_name(i, "color1", data); object[h][color1] = strval(data);
        cache_get_value_name(i, "color2", data); object[h][color2] = strval(data);

        object[h][idTeam] = AddStaticVehicle(object[h][modelo], object[h][posx], object[h][posy], object[h][posz], object[h][posrot], object[h][color1], object[h][color2]);
        printf("Vehiculo con idTeam %i, pos x: %f pos y: %f pos z: %f creado", object[h][idTeam], object[h][posx], object[h][posy], object[h][posz]);
        h++;
    }
    printf("Vehiculos cargados: %d",h);
    return 1;
}
Output console:
Код HTML:
Vehiculo con idTeam 1, pos x: 1536.407226 pos y: -1674.460693 pos z: 13.382813 creado
Vehiculo con idTeam 2, pos x: 1531.569946 pos y: -1671.101074 pos z: 13.382813 creado
Vehiculo con idTeam 3, pos x: 1531.474243 pos y: -1689.005126 pos z: 13.382813 creado
Vehiculos cargados: 3
New structure for table vehicles:
Код HTML:
SELECT * FROM `vehiculos`


idTeam	modelo	posx	posy	posz	posrot	color1	color2	
1	522	1536.407227	-1674.460693	13.382813	0	1	1	
4	522	1531.569946	-1671.101074	13.382813	0	1	1	
2	522	1531.474243	-1689.005127	13.382813	0	1	1	
Thanks you!
Reply
#4

pawn Код:
object[h][idTeam] = strval(data);
and error
pawn Код:
object[h][idTeam] = AddStaticVehicle(
Reply
#5

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
object[h][idTeam] = strval(data);
and error
pawn Код:
object[h][idTeam] = AddStaticVehicle(
Sorry, I don't understand you
Reply
#6

1.
Why do you load everything as a string?

https://sampwiki.blast.hk/wiki/MySQL/R40#cache_get_value_name_int
https://sampwiki.blast.hk/wiki/MySQL/R4...ue_index_float


2.

You assign a value to the varibale:
Код:
cache_get_value_name(i, "idTeam", data); object[h][idTeam] = strval(data);
Then overwriting it's value with the ID of the created vehicle:
Код:
object[h][idTeam] = AddStaticVehicle(s
Reply
#7

Quote:
Originally Posted by Rolux
Посмотреть сообщение
1.
Why do you load everything as a string?

https://sampwiki.blast.hk/wiki/MySQL/R40#cache_get_value_name_int
https://sampwiki.blast.hk/wiki/MySQL/R4...ue_index_float


2.

You assign a value to the varibale:
Код:
cache_get_value_name(i, "idTeam", data); object[h][idTeam] = strval(data);
Then overwriting it's value with the ID of the created vehicle:
Код:
object[h][idTeam] = AddStaticVehicle(s
Yes, I just tried now remove object[h][idTeam] = on AddStaticVehicle and variable is correctly but I need know for what because I'm trying create team vehicles loaded from MySQL. Can you please tell and help me with that?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)