MySQL -- Get VehicleID
#8

Quote:
Originally Posted by yoran765
Посмотреть сообщение
I have no idea how MySQL works and i'm getting pretty frustrated. What do you mean by MySQL non changing key to the ingame volatile vehicleid. You can't create your own ingame vehicleid, those go by order or am I wrong?.
He means if you load your vehicle you add something like this;
pawn Код:
enum vehicleinfo
{
    SQLID,
    VehicleID,
    Owner[MAX_PLAYER_NAME]
}
new VehicleInfo[MAX_VEHICLES][vehicleinfo];
And then when loading the vehicle (Alltough I always use(d) StrickenKid's SQL plugin and don't know what you use) you do something like this;

pawn Код:
public LoadVehicles()
{
    ...
    new string[128];
    format(string, sizeof(string), "...", ...);
    mysql_query(string);
    mysql_store_result();
    ...
    mysql_fetch_field("SQLID", string);
    VehicleInfo[i][SQLID] = strval(string);
    VehicleInfo[i][VehicleID] = CreateVehicle(...);
    mysql_free_result();
    return 1;
}
Then when you want to save to your SQL database for that vehicle you do something like this:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(!ispassenger)
        {
        for(new i = 0; i < MAX_VEHICLES; i++)
            {
            if(VehicleInfo[i][VehicleID] == vehicleid)
                {
                new string[128], name[MAX_PLAYER_NAME];
                GetPlayerName(playerid, name, sizeof(name));
                strmid(VehicleInfo[i][Owner], name, 0, strlen(name), MAX_PLAYER_NAME);
                format(string, sizeof(string), "UPDATE `Vehicles` SET `Owner` = '%s' WHERE `SQLID` = %d", VehicleInfo[i][Owner], VehicleInfo[vehicleid][SQLID]);
                mysql_query(string);
                }
            }
        }
    return 1;
}
It's mostly about the 'WHERE `SQLID` = %d' part but I hope you understand what I mean!

Best regards,
Jesse
Reply


Messages In This Thread
MySQL -- Get VehicleID - by yoran765 - 16.06.2014, 07:24
Re: MySQL -- Get VehicleID - by appleomax - 16.06.2014, 08:13
Re: MySQL -- Get VehicleID - by Jessyy - 16.06.2014, 10:01
Re: MySQL -- Get VehicleID - by yoran765 - 16.06.2014, 10:06
Re: MySQL -- Get VehicleID - by Vince - 16.06.2014, 10:38
Re: MySQL -- Get VehicleID - by yoran765 - 16.06.2014, 11:52
Re: MySQL -- Get VehicleID - by yoran765 - 16.06.2014, 12:07
Re: MySQL -- Get VehicleID - by jessejanssen - 16.06.2014, 12:44

Forum Jump:


Users browsing this thread: 3 Guest(s)