Loading cars.
#1

I have this code that's supposed to load all the cars from database when the gamemode starts. But there's a problem, every car owner is the same person.

pawn Код:
stock LaeAutod()
{
    new query[512];
    format(query, sizeof(query), "SELECT * FROM eraautod");
   
    mysql_query(query);
    mysql_store_result();

    new i = 0;

    while(mysql_retrieve_row())
    {
        new field[64];

        mysql_fetch_field_row(field, "model");
        AutoInfo[i][aModel] = strval(field);
       
        mysql_fetch_field_row(field, "varv1");
        AutoInfo[i][aVarv1] = strval(field);

        mysql_fetch_field_row(field, "varv2");
        AutoInfo[i][aVarv2] = strval(field);

        mysql_fetch_field_row(field, "x");
        AutoInfo[i][aX] = floatstr(field);

        mysql_fetch_field_row(field, "y");
        AutoInfo[i][aY] = floatstr(field);

        mysql_fetch_field_row(field, "z");
        AutoInfo[i][aZ] = floatstr(field);

        mysql_fetch_field_row(field, "a");
        AutoInfo[i][aA] = floatstr(field);

        new masin = CreateVehicle(AutoInfo[i][aModel], AutoInfo[i][aX], AutoInfo[i][aY], AutoInfo[i][aZ]+1.0, AutoInfo[i][aA], AutoInfo[i][aVarv1], AutoInfo[i][aVarv2], -1);
       
        mysql_fetch_field_row(field, "id");
        AutoInfo[masin][aID] = strval(field);
       
        mysql_fetch_field_row(field, "omanik");
        AutoInfo[masin][aOmanik] = strmid(AutoInfo[masin][aOmanik], field, 0, 24, 255);
       
        mysql_fetch_field_row(field, "numbrimark");
        AutoInfo[masin][aNumbrimark] = strmid(AutoInfo[masin][aNumbrimark], field, 0, strlen(field), 255);
       
        SetVehicleNumberPlate(masin, AutoInfo[masin][aNumbrimark]);
        SetVehicleVirtualWorld(masin, 0);
        i++;
    }
    mysql_free_result();
    print("[MYSQL] Autod serverisse laetud!");
    return 1;
}
This is the owner line..
pawn Код:
AutoInfo[masin][aOmanik] = strmid(AutoInfo[masin][aOmanik], field, 0, 24, 255);
And there are some others too.. am I using it wrong?
Reply
#2

Quote:
Originally Posted by Dan.
Посмотреть сообщение
And there are some others too.. am I using it wrong?
Yes you are.

Don't do

pawn Код:
AutoInfo[masin][aOmanik] = strmid(AutoInfo[masin][aOmanik], field, 0, 24, 255);
Do

pawn Код:
strmid(AutoInfo[masin][aOmanik], field, 0, 24, 255);
strmid sets the string, so the = isn't needed. You should also do this for the number plate.

You could also use format

pawn Код:
format(AutoInfo[masin][aOmanik],24,"%s",field);
Reply
#3

I have a problem. I made a debug command to get the owner of the car.

1) The car's owner should be "flashsnake" and the license plate "FLASH".

When I type the CMD, AutoInfo[masin[aOmanik] will be this:

pawn Код:
carowner: flFLASH
pawn Код:
stock LaeAutod()
{
    new query[512];
    format(query, sizeof(query), "SELECT * FROM eraautod");
   
    mysql_query(query);
    mysql_store_result();

    new i = 0;

    while(mysql_retrieve_row())
    {
        new field[64];

        mysql_fetch_field_row(field, "model");
        AutoInfo[i][aModel] = strval(field);
       
        mysql_fetch_field_row(field, "varv1");
        AutoInfo[i][aVarv1] = strval(field);

        mysql_fetch_field_row(field, "varv2");
        AutoInfo[i][aVarv2] = strval(field);

        mysql_fetch_field_row(field, "x");
        AutoInfo[i][aX] = floatstr(field);

        mysql_fetch_field_row(field, "y");
        AutoInfo[i][aY] = floatstr(field);

        mysql_fetch_field_row(field, "z");
        AutoInfo[i][aZ] = floatstr(field);

        mysql_fetch_field_row(field, "a");
        AutoInfo[i][aA] = floatstr(field);

        new masin = CreateVehicle(AutoInfo[i][aModel], AutoInfo[i][aX], AutoInfo[i][aY], AutoInfo[i][aZ]+1.0, AutoInfo[i][aA], AutoInfo[i][aVarv1], AutoInfo[i][aVarv2], -1);
       
        mysql_fetch_field_row(field, "id");
        AutoInfo[masin][aID] = strval(field);
       
        mysql_fetch_field_row(field, "omanik");
        format(AutoInfo[masin][aOmanik],24, "%s", field);
       
        mysql_fetch_field_row(field, "numbrimark");
        format(AutoInfo[masin][aNumbrimark],24, "%s", field);

        SetVehicleNumberPlate(masin, AutoInfo[masin][aNumbrimark]);
        SetVehicleVirtualWorld(masin, 0);
        i++;
    }
    mysql_free_result();
    print("[MYSQL] Autod serverisse laetud!");
    return 1;
}
And debug CMD:

pawn Код:
CMD:debug(playerid, params[])
{
    new aid, string[128];
    aid = kAutoID(playerid);

    format(string, sizeof(string), "carowner: %s", AutoInfo[aid][aOmanik]);
    SendClientMessage(playerid, C_GREY, string);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)