Raised This Month: $51 Target: $400
 12% 

Open menu only once per round


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
duducp
New Member
Join Date: Dec 2010
Old 07-24-2011 , 10:25   Open menu only once per round
Reply With Quote #1

Hello!
Sorry my bad English.
I wanted to know the code for the player to use the menu soh once per round.

Quote:
#include <amxmisc>
#include <fun>
#include <cstrike>

public plugin_init()
{
register_plugin("Menu Basico", "0.1", ".leonel")
register_clcmd( "meu_menu","meu_menu")
register_clcmd("say .menu", "meu_menu")
register_clcmd("say /menu", "meu_menu");
}

public meu_menu(id)
{
new menu = menu_create("Menu:", "menu_handler");
menu_additem(menu, "\w300 De Gravidade", "1", 0);
menu_additem(menu, "\w250 HP + 150 Colete", "2", 0);
menu_additem(menu, "\wGlow Azul", "3", ADMIN_ADMIN);

menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
}

public menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}

new data[6], iName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
new key = str_to_num(data);
switch(key)
{
case 1:
{
set_user_gravity(id, 0.3)
set_task(20.0, "remove_gravity", id)
}
case 2:
{
set_user_health(id, 250)
cs_set_user_armor(id, 150, CS_ARMOR_VESTHELM)
}
case 3:
{
set_user_rendering(id,kRenderFxGlowShell,0,0, 255,kRenderNormal,25)
set_task(20.0, "remove_glow", id)
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}

public remove_gravity(id)
{
set_user_gravity(id, 1.0)
client_print(id, print_chat, "Sua gravidade baixa acabou!")
}

public remove_glow(id)
{
set_user_rendering(id,kRenderFxNone,0,0,0,kRe nderNormal,0)
client_print(id, print_chat, "Seu glow acabou!")
}
duducp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-24-2011 , 10:32   Re: Open menu only once per round
Reply With Quote #2

Create a boolean variable and set it to false when the player is spawned. When the player opens the menu set it to true. Only allow the player to open the menu if the boolean is false.

PHP Code:
new boolg_bUsedMenu33 ];

//Spawn
g_bUsedMenuid ] = false;

//In menu function
if ( g_bUsedMenuid ] )
     return

g_bUsedMenuid ] = true;

//menu code 
__________________
Bugsy is offline
2reason2kill
Senior Member
Join Date: Feb 2011
Old 07-24-2011 , 15:31   Re: Open menu only once per round
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Create a boolean variable and set it to false when the player is spawned. When the player opens the menu set it to true. Only allow the player to open the menu if the boolean is false.

PHP Code:
new boolg_bUsedMenu33 ];

//Spawn
g_bUsedMenuid ] = false;

//In menu function
if ( g_bUsedMenuid ] )
     return

g_bUsedMenuid ] = true;

//menu code 
Can we Make a varriable Then Make it to 0?
2reason2kill is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2011 , 16:08   Re: Open menu only once per round
Reply With Quote #4

Quote:
Originally Posted by 2reason2kill View Post
Can we Make a varriable Then Make it to 0?
That doesn't make sense. Bugsy's code is the way it should be done.
__________________
fysiks is offline
Noah BR
Junior Member
Join Date: Mar 2024
Old 03-17-2024 , 12:44   Re: Open menu only once per round
Reply With Quote #5

So I tried to add this when opening the zombie menu but I couldn't, can you help me?

============================================= ===================

public select_class_zombie(id, menu, item)
{
if (!g_zombie[id]) return PLUGIN_HANDLED

if (item == MENU_EXIT)
{
menu_destroy(menu)
give_zombiebom(id)

return PLUGIN_HANDLED
}
new idclass[32], name[32], access
menu_item_getinfo(menu, item, access, idclass, 31, name, 31, access)

// set class zombie
g_zombieclass[id] = str_to_num(idclass)
make_zombie(id)
give_zombiebom(id)

menu_destroy(menu)
//client_print(id, print_chat, "item: %i - id: %s", name, idclass)

return PLUGIN_HANDLED
}

============================================= ===================

Last edited by Noah BR; 03-17-2024 at 12:45.
Noah BR is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-17-2024 , 14:46   Re: Open menu only once per round
Reply With Quote #6

