Senior Member
|
03-17-2024
, 19:11
Re: Open menu only once per round
|
#7
|
Quote:
Originally Posted by Noah BR
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.
|
|