Raised This Month: $ Target: $400
 0% 

[HELP] Auto close menu with HUD timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 10-16-2015 , 15:53   [HELP] Auto close menu with HUD timer
Reply With Quote #1

I'm trying to create a function that will auto close this menu after 20 seconds (cvar).
But seems that i'm doing something wrong!


PHP Code:
#define TASKID 1234

new hudtimercvarhudhandler

public plugin_init()
{
    
cvar register_cvar("timer""20")
    
hudhandler CreateHudSyncObj()
}

public 
adminMenuPre(id)
{
    
hudtimer get_pcvar_num(cvar)
    if(
hudtimer == -1)
    return
    new 
menu menu_create("menu title""adminMenuPre_handler")
    
    
formatex(onlyAdmin63"\wText 1: %s"OnlyA[id] ? "\rON" "\dOFF")
    
formatex(onlyVip63"\wText 2: %s"OnlyV[id] ? "\rON" "\dOFF")
    
formatex(onlyServer63"\wText 3: %s"OnlyS[id] ? "\rON" "\dOFF")
    
menu_additem(menu"\wText 04""1"ADMIN_BAN)
    
menu_additem(menu"\wText 05""2"ADMIN_LEVEL_A)
    
menu_additem(menu"\wText 06^n^n""3")
    
    
menu_additem(menuonlyAdmin"4"ADMIN_BAN)
    
menu_additem(menuonlyVip"5"ADMIN_LEVEL_A)
    
menu_additem(menuonlyServer"6")

    
menu_setprop(menuMPROP_EXITMEXIT_NEVER)
    
menu_display(idmenu0)
    
    
set_task(1.0"close_menu"TASKID__"b")
    }


public 
close_menu(id)
{
    if(
hudtimer <= 0)
    {
        
remove_task(TASKID)
                
// close the menu? 
        
menu_destroy(menu)
    } 
    else
    {
        
set_hudmessage(random(100), 150random(150), 0.030.8300.2,2.0,2.2,0.2)    
        
ShowSyncHudMsg(0hudhandler"This menu will auto close in %i seconds..."hudtimer)
    }    
    
hudtimer--

Also the timer is counting wrong, it's showing like 20 seconds... 14 seconds... 3 seconds... Hope you understand what i mean!

Last edited by CHE4TER; 10-18-2015 at 16:24. Reason: Title updaded.
CHE4TER is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-16-2015 , 18:44   Re: Auto close menu with HUD timer
Reply With Quote #2

It's counting like that because you have opened the menu more than once, which causes the task to be called multiple times. Reset the timer when opening the menu.

Last edited by OciXCrom; 10-16-2015 at 18:44.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Chihuahuax
Senior Member
Join Date: Oct 2014
Location: Malaysia
Old 10-17-2015 , 10:20   Re: Auto close menu with HUD timer
Reply With Quote #3

PHP Code:
set_task(get_pcvar_num(cvar), "close_menu"TASKID__"b"
Hope im right...
Chihuahuax is offline
Send a message via Skype™ to Chihuahuax
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 10-17-2015 , 16:13   Re: Auto close menu with HUD timer
Reply With Quote #4

Quote:
Originally Posted by OciXCrom View Post
It's counting like that because you have opened the menu more than once, which causes the task to be called multiple times. Reset the timer when opening the menu.
Can u show?


Quote:
Originally Posted by Chihuahuax View Post
PHP Code:
set_task(get_pcvar_num(cvar), "close_menu"TASKID__"b"
Hope im right...
The cvar is for the time wich will close the menu. set_task(1.0) = start the counter after 1 second.
CHE4TER is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-17-2015 , 19:22   Re: Auto close menu with HUD timer
Reply With Quote #5

hudtimer = 0
remove_task(TASKID)

Use this in the beginning of the menu function.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
colossus
Member
Join Date: Sep 2013
Old 10-17-2015 , 23:58   Re: Auto close menu with HUD timer
Reply With Quote #6

PHP Code:
new menukeys,
get_user_menu(idmenukeys)

menu_destroy(menu
colossus is offline
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 10-18-2015 , 16:23   Re: Auto close menu with HUD timer
Reply With Quote #7

Still not working, my bad!
CHE4TER is offline
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 10-28-2015 , 09:23   Re: [HELP] Auto close menu with HUD timer
Reply With Quote #8

No one can help?
CHE4TER is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 10-28-2015 , 10:00   Re: [HELP] Auto close menu with HUD timer
Reply With Quote #9

Just try below code:
PHP Code:
#include <amxmodx>

#define TASK_COUNT 1994

new g_iCount[33]
new 
g_iCountAmount

// We need global menu
new g_iMenu

new g_iHud

public plugin_init()
{
    
g_iCountAmount register_cvar("cs_count_amount""20")
    
    
// How to open our menu?
    // Just say /open
    
register_clcmd("say /open""open_menu")
    
register_clcmd("say_team /open""open_menu")
    
    
g_iMenu menu_create("Menu Title""menu_handler")
    
    
menu_additem(g_iMenu"Item 1")
    
menu_additem(g_iMenu"Item 2")
    
menu_additem(g_iMenu"Item 3")
    
    
g_iHud CreateHudSyncObj()
}

public 
open_menu(id)
{
    
g_iCount[id] = 0
    set_task
(1.0"MenuCount"id+TASK_COUNT__"b"
    
    
// Display our menu
    
menu_display(idg_iMenu0)
}

public 
menu_handler(idmenuiditem)
{
    
// Do semething
}

public 
MenuCount(id)
{
    
id -= TASK_COUNT
    
if(is_user_alive(id))
    {
        
g_iCount[id] ++
        
        if(
g_iCount[id] >= get_pcvar_num(g_iCountAmount))
        {
            
remove_task(id+TASK_COUNT)
            
g_iCount[id] = 0
            
// Close menu
            
menu_cancel(g_iMenu)
        } 
        else
        {
            
set_hudmessage(random(100), 150random(150), 0.030.8300.22.02.20.2)    
            
ShowSyncHudMsg(idg_iHud"This menu will auto close in %i seconds..."get_pcvar_num(g_iCountAmount) - g_iCount[id])
        }
    }


Last edited by zmd94; 10-28-2015 at 22:06.
zmd94 is offline
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 10-28-2015 , 13:21   Re: [HELP] Auto close menu with HUD timer
Reply With Quote #10

Nope, doesn't work! The hud count is not displayed, only the menu is displayed.
CHE4TER 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 22:08.


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