Changed it but still loads only the first house.
Here is my whole housing system.
pawn Код:
enum hInfo
{
hHouseID,
hAddress[32],
hPrice,
hPickup,
Text3D:hText,
Float:hEnterPos[3],
Float:hExitPos[3]
}
new HouseInfo[MAX_HOUSES][hInfo], houseid;
pawn Код:
public OnGameModeInit()
{
LoadHouses();
}
pawn Код:
stock CreateHouse(price, Float:PosX, Float:PosY, Float:PosZ)
{
new string[128], query[124];
HouseInfo[houseid][hHouseID] = houseid;
HouseInfo[houseid][hEnterPos][0] = PosX;
HouseInfo[houseid][hEnterPos][1] = PosY;
HouseInfo[houseid][hEnterPos][2] = PosZ;
HouseInfo[houseid][hExitPos][0] = PosX;
HouseInfo[houseid][hExitPos][1] = PosY;
HouseInfo[houseid][hExitPos][2] = PosZ;
format(HouseInfo[houseid][hAddress], 35, "1 San Fierro Drive");
HouseInfo[houseid][hPrice] = price;
format(query, sizeof(query), "INSERT INTO `Houses` (`HouseID`, `Address`, `Price`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`) VALUES (%d, \'%s\', %d, %f, %f, %f, %f, %f, %f)",
HouseInfo[houseid][hHouseID] = houseid,
HouseInfo[houseid][hAddress],
HouseInfo[houseid][hPrice],
HouseInfo[houseid][hEnterPos][0],
HouseInfo[houseid][hEnterPos][1],
HouseInfo[houseid][hEnterPos][2],
HouseInfo[houseid][hExitPos][0],
HouseInfo[houseid][hExitPos][1],
HouseInfo[houseid][hExitPos][2]
);
mysql_function_query(g_Handle, query, false, "", "");
HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 23, PosX, PosY, PosZ, -1, -1, -1, 100.0);
format(string,sizeof(string),"HouseID: %d\nAddress: %s\nPrice: %d", HouseInfo[houseid][hHouseID], HouseInfo[houseid][hAddress], HouseInfo[houseid][hPrice]);
HouseInfo[houseid][hText] = CreateDynamic3DTextLabel(string, -1, PosX, PosY, PosZ, 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100);
houseid ++;
}
pawn Код:
CMD:createhouse(playerid, params[])
{
new Float:pos[3], string[30], price;
if(!IsPlayerLoggedIn(playerid))
{
SendClientMessage(playerid, -1, "You are restricted from using commands until you log in.");
return 1;
}
if(PlayerInfo[playerid][pAdminLevel] < 1)
{
SendClientMessage(playerid, -1, "You do not have the authority to use this command.");
return 1;
}
if(!AdminDuty[playerid])
{
SendClientMessage(playerid, -1, "You are not on duty as an Administrator (/aduty).");
return 1;
}
if(sscanf(params, "i", price))
{
SendClientMessage(playerid, -1, "Usage: /createhouse <price>");
return 1;
}
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
CreateHouse(price, pos[0], pos[1], pos[2]);
format(string, sizeof(string), "You have created House ID %d.", houseid);
SendClientMessage(playerid, -1, string);
return 1;
}
pawn Код:
stock LoadHouses()
{
mysql_function_query(g_Handle, "SELECT * FROM `Houses`", true, "HousesLoad", "");
return 1;
}
pawn Код:
forward HousesLoad();
public HousesLoad()
{
new temp[400], string[120], rows, fields;
cache_get_data(rows, fields, g_Handle);
if(rows)
{
for(new id = 0; id < MAX_HOUSES; id++)
{
HouseInfo[id][hHouseID] = cache_get_row_int(id, 0, g_Handle);
cache_get_row(id, 1, HouseInfo[houseid][hAddress], g_Handle, 31);
cache_get_row(id, 2, temp, g_Handle), HouseInfo[id][hPrice] = strval(temp);
cache_get_row(id, 3, temp, g_Handle), HouseInfo[id][hEnterPos][0] = floatstr(temp);
cache_get_row(id, 4, temp, g_Handle), HouseInfo[id][hEnterPos][1] = floatstr(temp);
cache_get_row(id, 5, temp, g_Handle), HouseInfo[id][hEnterPos][2] = floatstr(temp);
cache_get_row(id, 6, temp, g_Handle), HouseInfo[id][hExitPos][0] = floatstr(temp);
cache_get_row(id, 7, temp, g_Handle), HouseInfo[id][hExitPos][1] = floatstr(temp);
cache_get_row(id, 8, temp, g_Handle), HouseInfo[id][hExitPos][2] = floatstr(temp);
HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
format(string,sizeof(string),"HouseID: %d\nAddress: %s\nPrice: %d", HouseInfo[id][hHouseID], HouseInfo[id][hAddress], HouseInfo[id][hPrice]);
HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, -1, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100);
break;
}
}
return 1;
}
Database layout for the 'Houses' table (only creates ID 0 pickup and text label on game mode start):