Raised This Month: $ Target: $400
 0% 

Menu Case Check


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-01-2017 , 02:41   Menu Case Check
Reply With Quote #1

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 !
DarthMan is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-01-2017 , 04:52   Re: Menu Case Check
Reply With Quote #2

just store the model file name in the item info string
jimaway is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-01-2017 , 05:32   Re: Menu Case Check
Reply With Quote #3

Quote:
Originally Posted by jimaway View Post
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.
DarthMan is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-01-2017 , 06:12   Re: Menu Case Check
Reply With Quote #4

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

Last edited by jimaway; 03-01-2017 at 06:12.
jimaway is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-01-2017 , 06:16   Re: Menu Case Check
Reply With Quote #5

Quote:
Originally Posted by jimaway View Post
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 is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-01-2017 , 07:04   Re: Menu Case Check
Reply With Quote #6

Quote:
Originally Posted by DarthMan View Post
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:
DarthMan is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-01-2017 , 18:03   Re: Menu Case Check
Reply With Quote #7

Quote:
Originally Posted by DarthMan View Post
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
jimaway 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 20:59.


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