AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [INC/STOCK] menu_set_timeout (https://forums.alliedmods.net/showthread.php?t=294087)

OciXCrom 02-19-2017 13:22

[INC/STOCK] menu_set_timeout
 
1 Attachment(s)
With this stock you can make a menu disappear after X seconds.

Code:
stock menu_set_timeout(const id, const iMenu, const Float:fTime)

Example:

Code:
#include <amxmodx> #include <menutime> public plugin_init() {     register_plugin("Menu Timeout Test", "1.0", "OciXCrom")     register_clcmd("say /tmenu", "ShowMenu")     register_clcmd("say_team /tmenu", "ShowMenu") } public ShowMenu(id) {     new iMenu = menu_create("Test Menu", "Menu_Handler")         menu_additem(iMenu, "This")     menu_additem(iMenu, "is")     menu_additem(iMenu, "only")     menu_additem(iMenu, "a")     menu_additem(iMenu, "test")    
    menu_set_timeout(id, iMenu, 3.0)
    menu_display(id, iMenu)     return PLUGIN_HANDLED } public Menu_Handler(id, iMenu, iItem) {     menu_destroy(iMenu)     return PLUGIN_HANDLED }

Please note that if you're using AMXX 1.8.3, this stock is unnecessary, because AMXX already has an option like this:

Code:
native menu_display(id, menu, page=0, time=-1)

Black Rose 02-19-2017 18:37

Re: [INC/STOCK] menu_set_timeout
 
Great snippet.
Don't make it an include.

fysiks 02-19-2017 20:21

Re: [INC/STOCK] menu_set_timeout
 
While I agree that an include for this is unnecessary, if you do want it as an include and the function exists in AMX Mod X 1.8.3-dev then you might want to check the AMX Mod X version and conditionally disable the functions based on that.

OciXCrom 02-20-2017 07:14

Re: [INC/STOCK] menu_set_timeout
 
Even though it exists in 1.8.3, it doesn't exist in the earlier dev builds, so adding a version check might break the code. Is there a way to check the dev build with #if? The AMXX_VERSION_LOCAL_REV value is a string, so how do I check that, and how do I know in which dev build this was added?

edon1337 02-20-2017 07:21

Re: [INC/STOCK] menu_set_timeout
 
I personally think this is unnecessary, like, you just have to set a task and hide the menu inside the task. No need for someone to make a(n) stock/include for you. Anyways wouldn't enum be better than define for the Task ID?

HamletEagle 02-20-2017 08:48

Re: [INC/STOCK] menu_set_timeout
 
Quote:

Anyways wouldn't enum be better than define for the Task ID?
That does not make much sense. enum and define are not the same thing. You should read the two enum tutorials from this section.

klippy 02-20-2017 09:51

Re: [INC/STOCK] menu_set_timeout
 
And menu_destroy() doesn't hide the specified menu, it destroys its internal AMXX handle.

edon1337 02-20-2017 10:12

Re: [INC/STOCK] menu_set_timeout
 
Quote:

Originally Posted by KliPPy (Post 2496874)
And menu_destroy() doesn't hide the specified menu, it destroys its internal AMXX handle.

fixed

Quote:

Originally Posted by HamletEagle (Post 2496864)
That does not make much sense. enum and define are not the same thing. You should read the two enum tutorials from this section.

I've seen people store the task ids in enum, and I never said they were the same..

HamletEagle 02-20-2017 11:26

Re: [INC/STOCK] menu_set_timeout
 
Task ids are just numbers, doesn't matter how you save them. That will be decided by plugin's internal design. For example, if you want to index an array by some predefined values enum could be handy.

Example from WC3FT mod, where tasks are separated by player ids:
Code:

#define TASK_ITEMS                0                // Showing items in the HUD
#define TASK_SPAWN                32                // Respawning from revive
#define TASK_ITEM_SCROLL        64                // Respawning after death from an item
#define TASK_VENGEANCE                96                // Respawning from having vengeance (warden ultimate)
...

Can be simplified with an enum:
Code:

enum ( += 32 )
{
    TASK_ITEMS,
    TASK_SPAWN,
    TASK_ITEM_SCROLL,
    TASK_VENGEANCE,
...


addons_zz 02-20-2017 12:45

Re: [INC/STOCK] menu_set_timeout
 
Quote:

Originally Posted by OciXCrom (Post 2496838)
Even though it exists in 1.8.3, it doesn't exist in the earlier dev builds, so adding a version check might break the code. Is there a way to check the dev build with #if? The AMXX_VERSION_LOCAL_REV value is a string, so how do I check that,

There is anything I know of. Anyways, just check `#if AMXX_VERSION_NUM < 183` and block for all devs versions. If someone is using an old dev build, this someone should update it.

Quote:

Originally Posted by OciXCrom (Post 2496838)
and how do I know in which dev build this was added?

Just review the git history and find out on which commit it was added. https://github.com/alliedmodders/amxmodx/commits/master
May be it was a pull request, so check them. https://github.com/alliedmodders/amx...pr+is%3Aclosed

You could also find out where it is defined and do blame command on some git gui.
  1. https://github.com/alliedmodders/amxmodx/blame/master/amxmodx/newmenus.cpp
  2. https://github.com/alliedmodders/amxmodx/commits/master/amxmodx/newmenus.cpp
Reviewing the history on the second link `master/amxmodx/newmenus.cpp` above should be enough.


All times are GMT -4. The time now is 18:53.

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