Workaround vehicleid not matching MySQL vehicleid
#1

Hello,

I'm hoping to get some help. I'll try to explain this as clearly as possible, but if you don't understand something properly or need extra information, don't hesitate to ask.

So today I started on retrieving the vehicles from my MySQL database and creating them in the gamemode. This all works fine, but as soon as I started issuing them to certain Factions and using the in-game vehicleid to identify the enum's variables for the vehicle, it showed up with the bug. Obviously if I delete one of the vehicles in the MySQL database (with Auto-Increment on), it will no longer match the in-game vehicleid. Is there a good workaround for this? For example:

MySQL
1 Turismo
2 Alpha
3 Cheetah
In-Game
1 Turismo
2 Alpha
3 Cheetah

That works fine. But if I delete the Alpha they no longer match:

MySQL
1 Turismo
3 Cheetah
In-Game
1 Turismo
2 Cheetah

Now it'll not display any enum variables.

Here's a part of the script:

pawn Code:
//enum
enum VehicleInfo
{
    vehFaction,
};

// function where I load the vehicles

        new rows, fields;
    cache_get_data(rows, fields);
    for(new i=0; i<rows; i++){
        new vresult[11], float:fresult[11];
        printf("Getting %d", i);
        cache_get_field_content(i, "vehicleid", vresult);
        vehInfo[i][vehID] = strval(vresult);
       
        cache_get_field_content(i, "modelid", vresult);
        vehInfo[i][vehModel] = strval(vresult);
       
        cache_get_field_content(i, "Xpos", fresult);
        vehInfo[i][vehXPos] = floatstr(fresult);
       
        cache_get_field_content(i, "Ypos", fresult);
        vehInfo[i][vehYPos] = floatstr(fresult);
       
        cache_get_field_content(i, "Zpos", fresult);
        vehInfo[i][vehZPos] = floatstr(fresult);
       
        cache_get_field_content(i, "rotation", fresult);
        vehInfo[i][vehRotation] = floatstr(fresult);
       
        cache_get_field_content(i, "color1", vresult);
        vehInfo[i][vehColor1] = strval(vresult);
       
        cache_get_field_content(i, "color2", vresult);
        vehInfo[i][vehColor2] = strval(vresult);

        cache_get_field_content(i, "faction", vresult);
        vehInfo[i][vehFaction] = strval(vresult);
       
        cache_get_field_content(i, "team", vresult);
        vehInfo[i][vehTeam] = strval(vresult);
       
        CreateVehicle(vehInfo[i][vehModel], vehInfo[i][vehXPos], vehInfo[i][vehYPos], vehInfo[i][vehZPos], vehInfo[i][vehRotation], vehInfo[i][vehColor1], vehInfo[i][vehColor2], 0);
    }

//OnPlayerStateChange where it checks if the player is in the faction
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(IsPlayerInAnyVehicle(playerid)){
        if(vehInfo[GetPlayerVehicleID(playerid)][vehFaction] != pInfo[playerid][pFaction]){}//when player is not faction
        else{}//when player is faction
    }
    return 1;
}
Reply
#2

Same problem
Reply
#3

If you deleted the most recent entries, this would make it use the next lowest available one. For example, if you delete 13, 14 and 15 the A_I will be reset to 13 as long as there's no 15 already in table.

Code:
ALTER TABLE tata AUTO_INCREMENT=1
While 'tata' is your table name. This may solve your issue, however IMO, I think you shouldn't be relying on AUTO_INCREMENT, just ignore it and add/delete your records manually.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)