Vehicle command
#3

The first mistake is that `cache_insert_id` returns -1 on error for R40 version and above. You call a cache function before even executing the INSERT query.

The second mistake is that `format` function does not support %e specifier. Use `mysql_format` instead.

The third mistake is the number of INSERT queries you are trying to execute. It must be 1 query otherwise it will create 4 rows with different dbid but duplicate data.

Move the `IsPlayerInAnyVehicle` check at the very top.

You know the modelid, no need to store the vehicle name as it can be easily retrieved.

Vehicle owner should be an integer, sql unique id of the player which can be linked and can also be easily compared with. If a vehicle is not owned, owner should be NULL and makes `owned` column redundant.

Set default value for plate so you do not have to set it in the query. You call SetVehicleNumberPlate but the vehicle was not created yet.

Pass everything as arguments and when the query succeeded, assign them to the variables.

While INSERT INTO .. SET syntax is valid, I'll show an example with this mysql extension and not the standard sql syntax. If you change the owner datatype, remove the redundant vehicle name and set the default value for vehicle plate, you can remove them from the query:
pawn Код:
new player_interior = GetPlayerInterior(playerid),
    player_virtual_world = GetPlayerVirtualWorld(playerid);
   
mysql_format(mysql, query, sizeof(query),
    "INSERT INTO vehicles \
        SET vehicleName='%e', \
            vehicleOwner='-', \
            vehiclePlate='SSRP', \
            vehicleModel=%d, \
            vehiclePrice=%d, \
            vehicleColorOne=%d, \
            vehicleColorTwo=%d, \
            vehicleX=%f, \
            vehicleY=%f, \
            vehicleZ=%f, \
            vehicleA=%f, \
            vehicleInterior=%d, \
            vehicleWorld=%d, \
            vehicleOwned=0"
,

    GetVehicleName(vehid),
    vehid,
    price,
    color1,
    color2,
    x,
    y,
    z,
    angle,
    player_interior,
    player_virtual_world);

mysql_tquery(mysql, query, "OnVehicleCreate", "dddddffffdd", veh_index, vehid, price, color1, color2, x, y, z, angle, player_interior, player_virtual_world);
pawn Код:
forward OnVehicleCreate(veh_index, vehid, price, color1, color2, Float: x, Float: y, Float: z, Float: angle, vehicle_interior, vehicle_virtual_world);
public OnVehicleCreate(veh_index, vehid, price, color1, color2, Float: x, Float: y, Float: z, Float: angle, vehicle_interior, vehicle_virtual_world)
{
    VehicleData[veh_index][vehicleDBID] = cache_insert_id();
    VehicleData[veh_index][vehicleExists] = true;

    VehicleData[veh_index][vehicleModel] = vehid;
 
    strcpy(VehicleData[veh_index][vehicleName], GetVehicleName(vehid), MAX_PLAYER_NAME);
    strcpy(VehicleData[veh_index][vehicleOwner], "-", MAX_PLAYER_NAME);
    strcpy(VehicleData[veh_index][vehiclePlate], "SSRP", 16);

    VehicleData[veh_index][vehiclePrice] = price;

    VehicleData[veh_index][vehicleLock] = 0;

    VehicleData[veh_index][vehicleColorOne] = color1;
    VehicleData[veh_index][vehicleColorTwo] = color2;

    VehicleData[veh_index][vehiclePos][0] = x;
    VehicleData[veh_index][vehiclePos][1] = y;
    VehicleData[veh_index][vehiclePos][2] = z;
    VehicleData[veh_index][vehiclePos][3] = angle;

    VehicleData[veh_index][vehicleInterior] = vehicle_interior;
    VehicleData[veh_index][vehicleWorld] = vehicle_virtual_world;

    VehicleData[veh_index][vehicleOwned] = 0;
 
    /*
        create the vehicle here.
        what do `Vehicle_Save` and `Vehicle_Refresh` do?
    */

}
Reply


Messages In This Thread
Vehicle command - by SymonClash - 13.02.2019, 09:26
Re: Vehicle command - by d3Pedro - 13.02.2019, 10:02
Re: Vehicle command - by Calisthenics - 13.02.2019, 10:29
Re: Vehicle command - by d3Pedro - 13.02.2019, 10:34
Re: Vehicle command - by SymonClash - 13.02.2019, 10:37
Re: Vehicle command - by Calisthenics - 13.02.2019, 10:45
Re: Vehicle command - by SymonClash - 13.02.2019, 10:52
Re: Vehicle command - by Calisthenics - 13.02.2019, 11:02
Re: Vehicle command - by SymonClash - 13.02.2019, 12:40
Re: Vehicle command - by Calisthenics - 13.02.2019, 12:45

Forum Jump:


Users browsing this thread: 2 Guest(s)