Best way to do this?
#1

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?
Reply
#2

Add a break when an entrance is found.
Reply
#3

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 );
    }
}
Reply
#4

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.
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)