ZCMD: Unkown Command
#1

I keep getting unknown command if im not in range of a house I own. but if I am in range the command does what its suppose to
Here is the command:

Код:
CMD:lockhouse(playerid, params[])
{
	new hid = 0;
	hid = IsPlayerNearHouse(playerid);
	printf("house id: %i", hid);
	if(hid == 0) return SendClientMessage(playerid, COLOR_GREY, "You are not in range of a house you own.");
	if(hInfo[hid][hLocked] == 1)
	{
		hInfo[hid][hLocked] = 0;
		GameTextForPlayer(playerid, "~g~Unlocked", 1000, 6);
	}
	else if(hInfo[hid][hLocked] == 0)
	{
		hInfo[hid][hLocked] = 1;
		GameTextForPlayer(playerid, "~r~Locked", 1000, 6);
	}
	return 1;
}

stock IsPlayerNearHouse(playerid)
{
	for(new i = 0; i <= sizeof(hInfo); i++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 5.0, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
		{
			if(strcmp(GetNameEx(playerid), hInfo[i][hOwner], true) == 0)
			{
				printf("%i", i);
				return i;
			}
		}
	}
	return 0;
}
Reply
#2

Change the stock IsPlayerNearHouse to this

pawn Код:
stock IsPlayerNearHouse(playerid)
{
    for(new i = 0; i <= sizeof(hInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
        {
            if(strcmp(GetNameEx(playerid), hInfo[i][hOwner], true) == 0)
            {
                printf("%i", i);
                return i;
            }
        }
    }
        else
        {
        return SendClientMessage(playerid, COLOR_GREY, "You are not in range of a house you own.");
        }
    return 1;
}
Should work.
Reply
#3

That wouldnt work because there is no "if" before the else. If I did the else in the loop, it will say you are not in range over 1000 times until it gets your id
Reply
#4

why you are looping inside the size of the "hInfo" array while you should loop inside houses such MAX_HOUSES as an example.
And why you are returning the size of the array if he was really in range of it, instead of returning a "true" value?
pawn Код:
/* An example, let's put MAX_HOUSES 400 */
#define MAX_HOUSES 400

stock IsPlayerNearAnyHouse(playerid)
{
     for(new i = 0; i < MAX_HOUSES; i++)
     {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
        {
                return 1; // returning one so it can work with "hid == 0" or "hid == 1"
                        // He's near the house already, we don't need to check if his name same as owner's name
            if(strcmp(GetNameEx(playerid), hInfo[i][hOwner], true) == 0)
            {
                printf("%i", i);
               
            }
        }
    }
    return 0;
P.S , if you want this function to work as if the player's name same as owner's name or not, move return 1; under strcmp statement
Reply
#5

Im returning the size, because I am using the the size as the houseid to lock the house. The looping is fine, its looping as much as it needs to
Reply
#6

Should be < sizeof(hInfo); not <= sizeof(hInfo);
Reply
#7

That shouldnt matter either, that would make it loop while i is less than or equal to
Reply
#8

try this
pawn Код:
stock IsPlayerNearHouse(playerid)
{
    for(new i = 0; i <= sizeof(hInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
        {
            if(strcmp(GetNameEx(playerid), hInfo[i][hOwner], true) == 0)
            {
                printf("%i", i);
                return i;
            }
        }
        else if(!IsPlayerInRangeOfPoint(playerid, 5.0, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
        {
            SendClientMessage(playerid, COLOR_GREY, "You are not in range of a house you own.");
        }
    }
    return 0;
}
Reply
#9

Quote:

stock IsPlayerNearHouse(playerid)
{
for(new i = 0; i <= sizeof(hInfo); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
{
if(strcmp(GetNameEx(playerid), hInfo[i][hOwner], true) == 0)
{
printf("%i", i);
return i;
}
}
else if(!IsPlayerInRangeOfPoint(playerid, 5.0, hInfo[i][hPos][0], hInfo[i][hPos][1], hInfo[i][hPos][2]))
{
SendClientMessage(playerid, COLOR_GREY, "You are not in range of a house you own.");
}
}
return 0;
}

If I did this, it would say "You are not inrange" every time it loops that I am not in range. So if I was at houseid 297 when i used the command, it would say "You are not in range" 296 times until it said "locked"
Reply
#10

Quote:
Originally Posted by Blademaster680
Посмотреть сообщение
That shouldnt matter either, that would make it loop while i is less than or equal to
Must be less because sizeof(hInfo) is out of bounds

new hInfo[10]; = sizeof(hInfo) = 10 but array is from 0-9 so if loop go to 10 you got unknown command
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)