which one?
#1

Which one is better at performance? (Sorry for bad indentation, I wrote these codes in this box )

pawn Код:
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

pawn Код:
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);
}
Reply
#2

I think they are both basicly the same.
Reply
#3

And what about my question?
Reply
#4

You could do:
pawn Код:
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.
Reply
#5

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
pawn Код:
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;
}
Reply
#6

And what about my question? ..
Reply
#7

the top one is best he is saying dude
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)