AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Filling menu with options (https://forums.alliedmods.net/showthread.php?t=22738)

Kensai 01-02-2006 22:22

Filling menu with options
 
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.

Charr 01-03-2006 15:58

I would read the file and format the menu options in a loop

Hawk552 01-03-2006 20:02

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++;     } }

Kensai 01-03-2006 20:36

Sweet thanks.

What does this do exactly?

Code:
if(!file_exists(configfile))         {         write_file(configfile,"de_dust",0);     }

Hawk552 01-03-2006 20:40

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.

Kensai 01-04-2006 18:17

Lolz. yupp yupp.

And okay will do.

EDIT: So it's making a file called "de_dust"??

Hawk552 01-04-2006 20:53

It's creating the file, and then writing one line inside it, "de_dust", without the quotes.


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

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