for(new h = 0; h <= MAX_HOUSES; h++) |
for(new h; h < MAX_HOUSES; h++)
Create a function that returns the closest house within a certain radius, or at least the first house within the radius (break; the loop). Check if the return value is false in a if-then, then show the message.
If you don't want to create a function and use that loop, then use the loop only for getting a house in range (break; the loop when a house is found). Send the message or proceed with locking the house OUTSIDE the loop. |
if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[h][HouseX], HosueInfo[h][HouseY], HouseInfo[h][HouseZ])) { //here is the code } else SendClientMessage(playerid, Color, Message); |
Hello guys. I made a house system. I need help please. I created /lock command and it works perfect, but I want, when the player is not in range of point, it return a message. I made this, but the server send me the message 40- 50 times, I think it's because of this code:
Can you tell me how to fix it? |
Well that line is a loop, and to assume that loop sends you 40-50 messages is the right way.
Inside that loop you need to check if player is in range of given house (point). If he is not continue, if he is, break. |
for(new h = 0; h <= MAX_HOUSES; h++) { if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[h][HouseX], HouseInfo[h][HouseY], HouseInfo[h][HouseZ])) { //Here is the lock } else SendClientMessage(mymessage); //This message doesn't work as needed } |
new houseid = -1; for(new h = 0; h <= MAX_HOUSES; h++) { if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[h][HouseX], HouseInfo[h][HouseY], HouseInfo[h][HouseZ])) { houseid = h;//Lets save house id to a variable. //Here is the lock break;//And since we found house, we leave loop (no need to waste resources) } } if(houseid == -1) return SendClientMessage(mymessage); //This message doesn't work as needed
for(new h = 0; h <= MAX_HOUSES; h++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[h][HouseX], HouseInfo[h][HouseY], HouseInfo[h][HouseZ]))
{
// If exist one house in range of player.
return 1;
}
}
// Message if don't exist one house in range.