AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Auto close menu with HUD timer (https://forums.alliedmods.net/showthread.php?t=273271)

CHE4TER 10-16-2015 15:53

[HELP] Auto close menu with HUD timer
 
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!

OciXCrom 10-16-2015 18:44

Re: Auto close menu with HUD timer
 
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.

Chihuahuax 10-17-2015 10:20

Re: Auto close menu with HUD timer
 
PHP Code:

set_task(get_pcvar_num(cvar), "close_menu"TASKID__"b"

Hope im right...

CHE4TER 10-17-2015 16:13

Re: Auto close menu with HUD timer
 
Quote:

Originally Posted by OciXCrom (Post 2353764)
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 (Post 2353934)
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.

OciXCrom 10-17-2015 19:22

Re: Auto close menu with HUD timer
 
hudtimer = 0
remove_task(TASKID)

Use this in the beginning of the menu function.

colossus 10-17-2015 23:58

Re: Auto close menu with HUD timer
 
PHP Code:

new menukeys,
get_user_menu(idmenukeys)

menu_destroy(menu


CHE4TER 10-18-2015 16:23

Re: Auto close menu with HUD timer
 
Still not working, my bad!

CHE4TER 10-28-2015 09:23

Re: [HELP] Auto close menu with HUD timer
 
No one can help?

zmd94 10-28-2015 10:00

Re: [HELP] Auto close menu with HUD timer
 
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])
        }
    }



CHE4TER 10-28-2015 13:21

Re: [HELP] Auto close menu with HUD timer
 
Nope, doesn't work! The hud count is not displayed, only the menu is displayed.


All times are GMT -4. The time now is 22:08.

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