20.10.2013, 09:07
(
Last edited by EiresJason; 20/10/2013 at 10:27 AM.
)
This is the way you need to do it. The current way you want to save and load the houses won't work if you want the houses to be numbered on the files.
I added in some comments. I completely removed 'playerid' from the enum as you wouldnt want to store them like that.
It's best to store each house as it's own enum and then just give the player a variable storing his house number.
Also, make sure you keep backups of the code
I added in some comments. I completely removed 'playerid' from the enum as you wouldnt want to store them like that.
It's best to store each house as it's own enum and then just give the player a variable storing his house number.
Also, make sure you keep backups of the code
pawn Code:
forward CreateHouse(playerid, costs, sells, interior , virtualworld);
public CreateHouse(playerid, costs, sells, interior , virtualworld)
{
for(new h = 0; h < MAX_HOUSE; h++)
{
if(!fexist(HousePath(h))) //loops through all houses in the file, and when the file does not exist; that's the new house id.
{
//new str[256];
//format(str, sizeof(str), "%d", h);
PlayerInfo[playerid][pHouseID] = h; //store the players house id to their variable. This can be used later, when locking houses, etc. For example: See if they're infront of their house.
new Float:X, Float:Y, Float:Z;
new Float:X1, Float:Y1, Float:Z1;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerPos(playerid, X1, Y1, Z1);
GetPlayerVirtualWorld(virtualworld);
new INI:HouseFile = INI_Open(HousePath(h)); //make sure HousePath points to something like this: "/houses/%i.ini".
HouseCount++;
hInfo[h][hEnterX] = X;
hInfo[h][hEnterY] = Y;
hInfo[h][hEnterZ] = Z;
hInfo[h][hExitX] = X1;
hInfo[h][hExitY] = Y1;
hInfo[h][hExitZ] = Z1;
hInfo[h][hInterior] = interior;
hInfo[h][hCost] = costs;
hInfo[h][hSell] = sells;
hInfo[h][hVW] = virtualworld;
INI_WriteFloat(HouseFile, "EnterenceX", hInfo[h][hEnterX]);
INI_WriteFloat(HouseFile, "EnterenceY", hInfo[h][hEnterY]);
INI_WriteFloat(HouseFile, "EnterenceZ", hInfo[h][hEnterZ]);
INI_WriteFloat(HouseFile, "ExitX", hInfo[h][hExitX]);
INI_WriteFloat(HouseFile, "ExitY", hInfo[h][hExitY]);
INI_WriteFloat(HouseFile, "ExitZ", hInfo[h][hExitZ]);
INI_WriteInt(HouseFile, "Interior", hInfo[h][hInterior]);
INI_WriteInt(HouseFile, "VW", hInfo[h][hVW]);
INI_WriteInt(HouseFile, "Cost", hInfo[h][hCost]);
INI_WriteInt(HouseFile, "Sell", hInfo[h][hSell]);
INI_WriteString(HouseFile, "Phone", hInfo[h][hPhone]);
INI_WriteInt(HouseFile, "Garderobe", hInfo[h][hGarderobe]);
INI_WriteInt(HouseFile, "Garderobe1", hInfo[h][hGarderobe1]);
INI_WriteInt(HouseFile, "Storage", hInfo[h][hStorage]);
INI_WriteInt(HouseFile, "Storage1", hInfo[h][hStorage1]);
INI_WriteInt(HouseFile, "Storage2", hInfo[h][hStorage2]);
INI_WriteInt(HouseFile, "Storage3", hInfo[h][hStorage3]);
INI_WriteInt(HouseFile, "Storage4", hInfo[h][hStorage4]);
INI_WriteInt(HouseFile, "Storage5", hInfo[h][hStorage5]);
INI_WriteInt(HouseFile, "Storage6", hInfo[h][hStorage6]);
INI_WriteInt(HouseFile, "Storage7", hInfo[h][hStorage7]);
INI_WriteInt(HouseFile, "Storage8", hInfo[h][hStorage8]);
INI_WriteInt(HouseFile, "Storage9", hInfo[h][hStorage9]);
INI_WriteInt(HouseFile, "Storage10", hInfo[h][hStorage10]);
INI_WriteInt(HouseFile, "Money", hInfo[h][hMoney]);
INI_WriteInt(HouseFile, "Drugs", hInfo[h][hDrugs]);
INI_WriteInt(HouseFile, "Drugs1", hInfo[h][hDrugs1]);
INI_WriteInt(HouseFile, "Drugs2", hInfo[h][hDrugs2]);
INI_WriteInt(HouseFile, "Drugs3", hInfo[h][hDrugs3]);
INI_WriteInt(HouseFile, "Drugs4", hInfo[h][hDrugs4]);
INI_WriteInt(HouseFile, "Drugs5", hInfo[h][hDrugs5]);
INI_WriteInt(HouseFile, "Drugs6", hInfo[h][hDrugs6]);
INI_WriteInt(HouseFile, "Drugs7", hInfo[h][hDrugs7]);
INI_WriteInt(HouseFile, "Drugs8", hInfo[h][hDrugs8]);
INI_WriteInt(HouseFile, "Drugs9", hInfo[h][hDrugs9]);
INI_WriteInt(HouseFile, "Drugs10", hInfo[h][hDrugs10]);
INI_WriteInt(HouseFile, "Drugs11", hInfo[h][hDrugs11]);
INI_WriteInt(HouseFile, "Products", hInfo[h][hProducts]);
INI_WriteInt(HouseFile, "Products1", hInfo[h][hProducts1]);
INI_WriteInt(HouseFile, "Products2", hInfo[h][hProducts2]);
INI_WriteInt(HouseFile, "Products3", hInfo[h][hProducts3]);
INI_WriteInt(HouseFile, "Products4", hInfo[h][hProducts4]);
INI_WriteInt(HouseFile, "Products5", hInfo[h][hProducts5]);
INI_WriteInt(HouseFile, "Products6", hInfo[h][hProducts6]);
INI_WriteInt(HouseFile, "Products7", hInfo[h][hProducts7]);
INI_WriteInt(HouseFile, "Products8", hInfo[h][hProducts8]);
INI_WriteInt(HouseFile, "Products9", hInfo[h][hProducts9]);
INI_WriteInt(HouseFile, "Products10", hInfo[h][hProducts10]);
INI_WriteInt(HouseFile, "Products11", hInfo[h][hProducts11]);
}
}
return 1;
}
//looks through all the houses that exist in the folder and loads their data.
forward LoadHouses();
public LoadHouses()
{
for(new h=0;h<MAX_HOUSES;h++)
{
if(fexist(HousePath(h)))
{
INI_ParseFile(HousePath(h), "LoadHouseData", .bExtra = true, .extra = h);
}
}
return 1;
}
forward LoadHouseData(houseid, name[], value[]);
public LoadHouseData(houseid, name[], value[])
{
INI_String("Owner", hInfo[houseid][hOwner], MAX_PLAYER_NAME);
INI_Float("EnterenceX", hInfo[houseid][hEnterX]);
INI_Float("EnterenceY", hInfo[houseid][hEnterY]);
INI_Float("EnterenceZ", hInfo[houseid][hEnterZ]);
INI_Float("ExitX", hInfo[houseid][hExitX]);
INI_Float("ExitY", hInfo[houseid][hExitY]);
INI_Float("ExitZ", hInfo[houseid][hExitZ]);
INI_Int("Interior", hInfo[houseid][hInterior]);
INI_Int("VW", hInfo[houseid][hVW]);
INI_Int("Cost", hInfo[houseid][hCost]);
INI_Int("Sell", hInfo[houseid][hSell]);
INI_String("Phone", hInfo[houseid][hPhone], 16);
INI_Int("Garderobe", hInfo[houseid][hGarderobe]);
INI_Int("Garderobe1", hInfo[houseid][hGarderobe1]);
INI_Int("Storage", hInfo[houseid][hStorage]);
INI_Int("Storage1", hInfo[houseid][hStorage1]);
INI_Int("Storage2", hInfo[houseid][hStorage2]);
INI_Int("Storage3", hInfo[houseid][hStorage3]);
INI_Int("Storage4", hInfo[houseid][hStorage4]);
INI_Int("Storage5", hInfo[houseid][hStorage5]);
INI_Int("Storage6", hInfo[houseid][hStorage6]);
INI_Int("Storage7", hInfo[houseid][hStorage7]);
INI_Int("Storage8", hInfo[houseid][hStorage8]);
INI_Int("Storage9", hInfo[houseid][hStorage9]);
INI_Int("Storage10", hInfo[houseid][hStorage10]);
INI_Int("Money", hInfo[houseid][hMoney]);
INI_Int("Drugs", hInfo[houseid][hDrugs]);
INI_Int("Drugs1", hInfo[houseid][hDrugs1]);
INI_Int("Drugs2", hInfo[houseid][hDrugs2]);
INI_Int("Drugs3", hInfo[houseid][hDrugs3]);
INI_Int("Drugs4", hInfo[houseid][hDrugs4]);
INI_Int("Drugs5", hInfo[houseid][hDrugs5]);
INI_Int("Drugs6", hInfo[houseid][hDrugs6]);
INI_Int("Drugs7", hInfo[houseid][hDrugs7]);
INI_Int("Drugs8", hInfo[houseid][hDrugs8]);
INI_Int("Drugs9", hInfo[houseid][hDrugs9]);
INI_Int("Drugs10", hInfo[houseid][hDrugs10]);
INI_Int("Drugs11", hInfo[houseid][hDrugs11]);
INI_Int("Products", hInfo[houseid][hProducts]);
INI_Int("Products1", hInfo[houseid][hProducts1]);
INI_Int("Products2", hInfo[houseid][hProducts2]);
INI_Int("Products3", hInfo[houseid][hProducts3]);
INI_Int("Products4", hInfo[houseid][hProducts4]);
INI_Int("Products5", hInfo[houseid][hProducts5]);
INI_Int("Products6", hInfo[houseid][hProducts6]);
INI_Int("Products7", hInfo[houseid][hProducts7]);
INI_Int("Products8", hInfo[houseid][hProducts8]);
INI_Int("Products9", hInfo[houseid][hProducts9]);
INI_Int("Products10", hInfo[houseid][hProducts10]);
INI_Int("Products11", hInfo[houseid][hProducts11]);
return 1;
}