24.05.2016, 16:01
So I'm making a dynamic vehicle system. I hope I give enough information to answer my question but not too much to be a headache. Below we have some of my /editvehicle command.
The car deletes like it's suppose to do with RespawnVehicle, but it doesn't come back. Probably because the database doesn't update but I'll show you the RespawnVehicle function:
And yes I know about SetVehicleToRespawn but this gives me more freedom.
But when I edit the spawn of the car, the database doesn't update. I'm not sure if the ID's are getting confused or what exactly is happening. But does anyone see why this would be happening?
I'll throw in my save function just incase.
pawn Код:
CMD:editvehicle(playerid, params[])
{
new id, usage[16], amount;
if(sscanf(params, "ds[16]D(0)", id, usage, amount))
{
if(Player[playerid][AdminLevel] >= 4)
{
SendClientMessage(playerid, WHITE, "USAGE: /editvehicle [id] [usage] [(optional) amount]");
return SendClientMessage(playerid, GREY, "Usages: spawn, colour(1-2), group, delete");
}
}
else if(Player[playerid][AdminLevel] >= 4)
{
if(id < 0 || id > MAX_DYN_VEHICLES) return SendClientMessage(playerid, WHITE, "That is not a valid vehicle ID!");
Array[0] = 0;
if(strcmp(usage, "spawn", true) == 0)
{
new Float:Pos[4];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
GetPlayerFacingAngle(playerid, Pos[3]);
Vehicle[id][VehiclePos][0] = Pos[0];
Vehicle[id][VehiclePos][1] = Pos[1];
Vehicle[id][VehiclePos][2] = Pos[2];
Vehicle[id][VehiclePos][3] = Pos[3];
Vehicle[id][VehicleVW] = GetPlayerVirtualWorld(playerid);
Vehicle[id][VehicleInt] = GetPlayerInterior(playerid);
format(Array, sizeof(Array), "You have moved the spawn of vehicle %d", id);
SendClientMessage(playerid, WHITE, Array);
format(Array, sizeof(Array), "[/EDITVEHICLE] %s has moved the spawn of vehicle %d to X: %f, Y: %f, Z: %f", GetName(playerid), id, Pos[0], Pos[1], Pos[2]);
}
else
{
SendClientMessage(playerid, WHITE, "USAGE: /editvehicle [id] [usage] [(optional) amount]");
return SendClientMessage(playerid, GREY, "Usages: spawn, colour(1-2), group, delete");
}
Log(4, Array);
SaveVehicle(Vehicle[id][VehID]);
RespawnVehicle(Vehicle[id][VehID]);
}
else SendClientMessage(playerid, WHITE, "You are not authorized to preform this command.");
return 1;
}
pawn Код:
RespawnVehicle(id)
{
DestroyVehicle(id);
if(Vehicle[id][VehiclePos][0] != 0.00000 && Vehicle[id][VehiclePos][1] != 0.00000 && Vehicle[id][VehiclePos][2] != 0.00000)
{
Vehicle[id][VehID] = CreateVehicle(Vehicle[id][Model], Vehicle[id][VehiclePos][0], Vehicle[id][VehiclePos][1], Vehicle[id][VehiclePos][2], Vehicle[id][VehiclePos][3], Vehicle[id][VehicleColour][0], Vehicle[id][VehicleColour][1], -1, Vehicle[id][Siren]);
SetVehicleVirtualWorld(Vehicle[id][VehID], Vehicle[id][VehicleVW]);
LinkVehicleToInterior(Vehicle[id][VehID], Vehicle[id][VehicleInt]);
}
return 1;
}
But when I edit the spawn of the car, the database doesn't update. I'm not sure if the ID's are getting confused or what exactly is happening. But does anyone see why this would be happening?
I'll throw in my save function just incase.
pawn Код:
SaveVehicle(id)
{
Array[0] = 0;
format(Array, sizeof Array, "UPDATE `vehicles` SET \
`Model` = '%d', `X` = '%f', `Y` = '%f', `Z` = '%f', `A` = %f, `VW` = '%d', `Int` = '%d', `Colour1` = '%d', `Colour2` = '%d', `Group` = '%d', `Siren` = '%d' WHERE `id` = '%d'",
Vehicle[id][Model], Vehicle[id][VehiclePos][0], Vehicle[id][VehiclePos][1], Vehicle[id][VehiclePos][2], Vehicle[id][VehiclePos][3], Vehicle[id][VehicleVW], Vehicle[id][VehicleInt],
Vehicle[id][VehicleColour][0], Vehicle[id][VehicleColour][1], Vehicle[id][VehicleGroup], Vehicle[id][Siren], Vehicle[id][VehicleDatabaseID]
);
mysql_tquery(SQL, Array, "", "");
return 1;
}