12.01.2013, 03:19
When my friend and I tested the code for this that we developed it didn't work. I'm not entirely sure why because I'm setting it from the seller to the buyer. The code below is what I have. It does take away the money from the buyer and gives it to the seller but it doesn't do the rest of the command and it also gives an error that it's an invalid command.
I get no errors/warnings when I compile this code. I have no idea what's going on. Help would be greatly appreciated!
When I added these 3 lines, not sure which one is breaking it, but that's when it began to display that error. Without those lines, the vehicle doesn't transfer correctly.
I get no errors/warnings when I compile this code. I have no idea what's going on. Help would be greatly appreciated!
Код:
//Seller (get slot #)
for(new t = 0; t < MAX_PLAYERVEHICLES; t++)
{
if(Vehicles[from][t][vVehicle] != INVALID_VEHICLE_ID)
{
countz++;
}
else
{
z = t;
break;
}
}
//Buyer (get slot #)
for(new e = 0; e < MAX_PLAYERVEHICLES; e++)
{
if(Vehicles[to][e][vVehicle] != INVALID_VEHICLE_ID)
{
count++;
}
else
{
i = e;
break;
}
}
if(count == MAX_PLAYERVEHICLES) return SendClientMessage(from, COLOR_GRAD3, "That player already has the maximum amount of vehicles.");
if(count == MAX_PLAYERVEHICLES) return SendClientMessage(to, COLOR_GRAD3, "You already have the maximum amount of vehicles allowed.");
GivePlayerMoney(to, -amount); //Take money from the purchaser
PlayerInfo[to][pCash] -= amount;
GivePlayerMoney(from, amount); //Give money to the vehicle owner
PlayerInfo[from][pCash] += amount;
format(string2, sizeof(string2), "UPDATE `vehicles` SET `player`='%s', `id`='%d' WHERE `player`='%s'",
pNameEx(to),
i,
pNameEx(from)
);
mysql_query(string2);
/** Set the buyer **/
Vehicles[to][i][vModel] = Vehicles[from][z][vModel];
Vehicles[to][i][vSpawnX] = Vehicles[from][z][vSpawnX];
Vehicles[to][i][vSpawnY] = Vehicles[from][z][vSpawnY];
Vehicles[to][i][vSpawnZ] = Vehicles[from][z][vSpawnZ];
Vehicles[to][i][vSpawnR] = Vehicles[from][z][vSpawnR];
Vehicles[to][i][vSpawnInt] = Vehicles[from][z][vSpawnInt];
Vehicles[to][i][vSpawnVW] = Vehicles[from][z][vSpawnVW];
Vehicles[to][i][vColors][0] = Vehicles[from][z][vColors][0];
Vehicles[to][i][vColors][1] = Vehicles[from][z][vColors][1];
Vehicles[to][i][vTickets] = Vehicles[from][z][vTickets];
Vehicles[to][i][vImpounded] = Vehicles[from][z][vImpounded];
Vehicles[to][i][vLocked] = Vehicles[from][z][vLocked];
for(new m = 0; m < 14; m++)
{
Vehicles[to][i][vMods][m] = Vehicles[from][z][vMods][m];
}
Vehicles[to][i][vVehicle] = Vehicles[from][z][vVehicle];
Vehicles[to][i][vLabel] = Vehicles[from][z][vLabel];
Fuel[Vehicles[to][i][vVehicle]] = Fuel[Vehicles[from][z][vVehicle]];
/** Make the seller no longer have access to the vehicle **/
Vehicles[from][z][vModel] = INVALID_VEHICLE_ID;
Vehicles[from][z][vSpawnX] = INVALID_VEHICLE_ID;
Vehicles[from][z][vSpawnY] = INVALID_VEHICLE_ID;
Vehicles[from][z][vSpawnZ] = INVALID_VEHICLE_ID;
Vehicles[from][z][vSpawnR] = INVALID_VEHICLE_ID;
Vehicles[from][z][vSpawnInt] = INVALID_VEHICLE_ID;
Vehicles[from][z][vSpawnVW] = INVALID_VEHICLE_ID;
Vehicles[from][z][vColors][0] = INVALID_VEHICLE_ID;
Vehicles[from][z][vColors][1] = INVALID_VEHICLE_ID;
Vehicles[from][z][vTickets] = INVALID_VEHICLE_ID;
Vehicles[from][z][vImpounded] = INVALID_VEHICLE_ID;
Vehicles[from][z][vLocked] = INVALID_VEHICLE_ID;
for(new m = 0; m < 14; m++)
{
Vehicles[from][z][vMods][m] = INVALID_VEHICLE_ID;
}
Vehicles[from][z][vVehicle] = INVALID_VEHICLE_ID;
DestroyDynamic3DTextLabel(Vehicles[from][z][vLabel]);
Fuel[Vehicles[from][z][vVehicle]] = INVALID_VEHICLE_ID;
SendClientMessage(to, COLOR_WHITE, "You have successfully purchased the vehicle from this person.");
SendClientMessage(from, COLOR_WHITE, "You have successfully sold your vehicle to this person.");
format(string, sizeof(string), "takes out his keys for his vehicle and hands it to the new owner, %s.", pName(to));
cmd_me(from, string);
//After purchasing the vehicle, set variables back to 0
SellCarType[playerid] = 0;
SellCarTo[playerid] = 0;
SellCarAmount[playerid] = 0;
SellCarFrom[playerid] = 0;
Код:
Vehicles[to][i][vVehicle] = Vehicles[from][z][vVehicle]; Vehicles[to][i][vLabel] = Vehicles[from][z][vLabel]; Fuel[Vehicles[to][i][vVehicle]] = Fuel[Vehicles[from][z][vVehicle]];

