strcmp returns 0 when both strings are equals as Lucky13's code. However, it also returns 0 when either of them is empty.
PHP код:
if (strcmp(cmdtext, "/lockhouse", true) == 0)
{
new name[MAX_PLAYER_NAME]; // 255 is way too big, 24 is more than enough
GetPlayerName(playerid, name, sizeof(name)); // get the name once only
for (new i = 0; i < sizeof(HouseInfo); i++)
{
// if player not in range of both interior and exterior, skip it (go to the next iteration)
if (!IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[i][HouseExitX], HouseInfo[i][HouseExitY], HouseInfo[i][HouseExitZ]) && !IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[i][HouseEnterX], HouseInfo[i][HouseEnterY], HouseInfo[i][HouseEnterZ])) continue;
if (!HouseInfo[i][HouseOwnerName][0]) continue; // no owner, empty variable
if (strcmp(HouseInfo[i][HouseOwnerName], name, true)) return SendClientMessage(playerid, COLOR_GREY, "Трябва да сте собственик на къщата!");
if (HouseInfo[i][HouseLocked] == 0)
{
HouseInfo[i][HouseLocked] = 1;
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: {FFFFFF}Къщата вече е заключена за посетители!");
}
else if (HouseInfo[i][HouseLocked] == 1)
{
HouseInfo[i][HouseLocked] = 0;
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: {FFFFFF}Къщата вече е отключена за посетители!");
}
break; // stop the loop, it is not needed anymore
}
return 1; // command found, don't search in other scripts
}