07.06.2012, 01:43
Your biggest problem is that you are comparing hLockCode to the entered text for EVERY HOUSE. Before even performing any checks, you should have a function that obtains the closest house. Here is an example:
The way the script is set up now, the message after "else" is sent every time that the hLockCode does not match the input text. If you have 500 houses, and only house id 400 has that Lock Code, you will get 399 messages before the loop is broken.
Also, I would perform the hHouseLocked check before the hLockCode check. It is easier for the server to compare two integers (0 or 1) than compare two strings.
pawn Код:
stock GetClosestHouseID(playerid)
{
new ClosestHouse;
new Float:ClosestDistance = 10000000;
for (new i = 1; i<MAX_HOUSES; i++)
{
new Float:Distance = GetPlayerDistanceFromPoint(playerid,HouseInfo[i][XPos],HouseInfo[i][YPos],HouseInfo[i][ZPos]);
if(Distance<ClosestDistance)
{
ClosestDistance = Distance;
ClosestHouse = i;
}
}
return ClosestHouse;
}
Also, I would perform the hHouseLocked check before the hLockCode check. It is easier for the server to compare two integers (0 or 1) than compare two strings.

