You should try to avoid using a native in the for loop in instances when it can be called multiple times. get_maxplayers() returns a constant value that is not going to change while the loop iterates so it's safe to use a variable.
Calling native in for-loop:
PHP Code:
public Test()
{
//Same as for( new i = 1 ; i <= get_maxplayers() ; i++ )
for( new i = 1; i <= gp() ; i++ )
{
server_print( "Iteration %d" , i );
}
}
public gp()
{
server_print( "get_maxplayers() called" );
return get_maxplayers();
}
Result:
Code:
get_maxplayers() called
Iteration 1
get_maxplayers() called
Iteration 2
get_maxplayers() called
Iteration 3
get_maxplayers() called
Iteration 4
get_maxplayers() called
Iteration 5
get_maxplayers() called
Iteration 6
get_maxplayers() called
Iteration 7
get_maxplayers() called
Iteration 8
get_maxplayers() called
Storing value in a variable
PHP Code:
public Test()
{
new iMaxPlayers = gp();
for( new i = 1; i <= iMaxPlayers ; i++ )
{
server_print( "Iteration %d" , i );
}
}
public gp()
{
server_print( "get_maxplayers() called" );
return get_maxplayers();
}
Result:
Code:
get_maxplayers() called
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Iteration 7
Iteration 8
__________________