10.03.2014, 14:12
Из-за чего не сохраняет машины? Возможно ли что переменные обнуляються раньше чем срабатывает каллбэк SavePlayerBikeOrVehicle и из-за этого существующую машину удаляет из базы данных? Если возможно значит проблема в этом(потому что на R5 все было нормально). Как исправить этот баг?
PHP Code:
public OnPlayerDisconnect(playerid, reason)
{
SaveVehicle(playerid, true);
SavePlayer(playerid, true);
return 1;
}
PHP Code:
stock SaveVehicle(playerid, bool:mode = false)
{
new oQuery[64];
mysql_format(MYSQL_ARG, oQuery, 64, "SELECT * FROM `vehicles` WHERE `Owner` = '%s'", GetPlayerNameEx(playerid));
mysql_function_query(MYSQL_ARG, oQuery, true, "SavePlayerBikeOrVehicle", "dsddd", playerid, GetPlayerNameEx(playerid), pInfo[playerid][vCarID], mode, 1);
return 1;
}
PHP Code:
stock SavePlayer(playerid, bool:mode = false)
{
...
ClearChar(playerid); // Обнуляю все переменные
return 1;
}
PHP Code:
forward SavePlayerBikeOrVehicle(playerid, name[], vehicleid, bool:mode, k);
public SavePlayerBikeOrVehicle(playerid, name[], vehicleid, bool:mode, k)
{
new rows, fields, Float:vPos[4], oQuery[183];
cache_get_data(rows, fields);
switch(k)
{
case 1:
{
new Float:hp;
if(rows && vehicleid == INVALID_VEHICLE_ID)
{
mysql_format(MYSQL_ARG, oQuery, 62, "DELETE FROM `vehicles` WHERE `Owner` = '%s'", name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
return 1;
}
if(vehicleid != INVALID_VEHICLE_ID)
{
GetVehiclePos(vehicleid, vPos[0], vPos[1], vPos[2]);
GetVehicleZAngle(vehicleid, vPos[3]);
GetVehicleHealth(vehicleid, hp);
tInfo[vehicleid][vLastPos][0] = vPos[0];
tInfo[vehicleid][vLastPos][1] = vPos[1];
tInfo[vehicleid][vLastPos][2] = vPos[2];
tInfo[vehicleid][vLastPos][3] = vPos[3];
if(!rows)
{
mysql_format(MYSQL_ARG, oQuery, 161, "INSERT INTO `vehicles` (Owner, Model, Pos_X, Pos_Y, Pos_Z, Pos_A) VALUES ('%s', '%d', '%.4f', '%.4f', '%.4f', '%.4f')", name, GetVehicleModel(vehicleid), vPos[0], vPos[1], vPos[2], vPos[3]);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
}
mysql_format(MYSQL_ARG, oQuery, 173, "UPDATE `vehicles` SET `Model` = '%d', `Pos_X` = '%.4f', `Pos_Y` = '%.4f', `Pos_Z` = '%.4f', `Pos_A` = '%.4f' WHERE `Owner` = '%s'", GetVehicleModel(vehicleid), vPos[0], vPos[1], vPos[2], vPos[3], name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
mysql_format(MYSQL_ARG, oQuery, 160, "UPDATE `vehicles` SET `Health` = '%.1f', `Rida` = '%.1f', `Fuel` = '%d', `Color1` = '%d', `Color2` = '%d' WHERE `Owner` = '%s'", hp, tInfo[vehicleid][Rida], tInfo[vehicleid][Fuel], tInfo[vehicleid][vColor][0], tInfo[vehicleid][vColor][1], name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
mysql_format(MYSQL_ARG, oQuery, 183, "UPDATE `vehicles` SET `Paintjob` = '%d', `Insurance` = '%d', `Technekine` = '%d', `Locked` = '%d', `Numeriai` = '%s' WHERE `Owner` = '%s'", tInfo[vehicleid][Paintjob], tInfo[vehicleid][Draudimas], tInfo[vehicleid][Technekine], tInfo[vehicleid][vLocked], tInfo[vehicleid][Numeriai], name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
mysql_format(MYSQL_ARG, oQuery, 94, "UPDATE `vehicles` SET `Alarm` = '%d', `Tune0` = '%d' WHERE `Owner` = '%s'", tInfo[vehicleid][vAlarm], GetVehicleComponentInSlot(vehicleid, 0), name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
mysql_format(MYSQL_ARG, oQuery, 151, "UPDATE `vehicles` SET `Tune1` = '%d', `Tune2` = '%d', `Tune3` = '%d', `Tune4` = '%d', `Tune5` = '%d' WHERE `Owner` = '%s'", GetVehicleComponentInSlot(vehicleid, 1), GetVehicleComponentInSlot(vehicleid, 2), GetVehicleComponentInSlot(vehicleid, 3), GetVehicleComponentInSlot(vehicleid, 4), GetVehicleComponentInSlot(vehicleid, 5), name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
mysql_format(MYSQL_ARG, oQuery, 151, "UPDATE `vehicles` SET `Tune6` = '%d', `Tune7` = '%d', `Tune8` = '%d', `Tune9` = '%d', `Tune10` = '%d' WHERE `Owner` = '%s'", GetVehicleComponentInSlot(vehicleid, 6), GetVehicleComponentInSlot(vehicleid, 7), GetVehicleComponentInSlot(vehicleid, 8), GetVehicleComponentInSlot(vehicleid, 9), GetVehicleComponentInSlot(vehicleid, 10), name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
mysql_format(MYSQL_ARG, oQuery, 165, "UPDATE `vehicles` SET `Tune11` = '%d', `Tune12` = '%d', `Tune13` = '%d', `KadaValge` = '%.1f', `KredVeh` = '%d' WHERE `Owner` = '%s'", GetVehicleComponentInSlot(vehicleid, 11), GetVehicleComponentInSlot(vehicleid, 12), GetVehicleComponentInSlot(vehicleid, 13), tInfo[vehicleid][KadaValge], tInfo[vehicleid][KredVeh], name);
mysql_tquery(MYSQL_ARG, oQuery, "", "");
if(mode)
{
DestroyVehicleEx(vehicleid);
pInfo[playerid][vCarID] = INVALID_VEHICLE_ID;
}
}
}
}
return 1;
}