stock SellHouse()
{
new bank, notice[8], text[3],playerid;
for(new i = 1; i <= TOTALHOUSE; i++)
{
HouseInfo[i][hRobhouse] = false;
if (HouseInfo[i][hOwned] == 0) continue;
if (HouseInfo[i][hTakings] < HouseInfo[i][hPaycash])
{
playerid = INVALID_PLAYER_ID;
sscanf(HouseInfo[i][hOwner], "u", playerid);
if (IsPlayerConnected(playerid))
{
PlayerInfo[playerid][pBank] += HouseInfo[i][hValue]+HouseInfo[i][hTakings]-HouseInfo[i][hPaycash]*2;
PlayerInfo[playerid][pIDHouse] = 0;
SetPVarInt(playerid, "GetHome", 1);
}
else
{
format(query,sizeof(query), "SELECT Bank, Notice FROM "TABLE_ACCOUNT" WHERE Name = '%s'", HouseInfo[i][hOwner]);
mysql_query(query);
mysql_store_result();
if (mysql_fetch_row_format(query))
{
sscanf(query, "p<|>is[8]", bank, notice);
}
mysql_free_result();
sscanf(notice, "p<,>a<i>[3]", text);
text[0] = 1;
format(notice, sizeof(notice),"%d,%d,%d", text[0], text[1], text[2]);
bank += HouseInfo[i][hValue];
SetPlayerInt(HouseInfo[i][hOwner],"Bank",bank);
SetPlayerStr(HouseInfo[i][hOwner],"Notice",notice);
}
HouseInfo[i][hOwned] = 0;
HouseInfo[i][hHealme] = 0;
HouseInfo[i][hTakings] = 0;
strmid(HouseInfo[i][hOwner], "The State", 0, strlen("The State"), 255);
SetHouseStr(i,"Owner",HouseInfo[i][hOwner]);
SetHouseInt(i,"Owned",HouseInfo[i][hOwned]);
SetHouseInt(i,"Takings",HouseInfo[i][hTakings]);
SetHouseInt(i,"Healme",HouseInfo[i][hHealme]);
UpdateHouseInfo(i);
}
else
{
HouseInfo[i][hTakings] -= HouseInfo[i][hPaycash];
SetHouseInt(i,"Takings",HouseInfo[i][hTakings]);
}
}
return 1;
}
stock SellHouse()
{
for (new i = 1, bank, notice[8], text[3], playerid; i <= TOTALHOUSE; i++) {
HouseInfo[i][hRobhouse] = false;
if (HouseInfo[i][hOwned]) {
if (HouseInfo[i][hTakings] < HouseInfo[i][hPaycash]) {
playerid = INVALID_PLAYER_ID;
sscanf(HouseInfo[i][hOwner], "u", playerid);
if (IsPlayerConnected(playerid)) {
PlayerInfo[playerid][pBank] += (HouseInfo[i][hValue] + HouseInfo[i][hTakings] - HouseInfo[i][hPaycash] * 2);
PlayerInfo[playerid][pIDHouse] = 0;
SetPVarInt(playerid, "GetHome", 1);
} else {
format(query, sizeof(query), "SELECT Bank, Notice FROM "TABLE_ACCOUNT" WHERE Name='%s'", HouseInfo[i][hOwner]);
mysql_query(query);
mysql_store_result();
if (mysql_fetch_row_format(query)) {
sscanf(query, "p<|>is[8]", bank, notice);
mysql_free_result();
sscanf(notice, "p<,>a<i>[3]", text);
text[0] = 1;
format(notice, sizeof(notice),"%d,%d,%d", text[0], text[1], text[2]);
bank += HouseInfo[i][hValue];
SetPlayerInt(HouseInfo[i][hOwner], "Bank", bank);
SetPlayerStr(HouseInfo[i][hOwner], "Notice", notice);
}// я пологаю что если строки вдруг нет или произошла ошибка в БД надо что-то предпринять
}
HouseInfo[i][hOwned] = 0;
HouseInfo[i][hHealme] = 0;
HouseInfo[i][hTakings] = 0;
strmid(HouseInfo[i][hOwner], "The State", 0, strlen("The State"), 255);
SetHouseStr(i,"Owner",HouseInfo[i][hOwner]);
SetHouseInt(i,"Owned",HouseInfo[i][hOwned]);
SetHouseInt(i,"Takings",HouseInfo[i][hTakings]);
SetHouseInt(i,"Healme",HouseInfo[i][hHealme]);
UpdateHouseInfo(i);
} else {
HouseInfo[i][hTakings] -= HouseInfo[i][hPaycash];
SetHouseInt(i, "Takings", HouseInfo[i][hTakings]);
}
}
}
return 1;
}
stock LoadHouse()
{
new time = GetTickCount();
mysql_query("SELECT * FROM "TABLE_HOUSE" ORDER BY "TABLE_HOUSE".`ID` ASC ");
mysql_store_result();
for(new i = 1; i < TOTALHOUSE; i++)
{
strmid(BizzInfo[i][bOwner],"The_State",0,strlen("The_State"),24);
}
if (mysql_num_rows() > 0)
{
for(new idx = 1; idx <= mysql_num_rows(); idx++)
{
mysql_fetch_row(query);
sscanf(query, "p<|>iffffffs[24]iiiiis[5]iiiiffffiii",
HouseInfo[idx][hID],
HouseInfo[idx][hEnterX],
HouseInfo[idx][hEnterY],
HouseInfo[idx][hEnterZ],
HouseInfo[idx][hExitX],
HouseInfo[idx][hExitY],
HouseInfo[idx][hExitZ],
HouseInfo[idx][hOwner],
HouseInfo[idx][hValue],
HouseInfo[idx][hInt],
HouseInfo[idx][hLock],
HouseInfo[idx][hOwned],
HouseInfo[idx][hTakings],
HouseInfo[idx][hClass],
HouseInfo[idx][hPaycash],
HouseInfo[idx][hMIcon],
HouseInfo[idx][hVirtWorld],
HouseInfo[idx][hHealme],
HouseInfo[idx][hCarX],
HouseInfo[idx][hCarY],
HouseInfo[idx][hCarZ],
HouseInfo[idx][hCarA],
HouseInfo[idx][hSafe],
HouseInfo[idx][hDrugs],
HouseInfo[idx][hMoney]);
TOTALHOUSE++;
HouseInfo[idx][hRobhouse] = false;
if (HouseInfo[idx][hOwned] == 0)
{
HouseInfo[idx][hPickup] = CreatePickup(1273, 23, HouseInfo[idx][hEnterX], HouseInfo[idx][hEnterY], HouseInfo[idx][hEnterZ]);
HouseInfo[idx][hMIcon] = CreateDynamicMapIcon(HouseInfo[idx][hEnterX], HouseInfo[idx][hEnterY], HouseInfo[idx][hEnterZ], 31, 0, -1, -1, -1, 100.0);
}
if (HouseInfo[idx][hOwned] == 1)
{
HouseInfo[idx][hPickup] = CreatePickup(1272, 23, HouseInfo[idx][hEnterX ], HouseInfo[idx][hEnterY ], HouseInfo[idx][hEnterZ]);
HouseInfo[idx][hMIcon] = CreateDynamicMapIcon(HouseInfo[idx][hEnterX], HouseInfo[idx][hEnterY], HouseInfo[idx][hEnterZ], 32, 0, -1, -1, -1, 100.0);
}
}
}
mysql_free_result();
printf("---------------------------------------------------------");
printf(" [Загрузка домов]: Было загружено - %d потрачено %d (ms)", TOTALHOUSE,GetTickCount() - time);
return 1;
}
stock SetPlayerInt(username[], stolb[], znach)
{
new Query[128];
format(Query, sizeof(Query), "UPDATE "TABLE_ACCOUNT" SET %s = '%i' WHERE ID = '%s' LIMIT 1", stolb, znach, username);
return mysql_query(Query);
}
stock SetPlayerStr(username[], stolb[], znach[])
{
new Query[128];
format(Query, sizeof(Query), "UPDATE "TABLE_ACCOUNT" SET %s = '%s' WHERE Name = '%s' LIMIT 1", stolb, znach, username);
return mysql_query(Query);
}
stock SetHouseStr(idx, stolb[], znach[])
{
new Query[128];
format(Query, sizeof(Query), "UPDATE "TABLE_HOUSE" SET %s = '%s' WHERE `ID` = '%i' LIMIT 1", stolb, znach, idx);
return mysql_query(Query);
}
stock SetHouseInt(idx, stolb[], znach)
{
new Query[128];
format(Query, sizeof(Query), "UPDATE "TABLE_HOUSE" SET %s = '%i' WHERE `ID` = '%i' LIMIT 1", stolb, znach, idx);
return mysql_query(Query);
}
UpdateHouseInfo(h)
{
DestroyDynamicMapIcon(HouseInfo[h][hMIcon]);
DestroyPickup(HouseInfo[h][hPickup]);
if (HouseInfo[h][hOwned] == 0)
{
HouseInfo[h][hMIcon] = CreateDynamicMapIcon(HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ], 31, 0, -1, -1, -1, 150.0);
HouseInfo[h][hPickup] = CreatePickup(1273, 23, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]);
return 1;
}
else if (HouseInfo[h][hOwned] == 1)
{
HouseInfo[h][hMIcon] = CreateDynamicMapIcon(HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ], 32, 0, -1, -1, -1, 150.0);
HouseInfo[h][hPickup] = CreatePickup(1272, 23, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]);
return 1;
}
return 1;
}
Какая на фиг оптимизация, у тебя на каждую итерацию вызывается от 4 до 6 подзапросов!!! |
stock SetHouseInt(idx, stolb[], znach)
{
new Query[128];
format(Query, sizeof(Query), "UPDATE "TABLE_HOUSE" SET %s = '%i' WHERE `ID` = '%i' LIMIT 1", stolb, znach, idx);
return mysql_query(Query);
}
То есть все можно использовать в 1 запрос когда они одинаковые?
Например PHP код:
|