Raised This Month: $ Target: $400
 0% 

prevent double items in menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
faki
Senior Member
Join Date: Jul 2013
Old 03-07-2014 , 07:15   prevent double items in menu
Reply With Quote #1

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".
faki is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-07-2014 , 17:28   Re: prevent double items in menu
Reply With Quote #2

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?
__________________

Last edited by Black Rose; 03-07-2014 at 17:31.
Black Rose is offline
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 05:55.


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