22.02.2019, 20:39
Just rewrote the code to show you. removed garageExists and added iterator:
Loading:
Creating:
THREAD_CHREATE_GARAGE:
/sellgarage CMD:
I don't understand WHY if the first created garage ever, is ALWAYS ID 0! I seriously don't understand why. Because if i do /sellgarage 0 *price* it works. But there is NO ID 0 on the "garages" table!
Also the debug and the SCM on /creategarage shows ID 0 too while creating.
But in the garages table EVERYTHING is perfect. (Correct ID, position price size etc.)
pawn Код:
new Iterator:Garages<MAX_GARAGES>;
pawn Код:
function LoadGarages()
{
new rows;
cache_get_row_count(rows);
if(!rows) return 1;
for(new i; i < rows; i++)
{
cache_get_value_int(i, "garageID", GarageInfo[i][garageID]);
cache_get_value_float(i, "garageX", GarageInfo[i][garagePos][0]);
cache_get_value_float(i, "garageY", GarageInfo[i][garagePos][1]);
cache_get_value_float(i, "garageZ", GarageInfo[i][garagePos][2]);
cache_get_value_float(i, "garageA", GarageInfo[i][garagePos][3]);
cache_get_value_int(i, "garageVW", GarageInfo[i][garageVW]);
cache_get_value_int(i, "garageOwnerID", GarageInfo[i][garageOwnerID]);
cache_get_value_int(i, "garageOwned", GarageInfo[i][garageOwned]);
cache_get_value_int(i, "garagePrice", GarageInfo[i][garagePrice]);
cache_get_value_int(i, "garagePlayerSellPrice", GarageInfo[i][garagePlayerSellPrice]);
cache_get_value_int(i, "garageSize", GarageInfo[i][garageSize]);
RefreshGarage(i);
Iter_Add(Garages, i);
}
return 1;
}
pawn Код:
CMD:creategarage(playerid, params[])
{
if(Player[playerid][AdminLevel] < 5) return 0;
if(Iter_Free(Garages) >= MAX_GARAGES) return SCM(playerid, COLOR_ERROR, "» Server has reached max garages limit.");
new id = Iter_Free(Garages);
new price, size;
if(sscanf(params, "dd(0)", price, size))
{
SCM(playerid, COLOR_BELGREEN, "» [USAGE]: /creategarage [price] [size(default 0)]");
return SCM(playerid, COLOR_BELGREEN, "» Size: 0 - Small Garage , 1 - Medium Garage, 2 - Big Garage.");
}
if((size < 0) || (size > 2)) return SCM(playerid, COLOR_ERROR, "» Size must be from 0 to 2.");
if((price < 1) || (price > 999999)) return SCM(playerid, COLOR_ERROR, "» Invalid price.");
GetPlayerPos(playerid, GarageInfo[id][garagePos][0], GarageInfo[id][garagePos][1], GarageInfo[id][garagePos][2]);
GetPlayerFacingAngle(playerid, GarageInfo[id][garagePos][3]);
GarageInfo[id][garagePos][0] = GarageInfo[id][garagePos][0] + (1.5 * floatsin(-GarageInfo[id][garagePos][3], degrees));
GarageInfo[id][garagePos][1] = GarageInfo[id][garagePos][1] + (1.5 * floatcos(-GarageInfo[id][garagePos][3], degrees));
GarageInfo[id][garageVW] = GetPlayerVirtualWorld(playerid);
GarageInfo[id][garagePrice] = price;
GarageInfo[id][garageSize] = size;
Iter_Add(Garages, id);
new query[300];
mysql_format(g_SQL, query, sizeof query, "INSERT INTO `garages` (`garagePrice`, `garageSize`) VALUES ('%d', '%d')", price, size);
mysql_tquery(g_SQL, query, "OnQueryFinished", "dd", id, THREAD_CREATE_GARAGE);
RefreshGarage(id);
SCMEX(playerid, COLOR_YELLOW, "» You have successfully created a garage. ID: %d - Price: %s - Size: %d", GarageInfo[id][garageID], formatInt(price), size);
printf("Garage is saved for id: %d", id);
return 1;
}
pawn Код:
function OnQueryFinished(extraid, threadid)
{
switch(threadid)
{
case THREAD_CREATE_GARAGE:
{
GarageInfo[extraid][garageID] = cache_insert_id();
SaveGarage(extraid);
}
}
return 1;
}
pawn Код:
CMD:sellgarage(playerid, params[])
{
new id, price;
if(sscanf(params, "dd", id, price)) return SCM(playerid, COLOR_BELGREEN, "» [USAGE]: /sellgarage [garage ID] [price]");
if((id < 0 || id >= MAX_GARAGES || !GarageInfo[id][garageID])) return SCM(playerid, COLOR_ERROR, "» You have specified an invalid garage ID.");
if(GarageInfo[id][garageOwnerID] != Player[playerid][ID]) return SCM(playerid, COLOR_ERROR, "» This garage is not yours.");
if(!GarageInfo[id][garageOwned]) return SCM(playerid, COLOR_ERROR, "» This garage can't be put for sale because it's unowned.");
if(GarageInfo[id][garagePlayerSellPrice] > 0) return SCM(playerid, COLOR_ERROR, "» This garage is already for sale. If you wish to change the price, you can use /changegarageprice.");
if((price < 1) || (price > 999999)) return SCM(playerid, COLOR_ERROR, "» Invalid price.");
PutGarageForSale(playerid, id, price);
RefreshGarage(id);
return 1;
}
Also the debug and the SCM on /creategarage shows ID 0 too while creating.
But in the garages table EVERYTHING is perfect. (Correct ID, position price size etc.)