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; }
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;
}
/* 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;
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;
}
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; } |
That shouldnt matter either, that would make it loop while i is less than or equal to
|