IsPlayerInRangeOfPoint
#1

Hi.

I have a problem with IsPlayerInRangeOfPoint... I am trying to
make a buy house command, but when I use the buyhouse command,
it keeps telling me that I am not inrange of the house, even though
I am able to enter it... So I know I am in range, but cant buy it...
Even if I stand inside the house pickup...

Please help.

Code:
Код:
CMD:buyhouse(playerid, params[])
{
	if(pInfo[playerid][pHouses] < 2)
	{
		for(new i = 0; i < sizeof(hInfo); i++)
		{
			if(IsPlayerInRangeOfPoint(playerid, 3, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
			{
				if(HouseBought[i] == 0)
				{
					if(pInfo[playerid][pCash] >= hInfo[i][hPrice])
					{
						new str[55], Query[500], fields, rows;
						HouseBought[i] = 1;
						pInfo[playerid][pCash] -= hInfo[i][hPrice];
						strcat(Query,"INSERT INTO `phouses`(`ID`, `Owner`, `Level`, `Price`,`PosX`,`PosY`,`PosZ`, `FacingAngle`, `IPosX`, `IPosY`, `IPosZ`, `Interior`, `VirtualWorld`)");
						strcat(Query," VALUES (NULL, '%s', '%d', '%d', '%f', '%f', '%f', '%f', '%f', '%f', '%f', 10, '%i')");
						mysql_format(dbHandle, Query, sizeof(Query), Query, GetName(playerid), hInfo[i][hLevel], hInfo[i][hPrice], hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2], hInfo[i][hFacAngle], hInfo[i][hIPos][0], hInfo[i][hIPos][1], hInfo[i][hIPos][2], hInfo[i][hVW]);
						mysql_query(dbHandle, Query, false);
						
						mysql_format(dbHandle,Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `ID` = '%d'", i);
						mysql_query(dbHandle,Query);
						cache_get_data(rows, fields);
						Load_PlayerHouse(i);
						
						strcat(Query, "DELETE FROM `lla`.`houses` WHERE `houses`.`ID` = %d;");
						mysql_format(dbHandle, Query, sizeof(Query), Query, i);
						mysql_query(dbHandle, Query, false);
						
						Destroy_DynamicHouse(i);
						
						format(str, sizeof(str), "You just bought this house for $%i", hInfo[i][hPrice]);
						SendClientMessage(playerid, COLOR_ORANGE, str);
					}
					else return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money");
				}
				else return SendClientMessage(playerid, COLOR_GREY, "That house is already owned");
			}
			else return SendClientMessage(playerid, COLOR_GREY, "You are not near a house");
		}
	}
	else return SendClientMessage(playerid, COLOR_GREY, "You already have 2 houses");
	return 1;
}
Reply
#2

You can't possibly know if a player is in range of any house before having gone through all of them. I will say it once more: never return inside a loop unless you explicitly want to break it.

When the loop is entered for the first time, the code checks if the player is at house 0. If the player isn't at house 0 then the code skips the first block and goes straight to the "You are not near a house" message. Because of the return there, the function ends there and other houses aren't even checked.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)