PHP Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "amx_map random"
#define VERSION "1.0"
#define AUTHOR "BOYSplayCS"
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_concmd("amx_map_random", "eventChangeMap", ADMIN_SLAY, "- Randomly change map");
}
public eventChangeMap(id, level, cid)
{
if (cmd_access(id, level, cid, 2))
{
new szMap[ 64 ];
if( GetRandomMap( "mapcycle.txt", szMap, 63 ) )
server_cmd( "changelevel %s", szMap );
else
console_print( id, "There were no maps to change to." );
}
else
client_print(id, print_chat, "[AMXX] Denied Command Access: 'amx_map_random'!");
return PLUGIN_HANDLED;
}
GetRandomMap( const szMapFile[ ], szReturn[ ], const iLen )
{
new iFile = fopen( szMapFile, "rt" );
if( !iFile )
{
return 0;
}
new Array:aMaps = ArrayCreate( 64 );
new Trie:tArrayPos = TrieCreate( );
new iTotal = 0;
static szData[ 128 ], szMap[ 64 ];
while( !feof( iFile ) )
{
fgets( iFile, szData, 127 );
parse( szData, szMap, 63 );
strtolower( szMap );
if( is_map_valid( szMap ) && !TrieKeyExists( tArrayPos, szMap ) )
{
ArrayPushString( aMaps, szMap );
TrieSetCell( tArrayPos, szMap, iTotal );
iTotal++;
}
}
TrieDestroy( tArrayPos );
if( !iTotal )
{
ArrayDestroy( aMaps );
return 0;
}
ArrayGetString( aMaps, random( iTotal ), szReturn, iLen );
ArrayDestroy( aMaps );
return 1;
}
__________________