Knock command help
#1

Hi!
Trying to make /knock command to simulate a knock on house door. problem is that it doesn't work and shows only "You are not near a house".. even if im standing on it.

Код:
CMD:knock(playerid, params[])
{
	new string[50], NearHouse;
	for(new idx; idx < MAX_HOUSES; idx++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 4.0, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]) && NearHouse==0)
		{
		    NearHouse=1;
 			format(string, sizeof(string), "* %s knocks on the house door.", RPN(playerid));
			SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
	 		for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
			{
				if(HouseInfo[idx][hLevel] == 1 && IsPlayerInRangeOfPoint(i, 8, 243.9951,304.9418,999.1484))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 2 && IsPlayerInRangeOfPoint(i, 8, 2259.6702,-1135.8542,1050.6328))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 3 && IsPlayerInRangeOfPoint(i, 8, 2308.8254,-1212.8070,1049.0234))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 4 && IsPlayerInRangeOfPoint(i, 8, 260.7436,1237.5563,1084.2578))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 5 && IsPlayerInRangeOfPoint(i, 8, -42.5742,1405.6521,1084.4297))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 6 && IsPlayerInRangeOfPoint(i, 8, 2203.3323,-1250.0913,1529.1060))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 7 && IsPlayerInRangeOfPoint(i, 8, 2365.2183,-1135.4014,1050.8750))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 8 && IsPlayerInRangeOfPoint(i, 8, 2270.1270,-1210.4855,1047.5625))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 9 && IsPlayerInRangeOfPoint(i, 8, 2324.4424,-1149.2057,1050.7101))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 10 && IsPlayerInRangeOfPoint(i, 8, 83.0863,1322.3020,1083.8662))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 11 && IsPlayerInRangeOfPoint(i, 8, 1260.6544,-785.6682,1091.9063))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 12 && IsPlayerInRangeOfPoint(i, 8, 852.0531,1997.6768,1011.0809))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 13 && IsPlayerInRangeOfPoint(i, 8, -1821.3711,802.0818,128.2039))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
			}
		}
		else
		{
		    NearHouse=0;
			SendClientMessage(playerid, COLOR_WHITE, "You are not near a house.");
			return 1;
		}
	}
	return 1;
}
Any ideas?
Reply
#2

try this


Код:
CMD:knock(playerid, params[])
{
	new string[50], NearHouse;
	for(new idx; idx < MAX_HOUSES; idx++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 4.0, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]))
		{
		    NearHouse=1;
 			format(string, sizeof(string), "* %s knocks on the house door.", RPN(playerid));
			SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
	 		for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
			{
				if(HouseInfo[idx][hLevel] == 1 && IsPlayerInRangeOfPoint(i, 8, 243.9951,304.9418,999.1484))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 2 && IsPlayerInRangeOfPoint(i, 8, 2259.6702,-1135.8542,1050.6328))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 3 && IsPlayerInRangeOfPoint(i, 8, 2308.8254,-1212.8070,1049.0234))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 4 && IsPlayerInRangeOfPoint(i, 8, 260.7436,1237.5563,1084.2578))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 5 && IsPlayerInRangeOfPoint(i, 8, -42.5742,1405.6521,1084.4297))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 6 && IsPlayerInRangeOfPoint(i, 8, 2203.3323,-1250.0913,1529.1060))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 7 && IsPlayerInRangeOfPoint(i, 8, 2365.2183,-1135.4014,1050.8750))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 8 && IsPlayerInRangeOfPoint(i, 8, 2270.1270,-1210.4855,1047.5625))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 9 && IsPlayerInRangeOfPoint(i, 8, 2324.4424,-1149.2057,1050.7101))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 10 && IsPlayerInRangeOfPoint(i, 8, 83.0863,1322.3020,1083.8662))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 11 && IsPlayerInRangeOfPoint(i, 8, 1260.6544,-785.6682,1091.9063))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 12 && IsPlayerInRangeOfPoint(i, 8, 852.0531,1997.6768,1011.0809))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 13 && IsPlayerInRangeOfPoint(i, 8, -1821.3711,802.0818,128.2039))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
			}
		}
		else
		{
		    NearHouse=0;
			SendClientMessage(playerid, COLOR_WHITE, "You are not near a house.");
			return 1;
		}
	}
	return 1;
}
Reply
#3

