How can -
Kraeror - 29.05.2017
How can I make the function the player is not close to the houses, then send just one message. I tried to add this on if(!IsPlayerInRangeOfPoint) message, but it send me the messages 50 times, because MAX_HOUSES are 50 and i loop it. How can I create this. Can you give me an example code (without any clarifications).
Re: How can -
Bolex_ - 29.05.2017
As example
Код:
if(!IsPlayerInRangeOfPoint( playerid, 3.0, b_House[id][EnterX], b_House[id][EnterY], b_House[id][EnterZ])) return SendClientMessage(playerid, -1,"You aren't near house");
Re: How can -
Kraeror - 29.05.2017
Quote:
Originally Posted by Bolex_
As example
Код:
if(!IsPlayerInRangeOfPoint( playerid, 3.0, b_House[id][EnterX], b_House[id][EnterY], b_House[id][EnterZ])) return SendClientMessage(playerid, -1,"You aren't near house");
|
Bro I already did this, but with loop like this:
for(new id = 0; id <= MAX_HOUSES; id++)
{
if(!IsPlayerInRangeOfPoint( playerid, 3.0, b_House[id][EnterX], b_House[id][EnterY], b_House[id][EnterZ])) return SendClientMessage(playerid, -1,"You aren't near house");
}
Re: How can -
Bolex_ - 29.05.2017
Код:
for(new id = 0; id < MAX_HOUSES; id++)
Re: How can -
Kraeror - 29.05.2017
Doesn't works.
Re: How can -
NaS - 29.05.2017
What Bolex_ said is correct and important (do not use <= MAX_HOUSES otherwise you will exceed the Array Bounds!).
Still that is not the solution of the problem.
You must create a temporary variable (before the loop) to save if a Player is near any house:
Код:
new bool:AnyHouse = false;
for(new id = 0; id < MAX_HOUSES; id++) if(IsPlayerInRangeOfPoint( playerid, 3.0, b_House[id][EnterX], b_House[id][EnterY], b_House[id][EnterZ]))
{
AnyHouse = true;
break; // Breaks the loop since we now know that the player is near a house
}
if(!AnyHouse) return SendClientMessage(playerid, -1,"You aren't near house"); // Send the message here, no house was found
Re: How can -
Bolex_ - 29.05.2017
Be careful, message must be outside loop, or it will send multiple messages!
Re: How can -
saffierr - 30.05.2017
The Message should be outside the loop.
Create a temporarily variable, example:
PHP код:
new bool:sendmessage=false;
Then inside the loop do:
PHP код:
sendmessage = true;
break;
And then outside the loop
PHP код:
if(!sendmessage) return SendClientMessage();
Tell me if it works.
EDIT: Just noticed Nas has the same solution lol.
Re: How can -
StrikerZ - 30.05.2017
PHP код:
new count=0;
for(new id = 0; id < MAX_HOUSES; id++)
{
if(IsPlayerInRangeOfPoint( playerid, 3.0, b_House[id][EnterX], b_House[id][EnterY], b_House[id][EnterZ])) count++;
}
if(!count) return SendClientMessage(playerid, -1,"You aren't near house");
Re: How can -
Kraeror - 30.05.2017
Thanks guys +1 REP for all!
I used solution to NaS, but all of the solutions were the best!
Thanks for all!
Best wishes, Kraeror!