24.05.2016, 23:04
I've persevered from my previous issue but now there's a new one. One with ID's. Because I'm working with three different ID's here, it's sort of difficult to pinpoint which one I should be using where. I'm working with the ROW when I load from MySQL, the DB ID of the vehicle, and the VID in game.
This is my load function: Rows are starting at zero bear in mind.
This successfully creates vehicles and the print that I put in looks like this for the two cars I have created: (I've laid it out in a table)
Perfect, it does what it's suppose to do. But when I do /editvehicle 1 spawn (which is designed to move vehicle ID 1's spawn and save it's new location) it moves vehicle ID 2, and saves it's coordinates to DBID 2 in the database. The possible issues I'm having are probably with wrongly used ID's somewhere in the /editvehicle command.
Here you go: (I'll only show the 'spawn' option just to spare you a headache.)
Any reason why the ID's are getting mismatched and confused?
This is my load function: Rows are starting at zero bear in mind.
PHP код:
forward InitiateVehicles();
public InitiateVehicles()
{
new rows, fields, vehicles;
cache_get_data(rows, fields);
for(new row; row < MAX_DYN_VEHICLES; row++)
{
Vehicle[row][VehicleDatabaseID] = cache_get_field_content_int(row, "id", SQL);
Vehicle[row][Model] = cache_get_field_content_int(row, "Model", SQL);
Vehicle[row][VehiclePos][0] = cache_get_field_content_float(row, "X", SQL);
Vehicle[row][VehiclePos][1] = cache_get_field_content_float(row, "Y", SQL);
Vehicle[row][VehiclePos][2] = cache_get_field_content_float(row, "Z", SQL);
Vehicle[row][VehiclePos][3] = cache_get_field_content_float(row, "A", SQL);
Vehicle[row][VehicleVW] = cache_get_field_content_int(row, "VW", SQL);
Vehicle[row][VehicleInt] = cache_get_field_content_int(row, "Int", SQL);
Vehicle[row][VehicleColour][0] = cache_get_field_content_int(row, "Colour1", SQL);
Vehicle[row][VehicleColour][1] = cache_get_field_content_int(row, "Colour2", SQL);
Vehicle[row][VehicleGroup] = cache_get_field_content_int(row, "Group", SQL);
Vehicle[row][Siren] = cache_get_field_content_int(row, "Siren", SQL);
if(Vehicle[row][VehiclePos][0] != 0.00000 && Vehicle[row][VehiclePos][1] != 0.00000 && Vehicle[row][VehiclePos][2] != 0.00000)
{
Vehicle[row][VehID] = CreateVehicle(Vehicle[row][Model], Vehicle[row][VehiclePos][0], Vehicle[row][VehiclePos][1], Vehicle[row][VehiclePos][2], Vehicle[row][VehiclePos][3], Vehicle[row][VehicleColour][0], Vehicle[row][VehicleColour][1], -1, Vehicle[row][Siren]);
SetVehicleVirtualWorld(Vehicle[row][VehID], Vehicle[row][VehicleVW]);
LinkVehicleToInterior(Vehicle[row][VehID], Vehicle[row][VehicleInt]);
}
printf("%d | %d | %d", row, Vehicle[row][VehicleDatabaseID], Vehicle[row][VehID]);
vehicles++;
}
switch(vehicles)
{
case 0: printf("[SCRIPT-LOAD/ERR] The script initiated 0 vehicles.", vehicles);
default: printf("[SCRIPT-LOAD] The script has initiated %d vehicles", vehicles);
}
}
pawn Код:
ROW|DID|VID
[18:53:18] 0 | 1 | 1
Here you go: (I'll only show the 'spawn' option just to spare you a headache.)
PHP код:
CMD:editvehicle(playerid, params[])
{
new id, usage[16], amount;
if(sscanf(params, "ds[16]D(0)", id, usage, amount))
{
if(Player[playerid][AdminLevel] >= 5)
{
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] >= 5)
{
if(id < 1 || id > MAX_VEHICLES) return SendClientMessage(playerid, WHITE, "That is not a valid vehicle ID!");
if(Vehicle[id][VehicleDatabaseID] < 1) return SendClientMessage(playerid, WHITE, "That is not a valid dynamic 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);
RespawnVehicle(id);
SaveVehicle(id);
}
else SendClientMessage(playerid, WHITE, "You are not authorized to preform this command.");
return 1;
}