SA-MP Forums Archive
Player vehicle ids - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Player vehicle ids (/showthread.php?tid=583321)



Player vehicle ids - Luis- - 27.07.2015

Hey! I've been wanting to find out how people do their vehicle system. Basically everybody on my server can own a vehicle, but they can also scrap (delete) their vehicle, meaning the vehicle ids will get mixed up on the vehicle mysql database. How would I go about fixing that?


Re: Player vehicle ids - xVIP3Rx - 27.07.2015

Try to use your own declared vehicle ids and match them with the actual vehicle ids, for example when somebody delete his vehicle mark that id as empty and when somebody creates a vehicle use that slot and mark it as occupied.


Re: Player vehicle ids - Luis- - 27.07.2015

So, something like,
pawn Код:
"INSERT INTO `server_vehicles` VALUES (%d, ...) ON DUPLICATE KEY UPDATE `x` = %d"



Re: Player vehicle ids - zT KiNgKoNg - 27.07.2015

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
Try to use your own declared vehicle ids and match them with the actual vehicle ids, for example when somebody delete his vehicle mark that id as empty and when somebody creates a vehicle use that slot and mark it as occupied.
Thats basically what you should do.

Something along these lines, this way when someone deletes their vehicles you can just compare it within say an 'Enum' and destroy the vehicle, set the vehicle data portion to INVALID_VEHICLE_ID and set SlotUsed to '0' as per my example below, frankly its upto the developers opinion, usually the simplest answer is the best answer in the short term.

Then delete the row in the database, I'm not entirely sure this is want you really wanted; but excuse me if it doesn't make sense or isn't related to your answer; When you've missed out on sleep for five days, it kinda' hits you.

Note: I've used "MAX_VEHICLES" for an example; usually I wouldn't use it, I'd use a custom amount depending on how many vehicles I'd prefer a player to have at anyone time times the slots of the server (as-long as its below the limit).

pawn Код:
stock GetFreeVehicleSlot()
{
    for(new i; < MAX_VEHICLES; i++)
        if(VehicleInformation[i][SlotUsed])
            continue;
        else
            return i;
}



Re: Player vehicle ids - xVIP3Rx - 27.07.2015

After reading again, why don't you use a number(for example -1) as the vehicle id/model when somebody deletes the vehicle and save it under the same database id with -1, you'll have some unused slots per player though..


Re: Player vehicle ids - Luis- - 29.07.2015

Right, I forgot to mention that I'm also using the same database to store job & faction vehicles, should I use a completely different database for each vehicle type?


Re: Player vehicle ids - Luis- - 03.08.2015

Quote:
Originally Posted by Luis-
Посмотреть сообщение
Right, I forgot to mention that I'm also using the same database to store job & faction vehicles, should I use a completely different database for each vehicle type?
Still could use some help with the above message.


Re: Player vehicle ids - Abagail - 03.08.2015

Show the code you currently use to insert the vehicles, destroy / scrap and the structure in phpMyAdmin(if possible).


Re: Player vehicle ids - Luis- - 04.08.2015

Here's the database structure;
http://prntscr.com/80sbdo

And, here's how I save them;
pawn Код:
stock SaveVehicles() {
    new query[1024];
    for(new i = 1; i != loadedCars; i++) {
        if(VehicleInfo[i][vInGarage] == 0) {
            GetVehicleHealth(i, VehicleInfo[i][vHealth]);
            GetVehicleDamageStatus(i, VehicleInfo[i][vPanels], VehicleInfo[i][vDoors], VehicleInfo[i][vLights], VehicleInfo[i][vTires]);
            format(query, sizeof query, "UPDATE `server_vehicles` SET `ID`=%d,`Model`=%d,`X`=%f,`Y`=%f,`Z`=%f,`A`=%f,`Owner`='%s',`ColorOne`=%d,`ColorTwo`=%d,`FactionID`=%d,`JobID`=%d,`Owned`=%d,`Plate`='%s',`Locked`=%d,\
            `Health`=%f,`Doors`=%d,`Tires`=%d,`Lights`=%d,`Panels`=%d,`Fuel`=%d,`Mileage`=%d,`GangID`=%d,`InGarage`=%d WHERE `ID` = %d"
,
                                                i, VehicleInfo[i][vModel], VehicleInfo[i][vX], VehicleInfo[i][vY], VehicleInfo[i][vZ], VehicleInfo[i][vA], VehicleInfo[i][vOwner],
                                                VehicleInfo[i][vColor1], VehicleInfo[i][vColor2], VehicleInfo[i][vFactionID], VehicleInfo[i][vJobID], VehicleInfo[i][vOwned], VehicleInfo[i][vPlate], VehicleInfo[i][vLocked],
                                                VehicleInfo[i][vHealth], VehicleInfo[i][vDoors], VehicleInfo[i][vTires], VehicleInfo[i][vLights], VehicleInfo[i][vPanels], VehicleInfo[i][vFuel], VehicleInfo[i][vMileage], VehicleInfo[i][vGangID], VehicleInfo[i][vInGarage], VehicleInfo[i][vID]);
            mysql_tquery(dbHandle, query);
        }
    }
    return 1;
}
Here's what I do when they're scrapped;
pawn Код:
CMD:dumpcar(playerid) {
    new query[128];
    if(!IsPlayerInVehicle(playerid, PlayerInfo[playerid][pCarKey])) return SendClientMessage(playerid, COLOR_GREY, "You need to be inside your vehicle!");
    if(PlayerInfo[playerid][pCarKey] <= 0) return SendClientMessage(playerid, COLOR_GREY, "You don't own a car.");
    if(IsPlayerInRangeOfPoint(playerid, 5.5, 2183.6150,-1988.7555,13.8917)) {
        format(query, sizeof query, "DELETE FROM `server_vehicles` WHERE `ID` = %d", PlayerInfo[playerid][pCarKey]);
        mysql_tquery(dbHandle, query);
        DestroyVehicle(PlayerInfo[playerid][pCarKey]);
        SetPlayerMoney(playerid, 500+random(2500));
        VehicleInfo[PlayerInfo[playerid][pCarKey]][vModel] = 0;
        VehicleInfo[PlayerInfo[playerid][pCarKey]][vX] = 0;
        VehicleInfo[PlayerInfo[playerid][pCarKey]][vY] = 0;
        VehicleInfo[PlayerInfo[playerid][pCarKey]][vZ] = 0;
        VehicleInfo[PlayerInfo[playerid][pCarKey]][vA] = 0;
        VehicleInfo[PlayerInfo[playerid][pCarKey]][vColor1] = 1;
        VehicleInfo[PlayerInfo[playerid][pCarKey]][vColor2] = 1;       
        PlayerInfo[playerid][pCarKey] = 0;
        SendClientMessage(playerid, COLOR_WHITE, "You have scrapped your car and have earned some money by doing so.");
        loadedCars--;
    }
    return 1;
}