Quote:
Originally Posted by xbatista
Nice example, btw can you show example without Arrays?
|
It's better with Arrays and Tries, but sure.
Code:
GetRandomMap( const szMapFile[ ], szReturn[ ], const iLen )
{
new iFile = fopen( szMapFile, "rt" );
if( !iFile )
{
return 0;
}
const MAX_MAPS = 100;
static szMaps[ MAX_MAPS ][ 64 ];
new iTotal = 0;
static szData[ 128 ], szMap[ 64 ], i, bool:bExists;
while( !feof( iFile ) && iTotal < MAX_MAPS )
{
fgets( iFile, szData, 127 );
parse( szData, szMap, 63 );
strtolower( szMap );
if( is_map_valid( szMap ) )
{
bExists = false;
for( i = 0; i < iTotal; i++ )
{
if( equal( szMaps[ i ], szMap ) )
{
bExists = true;
break;
}
}
if( !bExists )
{
copy( szMaps[ iTotal++ ], 63, szMap );
}
}
}
if( !iTotal )
{
return 0;
}
copy( szReturn, iLen, szMaps[ random( iTotal ) ] );
return 1;
}
__________________