SA-MP Forums Archive
Best way to do this? - 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: Best way to do this? (/showthread.php?tid=395984)



Best way to do this? - 2KY - 28.11.2012

Right now, I've got in a 1 1/2 second timer that repeats the following code;

pawn Код:
for( new e; e < MAX_ENTRANCES; e ++ )
{
    if( IsPlayerInRangeOfPoint( playerid, 1.5, EntranceInfo [ e ] [ eX ], EntranceInfo [ e ] [ eY ], EntranceInfo [ e ] [ eZ ] ) && tdShown [ playerid ] == false )
    {
        tdShown [ playerid ] = true;
        TextDrawShowForPlayer( playerid, EnterExitHelp );
    }
    else if( tdShown [ playerid ] == true && !IsPlayerInRangeOfPoint( playerid, 1.5, EntranceInfo [ e ] [ eX ], EntranceInfo [ e ] [ eY ], EntranceInfo [ e ] [ eZ ] ) )
    {
        tdShown [ playerid ] = false;
        TextDrawHideForPlayer( playerid, EnterExitHelp );
    }
}
Is there anything better I can do in terms of efficiency?


Re: Best way to do this? - Vince - 28.11.2012

Add a break when an entrance is found.


Re: Best way to do this? - 2KY - 28.11.2012

So just:

pawn Код:
for( new e; e < MAX_ENTRANCES; e ++ )
{
    if( IsPlayerInRangeOfPoint( playerid, 1.5, EntranceInfo [ e ] [ eX ], EntranceInfo [ e ] [ eY ], EntranceInfo [ e ] [ eZ ] ) && tdShown [ playerid ] == false )
    {
        tdShown [ playerid ] = true;
        TextDrawShowForPlayer( playerid, EnterExitHelp );
        break;
    }
    else if( tdShown [ playerid ] == true && !IsPlayerInRangeOfPoint( playerid, 1.5, EntranceInfo [ e ] [ eX ], EntranceInfo [ e ] [ eY ], EntranceInfo [ e ] [ eZ ] ) )
    {
        tdShown [ playerid ] = false;
        TextDrawHideForPlayer( playerid, EnterExitHelp );
    }
}



Re: Best way to do this? - Bakr - 28.11.2012

You don't need to re-check the conditions you tested for. You could simply write "else", which would stop an extra function call and variable look-up.


Re: Best way to do this? - 2KY - 28.11.2012

Quote:
Originally Posted by Bakr
Посмотреть сообщение
You don't need to re-check the conditions you tested for. You could simply write "else", which would stop an extra function call and variable look-up.
Why would I hide the textdraw if it was never shown in the first place? It would continuously try to hide a non-existant textdraw.