AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   prevent double items in menu (https://forums.alliedmods.net/showthread.php?t=236540)

faki 03-07-2014 07:15

prevent double items in menu
 
I build a menu with categories and after that i hook second menu.

I need to prevent the code to show double categories.
Here is the code:
Code:

                for(new i=1;i < file_size(file,1);i++)
                {

                        formatex(tempid4,255,"%d",i-1)
                        new data[1024],buffer
                        read_file(file,i,data,1023,buffer)
                        parse(data,category,63)
                        if(!equal(data,"//",2) && !equal(data,""))
                        menu_additem(menu,category,tempid4,0)
                }

Here is content in ini file:
"Deathrun" "IP: 127.0.0.1:27016"
"Deathrun" "IP: 127.0.0.1:27017"
"Classic" "IP: 127.0.0.1:27018"

But in category menu shows Deathrun two times i need to show only one item as name "Deathrun".

Black Rose 03-07-2014 17:28

Re: prevent double items in menu
 
Should the second value be ignored or added to the first one?

Basically...
Option 1:
Code:

1. Deathrun    IP: 127.0.0.1:27016
2. Classic      IP: 127.0.0.1:27018

Option 2:
Code:

1. Deathrun    IP: 127.0.0.1:27016|IP: 127.0.0.1:27017
2. Classic      IP: 127.0.0.1:27018

If the first option applies:
Create a cellarray to store all the categories, if one already exists just ignore the other. This would require a loop to check which is pretty bad.
Another option would be to use a trie with the category as the key and just checking if the key exists. Remember to clear it when you've generated the menu.

If the second option applies:
You would have to buffer all information until you are ready to push it out into the menu.
I would again use a trie to store the data using the category as a key. That way you could easily edit it until you are ready to push the menu. The problem being you would have to have something to remember all the keys as you need them later to generate the menu. In this case set up a cellarray to remember the trie keys.

There might be better options. These are dynamic and therefor scalable. If you only have a few menu options you would most likely be better off by using static arrays. It all depends on the situation. Is this plugin private or something you plan on releasing? Do you want it to be idiot proof or does it require some basic knowledge to set up correctly?


All times are GMT -4. The time now is 05:55.

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