AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu Case Check (https://forums.alliedmods.net/showthread.php?t=294516)

DarthMan 03-01-2017 02:41

Menu Case Check
 
Hello. I am running into a problem.
I was working on a menu that gets stuff from an ini file, and I am stuck at the switch item part.
Well, I can add lines for every 1 of these 128 case, case 0: case 1: and so on.
My problem here si that I don't want to do this for every case, I need a script that will atomatically look for every case from 0 to 128, to set the right model. Or maybe another way of knowing which tiem was selected on the menu. Thanks !

jimaway 03-01-2017 04:52

Re: Menu Case Check
 
just store the model file name in the item info string

DarthMan 03-01-2017 05:32

Re: Menu Case Check
 
Quote:

Originally Posted by jimaway (Post 2499619)
just store the model file name in the item info string

That didn't work. Can you show me exactly how?
Here is how the models are displayed :
Code:

                case 0:
                {
                new menu_model = menu_create("Models Menu", "mh_MMenu")
                for (new i; (i < file_size(conffile_model, 1)); i++)
                {
                        read_file(conffile_model, i, file_model, 127, leng)
                        menu_additem(menu_model, file_model, "", 0);
                }               
                menu_setprop(menu_model, MPROP_EXIT, MEXIT_ALL);
                menu_setprop(menu_model, MPROP_BACKNAME, "Back");
                menu_setprop(menu_model, MPROP_NEXTNAME, "Next");
                menu_setprop(menu_model, MPROP_EXITNAME, "Close");
                menu_destroy(menu);
                menu_display(id, menu_model, 0);
                }

The problem goes here :

Code:

public mh_MMenu(id, menu_model, item)
{
        if(item == MENU_EXIT)
        {
                menu_cancel(id);
                return PLUGIN_HANDLED;
        }

        new command[6], name[64], access, callback;

        menu_item_getinfo(menu_model, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);

       
        switch (item)
        {
                case 0:
                {
                read_file(conffile_model, item, file_model, 127, leng)
                tfc_setmodel(id,file_model,"0");
                client_print(id, print_chat, "You changed the player model to %s.", file_model);               
                }
        }
        menu_destroy(menu_model);

        return PLUGIN_CONTINUE;
}

I tried replacing the item as u said, but with no luck, so I changed it back.

jimaway 03-01-2017 06:12

Re: Menu Case Check
 
Code:

switch (item)
        {
                case 0:
                {
                read_file(conffile_model, item, file_model, 127, leng)
                tfc_setmodel(id,file_model,"0");
                client_print(id, print_chat, "You changed the player model to %s.", file_model);               
                }
        }

->
Code:

tfc_setmodel(id,name,"0");
client_print(id, print_chat, "You changed the player model to %s.", name);

when copy-pasting snippets into your code, try looking up what it actually does. good source for this information are the .inc files or http://www.amxmodx.org/funcwiki.php

DarthMan 03-01-2017 06:16

Re: Menu Case Check
 
Quote:

Originally Posted by jimaway (Post 2499632)
Code:

switch (item)
        {
                case 0:
                {
                read_file(conffile_model, item, file_model, 127, leng)
                tfc_setmodel(id,file_model,"0");
                client_print(id, print_chat, "You changed the player model to %s.", file_model);               
                }
        }

->
Code:

tfc_setmodel(id,name,"0");
client_print(id, print_chat, "You changed the player model to %s.", name);

when copy-pasting snippets into your code, try looking up what it actually does. good source for this information are the .inc files or http://www.amxmodx.org/funcwiki.php

Well, the plugin works fine, only thing is that I don't want to add case for each item.
That would mean that I have to put 128 cases, which i don't want to.

DarthMan 03-01-2017 07:04

Re: Menu Case Check
 
Quote:

Originally Posted by DarthMan (Post 2499634)
Well, the plugin works fine, only thing is that I don't want to add case for each item.
That would mean that I have to put 128 cases, which i don't want to.

I solved the problem by using case 0 .. 127: :)

jimaway 03-01-2017 18:03

Re: Menu Case Check
 
Quote:

Originally Posted by DarthMan (Post 2499641)
I solved the problem by using case 0 .. 127: :)

good for you, but you don't even need to use switch() if you would just read my last post


All times are GMT -4. The time now is 20:59.

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