Raised This Month: $ Target: $400
 0% 

Filling menu with options


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kensai
Veteran Member
Join Date: Aug 2005
Location: San Diego, California
Old 01-02-2006 , 22:22   Filling menu with options
Reply With Quote #1

Hi,

Can someone either show me a plugin or show me an example fo how to "auto-fill" a menu from a file.

What I want to do is when someone types w/e cmd it shows them a menu filled with names of all the maps iin the server maps.ini

I would love to make this myself, but I have no clue how to do the "filling" part.

This is how far I've gotten, pretty sure there's a few errors already.
Code:
#include <amxmodx> #include <amxmisc> #define MAX_MAPS 100 new configsdir[200] new configfile[200] new map[MAX_MAPS][64] new mapdir[MAX_MAPS][64] public plugin_init() {     register_plugin("Map List","1.0","Kensai")     register_concmd("maplist","Maplist",ADMIN_KICK,"Displays a menu, listing all maps on the server.")         register_menucmd(register_menuid("menu_Maplist"),1023,"DoMaplist"); } public Maplist(id) {           new menu[192]       format(menu, 191, "Maps List^n^n1. ^n^n0. Exit")         new keys = MENU_KEY_1|MENU_KEY_0     show_menu(id, keys, menu, 15, "menu_Maplist")             return PLUGIN_HANDLED }

Thanks.
Kensai is offline
Send a message via AIM to Kensai Send a message via MSN to Kensai
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 01-03-2006 , 15:58  
Reply With Quote #2

I would read the file and format the menu options in a loop
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 01-03-2006 , 20:02  
Reply With Quote #3

Not sure if this will work, most likely not, but you get the idea

Code:
#include <amxmodx> #include <amxmisc> #define MAX_MAPS 100 new MenuPage[33]; new configsdir[200] new configfile[200] new map[MAX_MAPS][64] new totalmaps; //new mapdir[MAX_MAPS][64] public plugin_init() {     register_plugin("Map List","1.0","Kensai")     register_concmd("maplist","Maplist",ADMIN_KICK,"Displays a menu, listing all maps on the server.")         register_menucmd(register_menuid("menu_Maplist"),1023,"DoMaplist");         Load_File();     Read_File(); } public Maplist(id) {           new menu[300], pos, menupos;     pos += format(menu[pos],299-pos,"Map List^n^n");     menupos += MenuPage[id];     for(new i = (menupos * 7); i <= (menupos * 7) + 7;i++)     {         pos += format(menu[pos], 299-pos, "%i. %s^n",i,map[i]);     }         pos += format(menu[pos],299-pos,"^n^n8. Last Page^n9.Next Page^n^n0. Exit");         new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9;     show_menu(id, keys, menu, 15, "menu_Maplist")             return PLUGIN_HANDLED }   public DoMaplist(id,key) {     switch(key)     {         // change level I guess...?                 case 8 :         {             if(MenuPage[id] > 0)             {                 MenuPage[id]--;                 Maplist(id);             }             else             {                 Maplist(id);             }         }                 case 9 :         {             if(MenuPage[id] < totalmaps)             {                 MenuPage[id]++;                 Maplist(id);             }             else             {                 Maplist(id);             }         }     } } public client_disconnect(id) {     MenuPage[id] = 0; } public Load_File() {     get_configsdir(configsdir,63);         format(configfile,63,"%s/maplist.ini",configsdir);         if(!file_exists(configfile))     {         write_file(configfile,"de_dust",0);     } } public Read_File() {     new data[3][36],line,lnstr[256],len;     while(read_file(configfile,line++,data[0],255,len))     {         if(lnstr[0] == ';' || !len)         {             continue;         }         copyc(map[line],19,data[0],'.')         totalmaps++;     } }
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Kensai
Veteran Member
Join Date: Aug 2005
Location: San Diego, California
Old 01-03-2006 , 20:36  
Reply With Quote #4

Sweet thanks.

What does this do exactly?

Code:
if(!file_exists(configfile))         {         write_file(configfile,"de_dust",0);     }
Kensai is offline
Send a message via AIM to Kensai Send a message via MSN to Kensai
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 01-03-2006 , 20:40  
Reply With Quote #5

If the file doesn't exist, it creates it.

write_file on a non-existant file creates the file.

EDIT:

Also you should probably increase the buffer sizes in Load_File, I copied those parts from another plugin I made and forgot to change the maxlen to fit what you wanted.

EDIT2:

Awesome, my karma is 69. I'm sexy.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Kensai
Veteran Member
Join Date: Aug 2005
Location: San Diego, California
Old 01-04-2006 , 18:17  
Reply With Quote #6

Lolz. yupp yupp.

And okay will do.

EDIT: So it's making a file called "de_dust"??
Kensai is offline
Send a message via AIM to Kensai Send a message via MSN to Kensai
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 01-04-2006 , 20:53  
Reply With Quote #7

It's creating the file, and then writing one line inside it, "de_dust", without the quotes.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode