How can
#1

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).
Reply
#2

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");
Reply
#3

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");
}
Reply
#4

Код:
for(new id = 0; id < MAX_HOUSES; id++)
Reply
#5

Doesn't works.
Reply
#6

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
Reply
#7

Be careful, message must be outside loop, or it will send multiple messages!
Reply
#8

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.
Reply
#9

PHP код:
new count=0;
for(new 
id 0id MAX_HOUSESid++)
{
     if(
IsPlayerInRangeOfPointplayerid3.0b_House[id][EnterX], b_House[id][EnterY], b_House[id][EnterZ])) count++;
}
if(!
count) return SendClientMessage(playerid, -1,"You aren't near house"); 
Reply
#10

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)