05.01.2015, 14:33
(
Last edited by JonathanW; 06/01/2015 at 09:48 AM.
)
Look Down..
if(rows > 0)
I'm not really sure if this would work, try changing your if statement at SpawnPlayerVehicle to;
pawn Code:
|
printf("ID: %d, Plate: %s, Owner: %s",VehicleInfo[i][vActualID], VehicleInfo[i][vPlate], VehicleInfo[i][vOwner]);
printf("ID: %d, Plate: %s, Owner: %s",VehicleInfo[i][vActualID], VehicleInfo[OwnedVehicle[playerid][i][vID]][vPlate],VehicleInfo[OwnedVehicle[playerid][i][vID]][vOwner]);
stock CreatePlayerVehicle(playerid, Model, Color1, Color2, Price, Float:x, Float:y, Float:z, Float:a, Locked = 0, Plate[] = "")
{
// Setup local variables
new name[MAX_PLAYER_NAME], query[800], Slot;
// Check if the player doesn't have 3 vehicles yet
for (Slot = 0; Slot < 3; Slot++)
{
// Check if the current slot is free (no valid vehicleid, as those start with "1" for the first vehicle created)
// When the slot is free, use "break" to exit the loop and hold the current Slot value
if (OwnedVehicle[playerid][Slot] == 0)
break;
}
// If the player already has 3 vehicles (Slot would point to "3"), exit the function with a message
if (Slot == 3) return SendClientMessage(playerid, 0xFF0000FF, "You can only have 3 vehicles");
// Immediately create a new vehicle on the server with the data provided
new vehicleid = CreateVehicle(Model, x, y, z, a, Color1, Color2, 60);
// Set numberplate directly to the vehicle
SetVehicleNumberPlate(vehicleid, Plate);
// Get the player's name
GetPlayerName(playerid, name, sizeof(name));
// Store all data about the new player-vehicle
format(VehicleInfo[vehicleid][vOwner], MAX_PLAYER_NAME, "%s", name);
format(VehicleInfo[vehicleid][vPlate], 12, "%s", Plate);
VehicleInfo[vehicleid][vModel] = Model;
VehicleInfo[vehicleid][vX] = x;
VehicleInfo[vehicleid][vY] = y;
VehicleInfo[vehicleid][vZ] = z;
VehicleInfo[vehicleid][vA] = a;
VehicleInfo[vehicleid][vColor1] = Color1;
VehicleInfo[vehicleid][vColor2] = Color2;
// Other data can also be stored in case you need it
// Here, we store which vehicleid the player has
OwnedVehicle[playerid][Slot] = vehicleid;
// Now it's time to save the vehicledata to your database
mysql_format(handle, query, sizeof(query), "INSERT INTO `vehicles` (vModel, vOwner, vOwnerID, vColor1, vColor2, vPrice, vX, vY, vZ, vA, vLocked, vPlate) \
VALUES ('%i', '%e', '%i', '%i', '%i', '%i', '%f', '%f', '%f', '%f', '%i', '%s')", Model, name, Character[playerid][CurrentCharacter[playerid]][ID], Color1, Color2, Price, x, y, z, a, Locked, Plate);
// Execute the query and call a callback when the vehicle has been inserted
mysql_tquery(handle, query, "GetVehicleSQLID", "i", vehicleid);
}
// Since you only need the vehicleid for each vehicle, you don't need an enum here
new OwnedVehicle[MAX_PLAYERS][3];
forward GetVehicleSQLID(vehicleid);
public GetVehicleSQLID(vehicleid)
{
// Get the new index in MySQL where the vehicle got inserted (this must be the auto-increment column and it must also be set as PRIMARY KEY)
VehicleInfo[vehicleid][vID] = cache_insert_id();
return 1;
}