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

set time for menu item


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 05-30-2019 , 07:46   set time for menu item
Reply With Quote #1

good day ,

actually i need help regarding setting time for any indiviual item in a menu

like for an example :- this is money menu , i take money once and i have to wait atleast 60 seconds to take again ? i dont have any idea about this so can you help me

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


new keys MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_menu("Menu 1"keys"func_menu")
        
register_concmd("money_menu""Server_Menu").
}


public 
Server_Menu(id)
{

   static 
menu[650], iLen
   
   iLen 
0
   iLen 
formatex(menu[iLen], charsmax(menu) - iLen"\rmoney-Menu^n^n")
    
    
   
   
iLen += formatex(menu[iLen], charsmax(menu) - iLen"\r1\w. \y Take money \r^n")
   
keys |= MENU_KEY_1
   
 
   show_menu
(idkeysmenu, -1"Menu 1")


 
public 
func_menu(idkey)
{
   switch(
key)
   {
      case 
0cs_set_user_money(id,50000);
   }
   return 
PLUGIN_HANDLED

__________________
SED LYF !!!
SHIELD755 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-30-2019 , 07:53   Re: set time for menu item
Reply With Quote #2

Store the time in a global variable for each player and each menu item. You will need a bidimensional array, something like: ItemBoughtTime[33][NUMBER_OF_ITEMS]
__________________
HamletEagle is offline
thEsp
BANNED
Join Date: Aug 2017
Old 05-30-2019 , 08:29   Re: set time for menu item
Reply With Quote #3

Use new menu system, it has inbuilt time rejection option AFAIK.

Last edited by thEsp; 05-30-2019 at 08:30.
thEsp is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 05-30-2019 , 08:36   Re: set time for menu item
Reply With Quote #4

PHP Code:
#include <amxmodx>
#include <amxmisc>

enum _:MENUITEMS
{
    
TAKE_MONEY
}

new 
g_iCooldown[33][MENUITEMS];

public 
plugin_init()
{
    
register_concmd("money_menu""Server_Menu");
}

public 
Server_Menu(id)
{
    new 
menu menu_create"\rMoney-Menu""menu_handler" );
    
menu_additem(menu"Take Money""");

    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
menu_handleridmenuitem )
{
    switch( 
item )
    {
        case 
TAKE_MONEY:
        {
            new 
iCurTime get_systime();
            if(
iCurTime g_iCooldown[id][TAKE_MONEY] >= 60) {
                
g_iCooldown[id][TAKE_MONEY] = iCurTime;
                
cs_set_user_money(id50000);
            }
            else {
                
client_print(idprint_chat"You have to wait %dsec."iCurTime g_iCooldown[id][TAKE_MONEY]);
            }
        }
    }

    
menu_destroymenu );
    return 
PLUGIN_HANDLED;

__________________
Airkish is offline
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 05-30-2019 , 08:57   Re: set time for menu item
Reply With Quote #5

Quote:
Originally Posted by thEsp View Post
Use new menu system, it has inbuilt time rejection option AFAIK.
can i get link to thread to know more information



Quote:
Originally Posted by Airkish View Post
PHP Code:
#include <amxmodx>
#include <amxmisc>

enum _:MENUITEMS
{
    
TAKE_MONEY
}

new 
g_iCooldown[33][MENUITEMS];

public 
plugin_init()
{
    
register_concmd("money_menu""Server_Menu");
}

public 
Server_Menu(id)
{
    new 
menu menu_create"\rMoney-Menu""menu_handler" );
    
menu_additem(menu"Take Money""");

    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
menu_handleridmenuitem )
{
    switch( 
item )
    {
        case 
TAKE_MONEY:
        {
            new 
iCurTime get_systime();
            if(
iCurTime g_iCooldown[id][TAKE_MONEY] >= 60) {
                
g_iCooldown[id][TAKE_MONEY] = iCurTime;
                
cs_set_user_money(id50000);
            }
            else {
                
client_print(idprint_chat"You have to wait %dsec."iCurTime g_iCooldown[id][TAKE_MONEY]);
            }
        }
    }

    
menu_destroymenu );
    return 
PLUGIN_HANDLED;


thanks it is working
__________________
SED LYF !!!
SHIELD755 is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 05-30-2019 , 09:13   Re: set time for menu item
Reply With Quote #6

Quote:
Originally Posted by SHIELD755 View Post
can i get link to thread to know more information
You can learn about it here: https://forums.alliedmods.net/showthread.php?t=46364

IMO it's way easier.
__________________
Airkish is offline
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 05-30-2019 , 09:16   Re: set time for menu item
Reply With Quote #7

thanks
__________________
SED LYF !!!
SHIELD755 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-30-2019 , 13:14   Re: set time for menu item
Reply With Quote #8

Quote:
Originally Posted by thEsp View Post
Use new menu system, it has inbuilt time rejection option AFAIK.
Nope, the time thingy is about the duration of which the menu stays on the screen.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 17:51.


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