PDA

View Full Version : ZCMD: Unkown Command


Blademaster680
08/01/2015, 08:39 PM
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;
}

DavidSparks
08/01/2015, 08:45 PM
Change the stock IsPlayerNearHouse to this

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.

Blademaster680
08/01/2015, 08:48 PM
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

Sawalha
08/01/2015, 08:48 PM
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?

/* 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

Blademaster680
08/01/2015, 08:51 PM
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

Jefff
08/01/2015, 08:53 PM
Should be < sizeof(hInfo); not <= sizeof(hInfo);

Blademaster680
08/01/2015, 08:54 PM
That shouldnt matter either, that would make it loop while i is less than or equal to

ahmedkoki
08/01/2015, 08:57 PM
try this

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;
}

Blademaster680
08/01/2015, 09:00 PM
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"

Jefff
08/01/2015, 09:08 PM
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

Blademaster680
08/01/2015, 09:25 PM
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
I honestly did not think of that. Thank you soooooooo much. Sorry if I seemed cocky, was a bit pissed off