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

Menu show/hide button on player_spawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheBladerX
Member
Join Date: Dec 2012
Location: Slovakia
Old 10-19-2018 , 20:50   Menu show/hide button on player_spawn
Reply With Quote #1

Hello, I have a menu, which opens at Ham_Spawn. How do I make one more button into it, that when you press it once, it will not show menu every time you respawn (button called do not show for now). [But it will show the menu for first time when you join server and spawn.] When you press the exact same button for the second time, it will keep showing menu every time after respawn (it will be called keep showing menu every time after respawn). Thank you.
TheBladerX is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 10-20-2018 , 07:48   Re: Menu show/hide button on player_spawn
Reply With Quote #2

Create a global array, let's say
PHP Code:
new bool:g_bMenuEnabled[MAX_PLAYERS 1]; 
Now when a player connects, set that player's index in the array to true
PHP Code:
public client_connect(id)
{
        
g_bMenuEnabled[id] = true;

In your Ham_Spawn hook, add an if clause to opening the menu
PHP Code:
if(g_bMenuEnabled[id])
        
OpenMenu(id); // ? 
Add another item to your menu for disabling it on spawn
PHP Code:
menu_additem(menug_bMenuEnabled[id] ? "Don't show menu on spawn" "Show menu on spawn"); 
Finally, in your menu handler function, add a clause for the new item, where you reverse the value of the global variable.
PHP Code:
switch(item)
{
        case 
0: ...
        case 
1: ...
        ...
        case ?: 
g_bMenuEnabled[id] = !g_bMenuEnabled[id];

Kushfield is offline
TheBladerX
Member
Join Date: Dec 2012
Location: Slovakia
Old 10-20-2018 , 10:37   Re: Menu show/hide button on player_spawn
Reply With Quote #3

It's working! Thank you. (had to define max players) But I have one more question. How do I make client_print "something", after someone clicks "don't show menu on spawn"? But it does not show for "show menu on spawn".

//edit:
And when you click "show menu on spawn again", it directly closes. How can I make it, that it just will not disappear again after the "show menu" click, but it will be still showing.

And one more thing. Is it possible, to take exit out of there and assign this enabler/disabler number 0, as exit was?

Last edited by TheBladerX; 10-20-2018 at 10:58.
TheBladerX is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 10-20-2018 , 13:34   Re: Menu show/hide button on player_spawn
Reply With Quote #4

Check the value of g_bMenuEnabled[id] again, so you know which name is shown for the menu item, and print the text accordingly.

To keep displaying the menu, you would need to use menu_item_setname to first change the item's name and then menu_display to display the menu again.

If you want to remove the exit button and change this to number 0, I believe you would have to use
PHP Code:
menu_setprop(menuMPROP_EXITMEXIT_NEVER); // Disable exit button
menu_setprop(menuMPROP_PERPAGE0); // Disable pagination 
and then repeat
PHP Code:
menu_addblank2(menu); 
until you have a total of 9 items on the menu, after that add the "enabler/disabler" item. Now it should be item number 10 on the menu and require pressing 0 to activate.

There might be some more elegant way to set an item explicitly to number 0, but I have never needed to do something like that and can't find anything with a quick look.
Kushfield is offline
TheBladerX
Member
Join Date: Dec 2012
Location: Slovakia
Old 10-23-2018 , 13:52   Re: Menu show/hide button on player_spawn
Reply With Quote #5

Unfortunately, I tried to check it, but it did not work out. But thank you for the other things, I appreciate it.
TheBladerX is offline
TheBladerX
Member
Join Date: Dec 2012
Location: Slovakia
Old 11-12-2018 , 11:23   Re: Menu show/hide button on player_spawn
Reply With Quote #6

Okay, I tried it again, and could not finish it. Could you please help me a little bit?
TheBladerX is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 11-15-2018 , 11:29   Re: Menu show/hide button on player_spawn
Reply With Quote #7

How far did you get and what exactly is the issue now?
It would be beneficial if you can provide the piece of code that you tried so we can see what's wrong with it.
Kushfield is offline
TheBladerX
Member
Join Date: Dec 2012
Location: Slovakia
Old 11-15-2018 , 16:28   Re: Menu show/hide button on player_spawn
Reply With Quote #8

I deleted it, because I was not able to make it correctly. I mean, the issue is that I tried to check the value of g_bMenuEnabled[id] again, so it would not hide menu directly after clicking "do not show again", it will only change the value of g_bMenuEnabled[id] to false (and it will print - if you want to reopen the menu, type /blabla...). The menu can be closed with number 0 afterwards and it would not show after user closes it with 0, until user reopens the menu by command.
TheBladerX is offline
Kushfield
Member
Join Date: Jan 2017
Location: Estonia
Old 11-16-2018 , 10:12   Re: Menu show/hide button on player_spawn
Reply With Quote #9

The suggestion of checking g_bMenuEnabled was so you can achieve this:
Quote:
How do I make client_print "something", after someone clicks "don't show menu on spawn"? But it does not show for "show menu on spawn".
I assume you would want to keep showing the menu regardless of the value of g_bMenuEnabled, for that you just need to use menu_display(id, menu) in the menu handler function.
Kushfield is offline
TheBladerX
Member
Join Date: Dec 2012
Location: Slovakia
Old 11-17-2018 , 09:53   Re: Menu show/hide button on player_spawn
Reply With Quote #10

Quote:
I assume you would want to keep showing the menu regardless of the value of g_bMenuEnabled, for that you just need to use menu_display(id, menu) in the menu handler function.
Yes, if you hit "don't show menu on spawn" it would be still shown, but it checks the value of g_bMenuEnabled to false, and it will keep showing, until you select one item out of it (for example that exit button), so basically, I need to edit handler function, where it check the value of g_bMenuEnabled to false and at the same time, it will pop up the menu again [function OpenMenu(id)], just until you select one item (it would not show at next spawn, bcs g_bMenuEnabled is false). I hope you understand now.
TheBladerX 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 11:30.


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