Show your full code, and put your code between php tags. [ php ] [/ php ] (without spaces)
__________________
Bugsy is offline
Tote
Senior Member
Join Date: Jul 2023
Old 03-17-2024 , 19:11   Re: Open menu only once per round
Reply With Quote #7

Quote:
Originally Posted by Noah BR View Post
So I tried to add this when opening the zombie menu but I couldn't, can you help me?

============================================= ===================

public select_class_zombie(id, menu, item)
{
if (!g_zombie[id]) return PLUGIN_HANDLED

if (item == MENU_EXIT)
{
menu_destroy(menu)
give_zombiebom(id)

return PLUGIN_HANDLED
}
new idclass[32], name[32], access
menu_item_getinfo(menu, item, access, idclass, 31, name, 31, access)

// set class zombie
g_zombieclass[id] = str_to_num(idclass)
make_zombie(id)
give_zombiebom(id)

menu_destroy(menu)
//client_print(id, print_chat, "item: %i - id: %s", name, idclass)

return PLUGIN_HANDLED
}

============================================= ===================
Code:
#include <amxmisc>
#include <fun>
#include <cstrike>

new menu_limit[33] // first, we add global which we will use to check if menu is opened 1 time or not

public plugin_init()
{
	register_plugin("Menu Basico", "0.1", ".leonel")
	register_clcmd( "meu_menu","meu_menu")
	register_clcmd("say .menu", "meu_menu")
	register_clcmd("say /menu", "meu_menu");
	
	register_event("HLTV", "event_new_round", "a", "1=0", "2=0")  // Making An event which we will use to reset the limit to 0
}

public client_putinserver(id)
{
	menu_limit[id] = 0 // Make it 0 When join server because hasn't used the menu.
}

public event_new_round(id)
{
	menu_limit[id] = 0 // we dont need to check if it was 1 or not since we are going to reset it for all on new round cause limit is 1
}

public meu_menu(id)
{
	new menu = menu_create("Menu:", "menu_handler");
	menu_additem(menu, "\w300 De Gravidade", "1", 0);
	menu_additem(menu, "\w250 HP + 150 Colete", "2", 0);
	menu_additem(menu, "\wGlow Azul", "3", ADMIN_ADMIN);
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, menu, 0);
}

public menu_handler(id, menu, item)
{
	if( item == MENU_EXIT )
	{
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	
	new data[6], iName[64];
	new access, callback;
	menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
	new key = str_to_num(data);
	
	if(menu_limit[id] == 1) // It will only work if menu_limit[id] == 1, so you see, below we did it to 1 on each case when use it once
	{
		client_print_color("^1Sorry, ^4The limit to open menu per round is 1") // show message that limit reached
		return PLUGIN_HANDLED; // return because limit reached so it wont open menu
	}
	
	switch(key)
	{
		case 1:
		{
			set_user_gravity(id, 0.3)
			set_task(20.0, "remove_gravity", id)
			menu_limit[id] = 1 // using the global and setting it to 1 so we can check if the menu is used once
		}
		case 2:
		{
			set_user_health(id, 250)
			cs_set_user_armor(id, 150, CS_ARMOR_VESTHELM)
			menu_limit[id] = 1 // using the global and setting it to 1 so we can check if the menu is used once
		}
		case 3:
		{
			set_user_rendering(id,kRenderFxGlowShell,0,0, 255,kRenderNormal,25)
			set_task(20.0, "remove_glow", id)
			menu_limit[id] = 1 // using the global and setting it to 1 so we can check if the menu is used once
		}
	}
	menu_destroy(menu);
	return PLUGIN_HANDLED;
}

public remove_gravity(id)
{
	set_user_gravity(id, 1.0)
	client_print(id, print_chat, "Sua gravidade baixa acabou!")
}

public remove_glow(id)
{
	set_user_rendering(id,kRenderFxNone,0,0,0,kRe nderNormal,0)
	client_print(id, print_chat, "Seu glow acabou!")
}
I did some explaination here for U.

NOTE: you can use like menu_limit[id]++ , menu_limit[id] += 1 if you want more limits and just make check if == 2 then return or == 3 then return

Last edited by Tote; 03-17-2024 at 19:13.
Tote 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 10:26.


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