SQL Login problem
#1

This is very odd, another error which seemingly happened out of nowhere. Where do I begin...

In my mysql_login,
pawn Код:
stock MySQL_Login(playerid)
{
    new query[300], savingstring[20];
    format(query, sizeof(query), "SELECT * FROM playerdata WHERE user = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    new angle[9];
    new model[9];
    new xcoords[9];
    new ycoords[9];
    new zcoords[9];
    new color1[9];
    new color2[9];
    new vehstring[64];
    new engine, lights, alarm, doors, bonnet, boot, objective;
    while(mysql_fetch_row_format(query, "|"))
    {
        mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
        mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "bankcash"); bankcash[playerid] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "robskill"); robskill[playerid] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "coprank"); coprank[playerid] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "adminlevel"); adminlevel[playerid] = strval(savingstring);
        for(new i; i < 9; i++)
        {
            vehstring = "";
            format(vehstring, sizeof(vehstring), "vehicle%ix", i+1);
            mysql_fetch_field_row(savingstring, vehstring);
            xcoords[i] = strval(savingstring);
           
            vehstring = "";
            format(vehstring, sizeof(vehstring), "vehicle%iy", i+1);
            mysql_fetch_field_row(savingstring, vehstring);
            ycoords[i] = strval(savingstring);

            vehstring = "";
            format(vehstring, sizeof(vehstring), "vehicle%iz", i+1);
            mysql_fetch_field_row(savingstring, vehstring);
            zcoords[i] = strval(savingstring);
           
            vehstring = "";
            format(vehstring, sizeof(vehstring), "angle%i", i+1);
            mysql_fetch_field_row(savingstring, vehstring);
            angle[i] = strval(savingstring);

            vehstring = "";
            format(vehstring, sizeof(vehstring), "model%i", i+1);
            mysql_fetch_field_row(savingstring, vehstring);
            model[i] = strval(savingstring);
           
            vehstring = "";
            format(vehstring, sizeof(vehstring), "%icolor1", i+1);
            mysql_fetch_field_row(savingstring, vehstring);
            color1[i] = strval(savingstring);
           
            vehstring = "";
            format(vehstring, sizeof(vehstring), "%icolor2", i+1);
            mysql_fetch_field_row(savingstring, vehstring);
            color2[i] = strval(savingstring);

            if(model[i] != 0)
            {
                new namestring[255];
                PlayerVehicles[playerid][i] = CreateVehicle(model[i], xcoords[i], ycoords[i], zcoords[i], angle[i], color1[i], color2[i], -1);
                format(namestring, 100, "%s's %s", PlayerName(playerid), VehicleNames[GetVehicleModel(PlayerVehicles[playerid][i])-400]);
                vehicle3Dtext[PlayerVehicles[playerid][i]] = Create3DTextLabel(namestring, 0xFF0000AA, 0.0, 0.0, 0.0, 50.0, 0, 1 );
                Attach3DTextLabelToVehicle(vehicle3Dtext[PlayerVehicles[playerid][i]], PlayerVehicles[playerid][i], 0.0, 0.0, 1.0);
                GetVehicleParamsEx(PlayerVehicles[playerid][i], engine, lights, alarm, doors, bonnet, boot, objective);
                SetVehicleParamsEx(PlayerVehicles[playerid][i], 0, lights, alarm, doors, bonnet, boot, objective);
            }
        }

    }
    mysql_free_result();
    printf("lolololol");
    SendClientMessage(playerid, -1, "You have been logged in!");
    Vehicle[playerid] = CreatePlayerTextDraw(playerid, 50.0, 250.0, "--");
    PlayerTextDrawFont(playerid, Vehicle[playerid], 3);
    PlayerTextDrawLetterSize(playerid, Vehicle[playerid], 0.399999,1.600000);
    PlayerTextDrawColor(playerid, Vehicle[playerid], 0xffffffff);

    VehicleHealth[playerid] = CreatePlayerTextDraw(playerid, 50.0, 276.0, "--");
    PlayerTextDrawLetterSize(playerid, VehicleHealth[playerid], 0.399999,1.600000);
    PlayerTextDrawFont(playerid, VehicleHealth[playerid], 3);
    PlayerTextDrawColor(playerid, VehicleHealth[playerid], 0xffffffff);
    Logged[playerid] = 1;
    return 1;
}
EDIT:
Problem came back, and I got an error tracing it back to this function. It looks like when a player has 6 vehicles it runs into problems. What can I do? I don't see any problems...
Reply
#2

update, if I remove all the car's information in slot 6, vehicle6x ect... in the database, it works fine
So if I have 1-5, 7-9 taken up, everything will log in fine. Getting closer.. Can't wait to smash this bug.
Reply
#3

Bump
Reply
#4

Use a proper table structure. If you need to add numbers to field names then you're doing it wrong.
Reply
#5

I've just recently put up mysql, could you give me an example on how it should be setup?
Edit:
I put numbers so I wouldn't have to type vehicle1x vehicle2x etc... by hand, so I thought this would be an easier work around. If you have a better idea please share, this is giving me a head ache. You think if I removed for loop and typed it all by hand it would fix the bug? I don't see why it would but need to hurry and fix this. Each player should be able to own up to 9 vehicles, and the position,color, and angle should be stored in the database. If there's a better way to organize this I'm all ears. I have to thank you for reply, no one has given me any suggestions or advice yet.
Reply
#6

Bump
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)