PDA

View Full Version : which one?


Gh0sT_
02/09/2011, 12:15 PM
Which one is better at performance? (Sorry for bad indentation, I wrote these codes in this box :D)

new Float:Array[][] =
{
{X, Y, Z},
{X, Y, Z},
{X, Y, Z}
};

stock IsPlayerNearSomething(playerid)
{
for(new i; i != sizeof(Array); ++i)
{
return IsPlayerInRangeOfPoint(playerid, radius, Array[i][0], Array[i][1], Array[i][2]);
}
}


OR just

stock IsPlayerNearSomething(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z) || IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z) || IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z)) return true;
return false;
}

And, one question: Can I create stocks like this?

stock IsPlayerNearSomething(playerid)
{
return IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z) || IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z) || IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z);
}

FireCat
02/09/2011, 12:24 PM
I think they are both basicly the same.

Gh0sT_
02/09/2011, 01:57 PM
And what about my question?

[MWR]Blood
02/09/2011, 02:04 PM
You could do:

stock IsPlayerNearSomething(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z) return 1;
if(IsPlayerInRangeOfPoint(playerid, radius, x, y, z) return 1;
return 0;
}

If you do it all in a row, you could encounter some errors as you might exceed the maximum PAWN length.

Pinguinn
02/09/2011, 02:05 PM
The arrays are more easier to use

What I am showing below does the same thing as [MWR]Blood posted
It returns false if he is not near it, and returns true if he is

new Float:Array[][] =
{
{X, Y, Z},
{X, Y, Z},
{X, Y, Z}
};

stock IsPlayerNearSomething(playerid)
{
for(new i; i != sizeof(Array); ++i)
{
if(IsPlayerInRangeOfPoint(playerid, radius, Array[i][0], Array[i][1], Array[i][2]) return true;
}
return false;
}

Gh0sT_
02/09/2011, 06:17 PM
And what about my question? ..

Zonoya
02/09/2011, 06:18 PM
the top one is best he is saying dude