SA-MP Forums Archive
house position error - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: house position error (/showthread.php?tid=665464)



house position error - bosmania - 05.04.2019

even if i am in range of a house it still says im not,i don;t know why

for(new i = 1; i <= 105; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez]))
{
HouseInfo[i][hType] = type;
mysql_format(SQL,str,sizeof(str), "UPDATE houses SET `Type`='%d' WHERE `ID`='%d'",type,HouseInfo[i][hID]);
mysql_tquery(SQL,str,"","");
}
else
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You aren't in range of any house");
return 1;
}
}


Re: house position error - JesterlJoker - 05.04.2019

Of course it will you are looping at all the the houses without breaking it...


Re: house position error - Markski - 06.04.2019

You need to break the loop with "break;" in order to stop looking for houses once you find it. Try this code.

PHP Code:
for(new 1<= 105i++) {
    if(
IsPlayerInRangeOfPoint(playerid5.0HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez]))    {
        
HouseInfo[i][hType] = type;
        
mysql_format(SQL,str,sizeof(str), "UPDATE houses SET `Type`='%d' WHERE `ID`='%d'",type,HouseInfo[i][hID]);
        
mysql_tquery(SQL,str,"","");
        break;
    } else {
        
SendClientMessage(playeridCOLOR_LIGHTRED"You aren't in range of any house");
        return 
1;
    }