Vehicle command
#6

Quote:
Originally Posted by ConnorW
Посмотреть сообщение
I didn't read the whole code tho! This is a good way of doing it, but if you look at his code he actually got
pawn Код:
Vehicle_Save(i);

        Vehicle_Refresh(i);
So in my way, I'd go with inserting the cache then just saving it and refreshing which is probably reloading vehicle using these two functions.
I mentioned it in comments that he should create the vehicle at the end and asked what those two functions do. If you just insert a new record, what would be the point to save it again right away? Nothing has changed!

Quote:
Originally Posted by SymonClash
Посмотреть сообщение
Thank you both.

@Calisthenics, this is what Vehicle_Save and Vehicle_Refresh do:

pawn Код:
stock Vehicle_Save(vid)
{
    static query[256];

    format(query, sizeof(query), "UPDATE `vehicles` SET `vehicleOwner` = '%e', `vehicleX` = '%.4f', `vehicleY` = '%.4f', `vehicleZ` = '%.4f', `vehicleA` = '%.4f', `vehicleInterior` = '%d', `vehicleWorld` = '%d' WHERE `vehicleDBID` = '%d'",
        VehicleData[vid][vehicleOwner],
        VehicleData[vid][vehiclePos][0],
        VehicleData[vid][vehiclePos][1],
        VehicleData[vid][vehiclePos][2],
        VehicleData[vid][vehiclePos][3],
        VehicleData[vid][vehicleInterior],
        VehicleData[vid][vehicleWorld],
        VehicleData[vid][vehicleDBID]
    );
    return mysql_tquery(mysql, query);
}
pawn Код:
stock Vehicle_Refresh(vid)
{
    if(vid != -1 && VehicleData[vid][vehicleExists] && VehicleData[vid][vehicleOwned] == 0)
    {
        static string[128];

        if(IsValidDynamic3DTextLabel(VehicleData[vid][vehicleLabel])) DestroyDynamic3DTextLabel(VehicleData[vid][vehicleLabel]);

        VehicleData[vid][vehicleDBID] = CreateVehicle(vid, VehicleData[vid][vehiclePos][0], VehicleData[vid][vehiclePos][1], VehicleData[vid][vehiclePos][2], VehicleData[vid][vehiclePos][3], VehicleData[vid][vehicleColorOne], VehicleData[vid][vehicleColorOne], 10);

        format(string, sizeof(string), "%s - For Sale (%s)", VehicleData[vid][vehicleName], VehicleData[vid][vehiclePrice]);
        VehicleData[vid][vehicleLabel] = CreateDynamic3DTextLabel(string, -1, VehicleData[vid][vehiclePos][0], VehicleData[vid][vehiclePos][1], VehicleData[vid][vehiclePos][2], 15.0, INVALID_VEHICLE_ID, INVALID_PLAYER_ID, 0, VehicleData[vid][vehicleWorld], VehicleData[vid][vehicleInterior]);

        UpdateDynamic3DTextLabelText(VehicleData[vid][vehicleLabel], -1, string);
    }
    return 1;
}
Edit: Now the command is this:

pawn Код:
CMD:createvehicle(playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid)) return SCM(playerid, COLOR_ERROR, "* You must be on foot to create a vehicle.");
   
    if(Vehicle_Nearest(playerid) != -1) return SCM(playerid, COLOR_ERROR, "* You can't create a vehicle near another one.");
   
    new modelid[30], vehid, color1, color2, price;
   
    if(sscanf(params, "s[30]iid", modelid, color1, color2, price)) return SCM(playerid, COLOR_BELGREEN, "* [USAGE]: /createvehicle <ModelID/Vehicle Name> <Color1> <Color2> <Price>");

    if(IsNumeric(modelid)) vehid = strval(modelid);
    else vehid = ReturnVehicleModelID(modelid);

    if(vehid < 400 || vehid > 611) return SCM(playerid, COLOR_ERROR, "* Invalid vehicle model.");

    static Float:x, Float:y, Float:z, Float:angle;
   
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, angle);

    for (new i = 0; i != MAX_VEH; i ++) if(!VehicleData[i][vehicleExists])
    {
        new query[1000];
       
        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);

        if(!VehicleData[i][vehicleExists]) return 0;
    }
    return 1;
}
But getting undefined symbol "veh_index" at the tquery line.
Replace:
pawn Код:
mysql_tquery(mysql, query, "OnVehicleCreate", "dddddffffdd", veh_index, vehid, price, color1, color2, x, y, z, angle, player_interior, player_virtual_world);

if(!VehicleData[i][vehicleExists]) return 0;
with:
pawn Код:
mysql_tquery(mysql, query, "OnVehicleCreate", "dddddffffdd", i, vehid, price, color1, color2, x, y, z, angle, player_interior, player_virtual_world);

break;
We need to stop the loop upon sending the threaded query. Also replace:
pawn Код:
/*
    create the vehicle here.
    what do `Vehicle_Save` and `Vehicle_Refresh` do?
*/
with:
pawn Код:
Vehicle_Refresh(veh_index);
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: 1 Guest(s)