SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/01/2013, 08:30 PM   #1
DrDoom151
Big Clucker
 
Join Date: Jun 2011
Posts: 65
Reputation: 4
Default Workaround vehicleid not matching MySQL vehicleid

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;
}
DrDoom151 is offline   Reply With Quote
Old 18/05/2013, 10:31 PM   #2
Moglizorz.
Big Clucker
 
Moglizorz.'s Avatar
 
Join Date: Feb 2009
Posts: 148
Reputation: 2
Default Re: Workaround vehicleid not matching MySQL vehicleid

Same problem
Moglizorz. is offline   Reply With Quote
Old 18/05/2013, 11:49 PM   #3
[KHK]Khalid
Gangsta
 
[KHK]Khalid's Avatar
 
Join Date: Jan 2012
Location: Alexandria, Egypt
Posts: 854
Reputation: 136
Default Re: Workaround vehicleid not matching MySQL vehicleid

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.
[KHK]Khalid is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible vehicleid bug? FufLa Bug Reports 56 16/07/2015 04:47 AM
What IS vehicleid jakejohnsonusa Scripting Help 7 24/01/2013 09:50 PM
VehicleID sjvt Scripting Help 4 23/04/2012 10:13 PM
Vehicleid cruising Scripting Help 9 14/01/2012 08:43 AM


All times are GMT. The time now is 03:57 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.