SA-MP Forums Archive
Help! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help! (/showthread.php?tid=614371)



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(playeridnamesizeof(name)); // get the name once only
    
for (new 0sizeof(HouseInfo); i++)
    {
        
// if player not in range of both interior and exterior, skip it (go to the next iteration)
        
if (!IsPlayerInRangeOfPoint(playerid1.0HouseInfo[i][HouseExitX], HouseInfo[i][HouseExitY], HouseInfo[i][HouseExitZ]) && !IsPlayerInRangeOfPoint(playerid1.0HouseInfo[i][HouseEnterX], HouseInfo[i][HouseEnterY], HouseInfo[i][HouseEnterZ])) continue;
        if (!
HouseInfo[i][HouseOwnerName][0]) continue; // no owner, empty variable
        
if (strcmp(HouseInfo[i][HouseOwnerName], nametrue)) return SendClientMessage(playeridCOLOR_GREY"Трябва да сте собственик на къщата!");
        if (
HouseInfo[i][HouseLocked] == 0)
        {
            
HouseInfo[i][HouseLocked] = 1;
            
SendClientMessage(playeridCOLOR_LIGHTBLUE"SERVER: {FFFFFF}Къщата вече е заключена за посетители!");
        }
        else if (
HouseInfo[i][HouseLocked] == 1)
        {
            
HouseInfo[i][HouseLocked] = 0;
            
SendClientMessage(playeridCOLOR_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(playeridnamesizeof(name)); // get the name once only
    
for (new 0sizeof(HouseInfo); i++)
    {
        
// if player not in range of both interior and exterior, skip it (go to the next iteration)
        
if (!IsPlayerInRangeOfPoint(playerid1.0HouseInfo[i][HouseExitX], HouseInfo[i][HouseExitY], HouseInfo[i][HouseExitZ]) && !IsPlayerInRangeOfPoint(playerid1.0HouseInfo[i][HouseEnterX], HouseInfo[i][HouseEnterY], HouseInfo[i][HouseEnterZ])) continue;
        if (!
HouseInfo[i][HouseOwnerName][0]) continue; // no owner, empty variable
        
if (strcmp(HouseInfo[i][HouseOwnerName], nametrue)) return SendClientMessage(playeridCOLOR_GREY"Трябва да сте собственик на къщата!");
        if (
HouseInfo[i][HouseLocked] == 0)
        {
            
HouseInfo[i][HouseLocked] = 1;
            
SendClientMessage(playeridCOLOR_LIGHTBLUE"SERVER: {FFFFFF}Къщата вече е заключена за посетители!");
        }
        else if (
HouseInfo[i][HouseLocked] == 1)
        {
            
HouseInfo[i][HouseLocked] = 0;
            
SendClientMessage(playeridCOLOR_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(playerid1.0HouseInfo[i][HouseExitX], HouseInfo[i][HouseExitY], HouseInfo[i][HouseExitZ]) && !IsPlayerInRangeOfPoint(playerid1.0HouseInfo[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.