house owned variable not saving (y_INI)
#1

Hello,

I am developing a house system for rp server. In my enum, one of my variables is hOwned which is set to 1 if someone buys house. The thing is that this variable doesn't save like the Player variables. I have a timer which should save it every 10 seconds but it does not.
Код:
#define MAX_HOUSES 10
new Text3D:housetextsell[MAX_HOUSES];
new Text3D:housetextlock[MAX_HOUSES];
forward LoadHouse_data(houseid,name[],value[]);
enum hInfo
{
	Float:hEnterx,
	Float:hEntery,
	Float:hEnterz,
	Float:hExitx,
	Float:hExity,
	Float:hExitz,
	hOwned,
	hInterior,
	hPrice,
	hLocked
}
new Float:HouseInfo[MAX_HOUSES][hInfo];
forward houseinfo();
Код:
public OnGamemodeInit()
{
    SetTimer("savestats",10000,1); // saving player and house stats each minute
}
	for(new i=0;i<MAX_HOUSES;i++)
	{
		INI_ParseFile(HousePath(i), "LoadHouse_%s", .bExtra = true, .extra = i);
		if(IsValidHouse(i))
		{
		    if(HouseInfo[i][hOwned]==0)
			{
				new housepricetext[50];
				format(housepricetext,sizeof(housepricetext),"Nehnutelnosќ - Na predaj. Cena: %i",HouseInfo[i][hPrice]);
				housetextsell[i]=Create3DTextLabel(housepricetext,COLOR_YELLOW,HouseInfo[i][hEnterx],HouseInfo[i][hEntery],HouseInfo[i][hEnterz],10,0,1);
 			}
		    else housetextsell[i]=Create3DTextLabel("Nehnutelnosќ - Predanб",COLOR_YELLOW,HouseInfo[i][hEnterx],HouseInfo[i][hEntery],HouseInfo[i][hEnterz],10,0,1);
		    if(HouseInfo[i][hLocked]==0) housetextlock[i]=Create3DTextLabel("Odomknutй",COLOR_RED,HouseInfo[i][hEnterx],HouseInfo[i][hEntery],HouseInfo[i][hEnterz]-0.1,10,0,1);
		    else housetextlock[i]=Create3DTextLabel("Zamknutй",COLOR_RED,HouseInfo[i][hEnterx],HouseInfo[i][hEntery],HouseInfo[i][hEnterz]-0.1,10,0,1);
		}
	}
	return 1;
Код:
stock IsValidHouse(houseid)
{
	if(fexist(HousePath(houseid))) return 1;
	else return 0;
}
Код:
public savestats()
{
	for(new i=0;i<MAX_PLAYERS;i++)
	{
	    if(IsPlayerConnected(i))
	    {
	        new INI:File = INI_Open(UserPath(i));
    		INI_SetTag(File,"Player Info Save");
    		INI_WriteInt(File,"House",PlayerInfo[i][pHouse]);
    		INI_WriteInt(File,"Cash",PlayerInfo[i][pCash]);
    		INI_Close(File);
    		return 1;
	    }
	}
	for(new i=0;i<MAX_HOUSES;i++)
	{
	    if(IsValidHouse(i))
	    {
	        new INI:File = INI_Open(HousePath(i));
	        INI_WriteInt(File,"Owned",HouseInfo[i][hOwned]);
	        INI_WriteInt(File,"Locked",HouseInfo[i][hLocked]);
	        INI_Close(File);
	    }
	}
	return 1;
}
Appreciate any help. Thanks
Reply
#2

What is it storing in the ini? Is it writing it as 0 or leaving it blank, by that i mean is it like hOwned 0 or just "hOwned" and the value blank? If so, then when you are buying your house its not updating the house variables data.

also check that the data is being wrote to the right file and not somewhere else.

Maybe try checking it again, hope this helps
Reply
#3

Quote:
Originally Posted by azzerking
Посмотреть сообщение
What is it storing in the ini? Is it writing it as 0 or leaving it blank, by that i mean is it like hOwned 0 or just "hOwned" and the value blank? If so, then when you are buying your house its not updating the house variables data.

also check that the data is being wrote to the right file and not somewhere else.

Maybe try checking it again, hope this helps
oh, sorry. I forgot to add those. Here you go

Код:
CMD:buyhouse(playerid,params[])
{
	if(IsPlayerInRangeOfPoint(playerid,2,HouseInfo[PlayerInfo[playerid][pHouse]][hEnterx],HouseInfo[PlayerInfo[playerid][pHouse]][hEntery],HouseInfo[PlayerInfo[playerid][pHouse]][hEnterz])) return SendClientMessage(playerid,COLOR_RED,"You own this house already.");
 	if(PlayerInfo[playerid][pHouse]!=-1) return SendClientMessage(playerid,COLOR_RED,"You own a property already. Sell it first.");
        for(new i=0;i<MAX_HOUSES;i++)
	{
	    if(IsValidHouse(i))
	    {
	        if(IsPlayerInRangeOfPoint(playerid,2,HouseInfo[i][hEnterx],HouseInfo[i][hEntery],HouseInfo[i][hEnterz]))
	   	{
	   	    if(PlayerInfo[playerid][pCash]<HouseInfo[i][hPrice]) return SendClientMessage(playerid,COLOR_RED,"You don't have enough money to buy this house.");
	   	    PlayerInfo[playerid][pCash]=PlayerInfo[playerid][pCash]-HouseInfo[i][hPrice];
                    SetPlayerCash(playerid,PlayerInfo[playerid][pCash]);
	   	    PlayerInfo[playerid][pHouse]=i;
	   	    HouseInfo[i][hOwned]=1;
	           SendClientMessage(playerid,COLOR_GREEN,"You successfully bought this property.");
	        }
	    }
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)