AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Open menu only once per round (https://forums.alliedmods.net/showthread.php?t=162903)

duducp 07-24-2011 10:25

Open menu only once per round
 
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!")
}

Bugsy 07-24-2011 10:32

Re: Open menu only once per round
 
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 


2reason2kill 07-24-2011 15:31

Re: Open menu only once per round
 
Quote:

Originally Posted by Bugsy (Post 1517403)
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?

fysiks 07-24-2011 16:08

Re: Open menu only once per round
 
Quote:

Originally Posted by 2reason2kill (Post 1517600)
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.

Noah BR 03-17-2024 12:44

Re: Open menu only once per round
 
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
}

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

Bugsy 03-17-2024 14:46

Re: Open menu only once per round
 
Show your full code, and put your code between php tags. [ php ] [/ php ] (without spaces)

Tote 03-17-2024 19:11

Re: Open menu only once per round
 
Quote:

Originally Posted by Noah BR (Post 2819672)
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


All times are GMT -4. The time now is 03:38.

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