Spawn at House (one line problem)
#2

Try this:
pawn Код:
if((HouseInfo[idz][hOwned] == 1) && (strcmp(HouseInfo[idz][hOwner], playername) == 0))
Always group your condition checks to be safe.
With the extra ( and ), you're telling the compiler to check if hOwned == 1, and take a separate check to see if strcmp returns 0.


The compiler may otherwise interpret it like:
pawn Код:
if(HouseInfo[idz][hOwned] == (1 && strcmp(HouseInfo[idz][hOwner], playername)) == 0)
This will of course check every house:
- if it's owned
- if the owner-name is identical

It does both checks even if the house isn't owned.
In such a case, it has no use to check if the owner is identical.

Comparing strings is quite slow.

You can avoid this by putting 2 separate if's below eachother:
pawn Код:
if(HouseInfo[idz][hOwned] == 1)
{
    if (strcmp(HouseInfo[idz][hOwner], playername) == 0)
    {
        SetPlayerPos(playerid, HouseInfo[idz][hEntranceX], HouseInfo[idz][hEntranceY], HouseInfo[idz][hEntranceZ]);
        SendClientMessage(playerid,COLOR_WHITE, string);
        format(string,sizeof(string), "Welcome back to your home, %s.", GetName(playerid));
    }
}
This way, the owner is only checked if the house is owned.
For available houses, this check isn't done and you put less stress on your server, increasing performance.
Reply


Messages In This Thread
Spawn at House (one line problem) - by Chrillzen - 20.02.2014, 18:39
Re: Spawn at House (one line problem) - by PowerPC603 - 20.02.2014, 18:45
Re: Spawn at House (one line problem) - by Konstantinos - 20.02.2014, 18:51
Re: Spawn at House (one line problem) - by Chrillzen - 20.02.2014, 19:02
Re: Spawn at House (one line problem) - by Konstantinos - 20.02.2014, 19:07
Re: Spawn at House (one line problem) - by Chrillzen - 20.02.2014, 19:15
Re: Spawn at House (one line problem) - by venomlivno8 - 20.02.2014, 19:30
Re: Spawn at House (one line problem) - by Chrillzen - 20.02.2014, 20:02

Forum Jump:


Users browsing this thread: 1 Guest(s)