PHP Code:
#include <amxmodx>
new Array: Maps
new const file[] = "file.txt"
new g_NumElements
public plugin_init()
{
Maps = ArrayCreate( 64 )
register_plugin( "LOLOLOL", "ROFLROFLROFL", "LOLOLOL" )
new File = fopen( file, "rt" ), Temp[ 64 ]
if( !File )
goto End
while( !feof( File ) )
{
fgets( File, Temp, charsmax( Temp ) )
if( !Temp[ 0 ] || Temp[ 0 ] == ';' )
continue
ArrayPushString( Maps, Temp )
}
fclose( File )
End:
g_NumElements = ArraySize( Maps )
register_clcmd( "say /maps", "_c_SayMaps" )
}
public _c_SayMaps( id )
{
if( !g_NumElements )
{
client_print( id, print_chat, "No maps were added or the file was not present" )
return PLUGIN_HANDLED
}
new Menu = menu_create( "Maps", "_m_MapsHandler" ), Temp[ 64 ]
// please correct me if this does not work as I'm not sure
for( new Count; Count < g_NumElements; Count++ )
{
ArrayGetString( Maps, Count, Temp, charsmax( Temp ) )
menu_additem( Menu, Temp, Temp )
}
menu_display( id, Menu )
return PLUGIN_HANDLED
}
public _m_MapsHandler( id, menu, item )
{
new Trash, Data[ 64 ]
menu_item_getinfo( menu, item, Trash, Data, Trash, _, _, Trash )
server_cmd( "changelevel %s", Data )
menu_destroy( menu )
return PLUGIN_HANDLED
}
Could be probably done with caching the whole menu in plugin_init() instead of the array though.