If i do this what would be the point of NearHouse? It will flood the chat for the player "You are not near a house" when he isn't near a house (cause it goes thorugh all houses...)
Reply
#4

Remove this part
PHP код:
                else //If the player is not in range of the house that is in loop.
        
{
            
NearHouse=0;
            
SendClientMessage(playeridCOLOR_WHITE"You are not near a house.");
            return 
1;
        } 
The loop is checking for every house and it is obvious that player will be near to only one house.


And add after the loop:
PHP код:
        if(NearHouse == 0)
        {
            
SendClientMessage(playeridCOLOR_WHITE"You are not near a house.");
         } 
Reply
#5

Put it outside the loop and return true at the end.

PHP код:
CMD:knock(playeridparams[])
{
     new 
bool:nearHouse false;
     for(new 
idxidx MAX_HOUSESidx++)
     {
         if(
IsPlayerInRangeOfPoint(playerid, ...)
         {
             
nearHouse true;
             for(new 
0GetPlayerPoolSize(); <= ji++)
             {
                  
//code;
             
}
         }
         return 
1;
      }
      if(
nearHouse == 1)
      {
           
SendClientMessage(playeridCOLOR_WHITE"You are not near a house.");
       } 
Reply
#6

server prints noting. not "* %s knocks on the house door." and not "You are not near a house."
what i used:
Код:
cmd:knock(playerid, params[])
{
	new string[50], NearHouse;
	for(new idx; idx < MAX_HOUSES; idx++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 4.0, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]))
		{
		    NearHouse=1;
			format(string, sizeof(string), "* %s knocks on the house door.", RPN(playerid));
			SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
	 		for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
			{
				if(HouseInfo[idx][hLevel] == 1 && IsPlayerInRangeOfPoint(i, 8, 243.9951,304.9418,999.1484))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 2 && IsPlayerInRangeOfPoint(i, 8, 2259.6702,-1135.8542,1050.6328))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 3 && IsPlayerInRangeOfPoint(i, 8, 2308.8254,-1212.8070,1049.0234))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 4 && IsPlayerInRangeOfPoint(i, 8, 260.7436,1237.5563,1084.2578))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 5 && IsPlayerInRangeOfPoint(i, 8, -42.5742,1405.6521,1084.4297))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 6 && IsPlayerInRangeOfPoint(i, 8, 2203.3323,-1250.0913,1529.1060))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 7 && IsPlayerInRangeOfPoint(i, 8, 2365.2183,-1135.4014,1050.8750))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 8 && IsPlayerInRangeOfPoint(i, 8, 2270.1270,-1210.4855,1047.5625))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 9 && IsPlayerInRangeOfPoint(i, 8, 2324.4424,-1149.2057,1050.7101))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 10 && IsPlayerInRangeOfPoint(i, 8, 83.0863,1322.3020,1083.8662))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 11 && IsPlayerInRangeOfPoint(i, 8, 1260.6544,-785.6682,1091.9063))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 12 && IsPlayerInRangeOfPoint(i, 8, 852.0531,1997.6768,1011.0809))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
				if(HouseInfo[idx][hLevel] == 13 && IsPlayerInRangeOfPoint(i, 8, -1821.3711,802.0818,128.2039))
				{
	   				format(string, sizeof(string), "* someone knocks on the door.");
					SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				}
			}
		}
		return 1;
	}
	if(NearHouse == 0) SendClientMessage(playerid, COLOR_WHITE, "You are not near a house.");
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)