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

[INC/STOCK] menu_set_timeout


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-19-2017 , 13:22   [INC/STOCK] menu_set_timeout
Reply With Quote #1

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)
Attached Files
File Type: inc menutime.inc (566 Bytes, 373 views)
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-19-2017 , 18:37   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #2

Great snippet.
Don't make it an include.
__________________
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-19-2017 , 20:21   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #3

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.
__________________
fysiks is online now
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-20-2017 , 07:14   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #4

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?
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-20-2017 , 07:21   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #5

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?
__________________

Last edited by edon1337; 02-20-2017 at 10:22.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-20-2017 , 08:48   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #6

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.
__________________

Last edited by HamletEagle; 02-20-2017 at 08:48.
HamletEagle is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-20-2017 , 09:51   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #7

And menu_destroy() doesn't hide the specified menu, it destroys its internal AMXX handle.
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-20-2017 , 10:12   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #8

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

Quote:
Originally Posted by HamletEagle View Post
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..
__________________

Last edited by edon1337; 02-20-2017 at 10:21.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-20-2017 , 11:26   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #9

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,
...
__________________

Last edited by Emp`; 02-20-2017 at 11:56. Reason: added example from WC3FT mod
HamletEagle is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 02-20-2017 , 12:45   Re: [INC/STOCK] menu_set_timeout
Reply With Quote #10

Quote:
Originally Posted by OciXCrom View Post
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 View Post
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.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 02-20-2017 at 12:47.
addons_zz is offline
Reply


Thread Tools
Display Modes

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 02:24.


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