05.06.2013, 12:15
Hello,
On my previous threat I found the problem, but since it would confuse people I will ask my 2nd problem here.
If load a car from the database I use this:
the (vehicleid) is the carfileid, discovered in my previous problem.
But when I save a vehicle, it also goes through this public function but it does not assign a CarFileID even though the Log sais it did.
Command to save a vehicle:
Public to save it into the db.
Can anyone help me?
On my previous threat I found the problem, but since it would confuse people I will ask my 2nd problem here.
If load a car from the database I use this:
pawn Код:
public LoadVehiclesCallback(vehicleid)
{
new
rows,
fields;
cache_get_data(rows, fields);
if(rows == 1)
{
new temp[50];
Vehicles[vehicleid][CarFileID] = vehicleid;
cache_get_row(0, 2, temp);
Vehicles[vehicleid][ModelID] = strval(temp);
cache_get_row(0, 3, temp);
Vehicles[vehicleid][Color1] = strval(temp);
cache_get_row(0, 4, temp);
Vehicles[vehicleid][Color2] = strval(temp);
cache_get_row(0, 5, temp);
Vehicles[vehicleid][VPosX] = floatstr(temp);
cache_get_row(0, 6, temp);
Vehicles[vehicleid][VPosY] = floatstr(temp);
cache_get_row(0, 7, temp);
Vehicles[vehicleid][VPosZ] = floatstr(temp);
cache_get_row(0, 8, temp);
Vehicles[vehicleid][VPosAngle] = floatstr(temp);
cache_get_row(0, 9, temp);
Vehicles[vehicleid][LockStatus] = strval(temp);
cache_get_row(0, 10, temp);
Vehicles[vehicleid][FactionCar] = strval(temp);
cache_get_row(0, 11, Vehicles[vehicleid][VOwner]);
cache_get_row(0, 12, Vehicles[vehicleid][VPlate]);
cache_get_row(0, 13, temp);
Vehicles[vehicleid][VehicleWorld] = strval(temp);
cache_get_row(0, 14, temp);
Vehicles[vehicleid][VehicleInteriorID] = strval(temp);
cache_get_row(0, 15, temp);
Vehicles[vehicleid][SpeedoColor] = strval(temp);
cache_get_row(0, 16, temp);
Vehicles[vehicleid][Impounded] = strval(temp);
cache_get_row(0, 17, temp);
Vehicles[vehicleid][FlashAble] = strval(temp);
if(Vehicles[vehicleid][Impounded] == 1)
{
if(VehicleJustImpounded[vehicleid] == 1)
{
ImpoundCount++;
if(ImpoundCount >= 48)
{
ImpoundCount = 0;
}
//new rand = random(sizeof(RandomImpoundSpawn));
//Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[rand][0], RandomImpoundSpawn[rand][1], RandomImpoundSpawn[rand][2], RandomImpoundSpawn[rand][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[ImpoundCount][0], RandomImpoundSpawn[ImpoundCount][1], RandomImpoundSpawn[ImpoundCount][2], RandomImpoundSpawn[ImpoundCount][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
new NewCar = Vehicles[vehicleid][VehicleID];
SetVehicleVirtualWorld(NewCar, 0);//set vw
LinkVehicleToInterior(NewCar, 0);//set int
SetVehicleNumberPlate(NewCar, Vehicles[NewCar][VPlate]);
Vehicles[NewCar][Fuel] = 100;
Vehicles[NewCar][Battery] = 100;
VehicleJustImpounded[NewCar] = 0;
}
else
{
new rand = random(sizeof(RandomImpoundSpawn));
Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[rand][0], RandomImpoundSpawn[rand][1], RandomImpoundSpawn[rand][2], RandomImpoundSpawn[rand][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
new NewCar = Vehicles[vehicleid][VehicleID];
SetVehicleVirtualWorld(NewCar, Vehicles[NewCar][VehicleID]+1);//set vw
LinkVehicleToInterior(NewCar, Vehicles[NewCar][VehicleInteriorID]);//set int
SetVehicleNumberPlate(NewCar, Vehicles[NewCar][VPlate]);
Vehicles[NewCar][Fuel] = 100;
Vehicles[NewCar][Battery] = 100;
}
}
else
{
Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], Vehicles[vehicleid][VPosX], Vehicles[vehicleid][VPosY], Vehicles[vehicleid][VPosZ], Vehicles[vehicleid][VPosAngle], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
new NewCar = Vehicles[vehicleid][VehicleID];
SetVehicleVirtualWorld(NewCar, Vehicles[NewCar][VehicleWorld]);//set vw
LinkVehicleToInterior(NewCar, Vehicles[NewCar][VehicleInteriorID]);//set int
SetVehicleNumberPlate(NewCar, Vehicles[NewCar][VPlate]);
Vehicles[NewCar][Fuel] = 100;
Vehicles[NewCar][Battery] = 100;
}
Vehicles[Vehicles[vehicleid][VehicleID]][SavedCar] = 1;
new query[500];
format(query, sizeof(query), "UPDATE `Vehicles` SET `VehicleID` = %d WHERE `CarFileID` = %d", Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][CarFileID]);
mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
printf("[System] Vehicle %d has been succesfully spawned, File ID: %d!", Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][CarFileID]);
SpawnedVehicles++;
}
return 1;
}
But when I save a vehicle, it also goes through this public function but it does not assign a CarFileID even though the Log sais it did.
Код:
//more log lines was here [16:08:06] [System] Vehicle 27 has been succesfully spawned, File ID: 27! [16:08:06] [System] Vehicle 28 has been succesfully spawned, File ID: 28! [16:08:06] [System] Vehicle 29 has been succesfully spawned, File ID: 29! [16:08:06] [System] Vehicle 30 has been succesfully spawned, File ID: 30! [16:08:06] [System] Vehicle 31 has been succesfully spawned, File ID: 31! [16:08:06] [System] Vehicle 32 has been succesfully spawned, File ID: 32! [16:08:06] [System] Vehicle 33 has been succesfully spawned, File ID: 33! [16:08:06] [System] Vehicle 34 has been succesfully spawned, File ID: 35! [16:08:06] [System] Vehicle 35 has been succesfully spawned, File ID: 36! [16:08:06] [System] Vehicle 36 has been succesfully spawned, File ID: 38! [16:08:12] [System] House 1 has been succesfully spawned! [16:08:12] [System] House 2 has been succesfully spawned! [16:08:12] [System] House 3 has been succesfully spawned! [16:08:34] Incoming connection: 83.82.158.32:60686 [16:08:34] [join] Stefand. has joined the server (0:83.82.158.32) [16:09:35] [System] Vehicle 37 has been succesfully spawned, File ID: 34! //saved a vehicle
pawn Код:
command(savecar, playerid, params[])
{
new carid = GetPlayerVehicleID(playerid);
if(AdminLoggedIn[playerid] == 1 && Player[playerid][Adminlevel] >= 6)
{
new NewCar = SpawnedVehicles+1;
if(NewCar <= MAX_VEHICLES)
{
if(IsPlayerInAnyVehicle(playerid))
{
new VehPlate[255];
format(VehPlate, 255, "%s", GetFreeVehiclePlate());
Vehicles[carid][ModelID] = GetVehicleModel(carid);
Vehicles[carid][Color1] = 0;
Vehicles[carid][Color2] = 0;
GetVehiclePos(carid, Vehicles[carid][VPosX], Vehicles[carid][VPosY], Vehicles[carid][VPosZ]);
GetVehicleZAngle(carid, Vehicles[carid][VPosAngle]);
Vehicles[carid][FactionCar] = 0;
format(Vehicles[carid][VOwner], 255, "None");
format(Vehicles[carid][VPlate], 255, "%s", VehPlate);
Vehicles[carid][VehicleWorld] = GetVehicleVirtualWorld(carid);
Vehicles[carid][VehicleInteriorID] = GetPlayerInterior(playerid);
//SavingVehiclePlayerID = playerid;
new query[2000];
format(query, sizeof(query), "SELECT * FROM `Vehicles` WHERE `VehicleID` = %d", carid);
mysql_function_query(g_connectionHandle, query, true, "SaveVehicleCallback", "dd", carid, playerid);
}
}
else
{
SCM(playerid, WARNRED, "Too Many cars are currenlty spawned");
}
}
else
{
RemoveTextMessage(playerid);
TextDrawShowForPlayer(playerid, Text:CantCommand);
SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
}
return 1;
}
pawn Код:
public SaveVehicleCallback(vehicleid, playerid)
{
new
rows,
fields;
cache_get_data(rows, fields);
if(rows == 1)
{
//SendClientMessage(SavingVehiclePlayerID, WARNRED, "This Vehicle already exists");
SendClientMessage(playerid, WARNRED, "This Vehicle already exists");
}
else if(rows == 0)
{
new query[2000];
new VSLOT = GetFreeVehicleSlot();
format(query, sizeof(query), "INSERT INTO `Vehicles` (`CarFileID`, `ModelID`, `VehicleID`,`VOwner`, `VPlate`, `VehicleWorld`, `VehicleInteriorID`) VALUES ");
format(query, sizeof(query), "%s(%d, %d, %d, '%s', '%s', %d, %d)",
query,
VSLOT,
Vehicles[vehicleid][ModelID],
vehicleid,
Vehicles[vehicleid][VOwner],
Vehicles[vehicleid][VPlate],
Vehicles[vehicleid][VehicleWorld],
Vehicles[vehicleid][VehicleInteriorID]);
mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
format(query, sizeof(query), "UPDATE `Vehicles` SET `Color1`= %d, `Color2` = %d, `VPosX` = '%f', `VPosY` = '%f', `VPosZ` = '%f', `VPosAngle` = '%f', `FactionCar` = %d WHERE `CarFileID` = %d",
Vehicles[vehicleid][Color1],
Vehicles[vehicleid][Color2],
Vehicles[vehicleid][VPosX],
Vehicles[vehicleid][VPosY],
Vehicles[vehicleid][VPosZ],
Vehicles[vehicleid][VPosAngle],
Vehicles[vehicleid][FactionCar],
VSLOT);
mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
DestroyVehicle(vehicleid);
SpawnedVehicles--;
new query2[400];
format(query2, sizeof(query2), "SELECT * FROM `Vehicles` WHERE `CarFileID` = %d", VSLOT); // Selects all the information from the table
mysql_function_query(g_connectionHandle, query2, true, "LoadVehiclesCallback", "d", VSLOT);
SendClientMessage(playerid, GREEN, "Vehicle Saved!");
//SendClientMessage(SavingVehiclePlayerID, GREEN, "Vehicle Saved!");
//SavingVehiclePlayerID = -1;
}
else
{
//SendClientMessage(SavingVehiclePlayerID, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
SendClientMessage(playerid, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
}
return 1;
}