Help! -
martintasin - 07.08.2016
I start a new house system, all it's okay but when i try to lock my own house, doesn't work..
Code:
if(strcmp(HouseInfo[i][HouseOwnerName], name, true) == 1)
{
Re: Help! -
Mencent - 07.08.2016
Hello.
We need more code. Show us your command which you use to lock your house.
Re: Help! -
martintasin - 07.08.2016
if(strcmp(cmdtext, "/lockhouse", true) == 0)
{
for(new i = 0; i <sizeof(HouseInfo); i++)
{
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]))
{
new name[255];
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(HouseInfo[i][HouseOwnerName], name, true) == 1)
{
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}Къщата вече е отключена за посетители!");
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Трябва да сте собственик на къщата!");
}
}
}
return 1;
}
Re: Help! -
Lucky13 - 07.08.2016
Код:
if(strcmp(cmdtext, "/lockhouse", true) == 0)
{
for(new i = 0; i <sizeof(HouseInfo); i++)
{
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]))
{
new name[MAX_PLAYER_ANME];
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(HouseInfo[i][HouseOwnerName], name, true) == 0)
{
if(HouseInfo[i][HouseLocked] == 0)
{
HouseInfo[i][HouseLocked] = 1;
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: {FFFFFF}Къщата вече е заключена за посетители!");
}
else
{
HouseInfo[i][HouseLocked] = 0;
SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: {FFFFFF}Къщата вече е отключена за посетители!");
}
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Трябва да сте собственик на къщата!");
return 1;
}
}
}
return 1;
}
Re: Help! -
martintasin - 07.08.2016
Not working, i can unlock all houses without to be my.
Re: Help! -
Lucky13 - 07.08.2016
Are you sure about this? Try to paste the code again and try.
Re: Help! -
martintasin - 07.08.2016
Yes, i'm sure.....
Re: Help! -
Konstantinos - 07.08.2016
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
}
Re: Help! -
martintasin - 07.08.2016
Quote:
Originally Posted by Konstantinos
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
}
|
Thanks!
Re: Help! -
Mencent - 07.08.2016
@Konstantinus:
PHP код:
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;
Is this right?
I mean , players can only be at the output OR at the entrance. Not in both places at the same time.
Sorry, when I'm false. I only want to ask because I think it's wrong.