20.02.2014, 18:45
Try this:
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:
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:
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.
pawn Код:
if((HouseInfo[idz][hOwned] == 1) && (strcmp(HouseInfo[idz][hOwner], playername) == 0))
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)
- 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));
}
}
For available houses, this check isn't done and you put less stress on your server, increasing performance.