Little help
#1

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:
Quote:

for(new h = 0; h <= MAX_HOUSES; h++)

Can you tell me how to fix it?
Reply
#2

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

PHP код:
for(new hMAX_HOUSESh++) 
Weird... o.O
Reply
#4

Quote:
Originally Posted by CheezIt
Посмотреть сообщение
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.
I created this:
Quote:

if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[h][HouseX], HosueInfo[h][HouseY], HouseInfo[h][HouseZ]))
{
//here is the code
}
else SendClientMessage(playerid, Color, Message);

but it doesn't works .
(This message sent to me wherever I am)
Can you fix it?
Reply
#5

Quote:
Originally Posted by Kraeror
Посмотреть сообщение
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.
Reply
#6

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
PHP код:
for(new hMAX_HOUSESh++) 
Weird... o.O
It's not weird, it's code for loop. :X
Reply
#7

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
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.
Can you give me еxemplary code to fix?
Reply
#8

Please help me (give me code).
Here is my code:
Quote:

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
}

Reply
#9

Код:
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
Keep in mind that you dont check if house is valid (if it exists)
Reply
#10

More simple:

PHP код:
for(new 0<= MAX_HOUSESh++)
{
    if(
IsPlayerInRangeOfPoint(playerid1.0HouseInfo[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. 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)