House System
#1

The problem is when I use /buyhouse, /housename, /sellhouse and /deletehouse it works but only on the last house created in game, I mean its being effected on the last house created.
CMD:buyhouse -
Код:
CMD:buyhouse(playerid, params[])
{
	new i; i = GetHouseID(playerid);
	new money = GetPlayerMoney(playerid), Query[250];
		
	if(pInfo[playerid][Login] == 0) return SendClientMessage(playerid, RED, "ERROR: You are not connected");

	if(money < HouseInfo[i][hPrice]) return SendClientMessage(playerid, RED, "ERROR: You don't have enough money to buy this house");

	if(HouseInfo[i][hOwned] == 1) return SendClientMessage(playerid, RED, "ERROR: This house is already owned");

	if(pInfo[playerid][OwnHouse] == 1) return SendClientMessage(playerid, RED, "ERROR: You own house already");

	if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]))
	{
		HouseInfo[i][hOwner] = GetName(playerid);
 		HouseInfo[i][hOwned] = 1;
 		pInfo[playerid][pHouseID] = HouseInfo[i][houseID];
  		pInfo[playerid][OwnHouse] = 1;
  		
   		DestroyDynamicPickup(HouseInfo[i][hPickup]);
    	HouseInfo[i][hPickup] = CreateDynamicPickup(1272, 1, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ], -1, -1, -1, House_Stream_Distance);
     	format(str, sizeof(str), "{FFFFFF}{00e600}%s\n{FFFFFF}Owner: %s\n{FFFFFF}Class: %s{FFFFFF}\nPrice: %d$\n{FFFFFF}Press {008080}N {FFFFFF}to enter", HouseInfo[i][HouseName], HouseInfo[i][hOwner],GetHouseType(), HouseInfo[i][hPrice]);
		UpdateDynamic3DTextLabelText(HouseInfo[i][hTextLabel], 0xFFFFFF, str);
		
		GivePlayerMoneyEx(playerid, -HouseInfo[i][hPrice]);

		format(Query, sizeof(Query), "UPDATE Houses SET `Owner`= '%s', `Owned`= 1 WHERE `ID`='%d'",GetName(playerid),HouseInfo[i][houseID]);
		mysql_query(mysql, Query);

		format(Query, sizeof(Query), "UPDATE Users SET `HouseID`= '%d' WHERE `Name`='%s'",HouseInfo[i][houseID],GetName(playerid));
		mysql_query(mysql, Query);

		format(Query, sizeof(Query), "UPDATE Houses SET `HouseName`= House Name, WHERE `ID` ='%d'",HouseInfo[i][houseID]);
		mysql_query(mysql, Query);

		SendClientMessage(playerid, YELLOW, "[SERVER]: You have successfully bought this house, use /housecmds for more information");
	}
	return 1;
}
Код:
#define INVALID_HOUSE_ID (-255)
GetHouseID(playerid)
{
    for(new i=0; i<MAX_HOUSES; i++)
    {
        if(PlayerToPoint(1.5, playerid, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]))
        {
            return i;
        }
    }
    return INVALID_HOUSE_ID;
}
Код:
PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
  if(IsPlayerConnected(playerid))
  {
    new Float:oldposx, Float:oldposy, Float:oldposz;
    new Float:tempposx, Float:tempposy, Float:tempposz;
    GetPlayerPos(playerid, oldposx, oldposy, oldposz);
    tempposx = (oldposx -x);
    tempposy = (oldposy -y);
    tempposz = (oldposz -z);
    if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
    {
      return 1;
    }
  }
  return 0;
}
I tried fixing it in many ways but nothing works, please if you have any solution ill be thankful
Reply
#2

You don't need a function to get the house ID.

Код:
        for(new i = 0; i < sizeof(HouseInfo); i++)
	{
                 if(IsPlayerInRangeOfPoint(playerid,2.0,HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ]))
                 {
                      //check to see if house is for sale or not etc...
                 }
        }
i is the house ID.

Put the for loop at the top of your code more or less (you can put a check to see if the players connected and what not before it if you wish)

Just put all of this:

Код:
        if(money < HouseInfo[i][hPrice]) return SendClientMessage(playerid, RED, "ERROR: You don't have enough money to buy this house");

	if(HouseInfo[i][hOwned] == 1) return SendClientMessage(playerid, RED, "ERROR: This house is already owned");

	if(pInfo[playerid][OwnHouse] == 1) return SendClientMessage(playerid, RED, "ERROR: You own house already");
inside the code I gave you above.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)