10.12.2015, 19:11
Quote:
1.Yes
2. Could you provide me with an example of how could this be implemented? |
pawn Код:
for(new i = 0; i <= rows; i++)
As for using a global housecount variable, all you need to do is create a global variable with a name of your choice, and when you call LoadHouses(), it should set the count equal to the number of rows returned by the SQL query.
pawn Код:
new HouseCount = 0;
LoadHouses()
{
new Cache:result,rows;
new label[250];
result = mysql_query(mysql, "SELECT * FROM `houses`");
HouseCount = cache_num_rows();
for(new i=0; i <= HouseCount; i++)
{
HouseInfo[i+1][hID] = cache_get_field_content_int(i, "hID");
HouseInfo[i+1][XEnt] = cache_get_field_content_float(i, "XEnt"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
HouseInfo[i+1][YEnt] = cache_get_field_content_float(i, "YEnt"); //Above
HouseInfo[i+1][ZEnt] = cache_get_field_content_float(i, "ZEnt");//Above
HouseInfo[i+1][XExit] = cache_get_field_content_float(i, "XExit");//Above. Since player's position is a float, we use cache_get_field_content_float
HouseInfo[i+1][YExit] = cache_get_field_content_float(i, "YExit");//Above
HouseInfo[i+1][ZExit] = cache_get_field_content_float(i, "ZExit");//Above
HouseInfo[i+1][HVirtualWorld] = cache_get_field_content_int(i, "HVirtualWorld");
HouseInfo[i+1][HInterior] = cache_get_field_content_int(i, "HInterior");
HouseInfo[i+1][HPrice] = cache_get_field_content_int(i, "HPrice");
HouseInfo[i+1][HOwnerID] = cache_get_field_content_int(i, "HOwnerID");
HouseInfo[i+1][HOwned] = cache_get_field_content_int(i, "HOwned");
HouseInfo[i+1][HLocked] = cache_get_field_content_int(i, "HLocked");
cache_get_field_content(i, "HName", HouseInfo[i+1][HName], 1, MAX_HOUSE_NAME);
if(HouseInfo[i+1][HOwned] == 1)
{
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[i+1][HName]);
HouseInfo[i+1][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i+1][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
printf("HOUSE ID : %d Housename : %s FloatX:%f Float Y: %f FloatZ: %f",HouseInfo[i+1][hID],HouseInfo[i+1][HName],HouseInfo[i+1][XEnt], HouseInfo[i+1][YEnt], HouseInfo[i+1][ZEnt]);
CreateDynamicPickup(HOWNED_PICKUP, 1, HouseInfo[i+1][XEnt], HouseInfo[i+1][YEnt], HouseInfo[i+1][ZEnt]);
}
else if(HouseInfo[i+1][HOwned] == 0)
{
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",HouseInfo[i][HPrice]);
HouseInfo[i][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i+1][XEnt], HouseInfo[i+1][YEnt], HouseInfo[i+1][ZEnt], 40.0);
CreateDynamicPickup(HUNOWNED_PICKUP, 1, HouseInfo[i+1][XEnt], HouseInfo[i+1][YEnt], HouseInfo[i+1][ZEnt]);
}
}
printf("Successfully Loaded All Houses! ( %d )",rows);
cache_delete(result);
}