Raised This Month: $32 Target: $400
 8% 

Store menu selection in client?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
343N
Member
Join Date: Jul 2015
Old 02-21-2017 , 18:03   Store menu selection in client?
Reply With Quote #1

So this is the my first plugin ever. I want a menu to let clients select a config for the models they'll use for their weapons, but the problem is I need to somehow keep track of each clients selection in the menu, since I'll have another plugin making callbacks depending on what option was picked in the menu. How would I go about storing a users selection/choice in a menu so that another plugin/part of my plugin can make sure to do the correct thing for each client?

Basically, how would I do this?

Code:
public bool AlwaysExecutingCallback(int client){

If (getSelectedOptionFromMyMenu(client)) { // <--- how do I get something like this
//do blah
}

}
I hope this is a good enough explanation of what I want to do.

Last edited by 343N; 02-21-2017 at 18:28.
343N is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-21-2017 , 19:17   Re: Store menu selection in client?
Reply With Quote #2

A param in the menu handler is the item number. You can use or store that to calculate the return menu item, just divide by 7
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
343N
Member
Join Date: Jul 2015
Old 02-21-2017 , 19:25   Re: Store menu selection in client?
Reply With Quote #3

Quote:
Originally Posted by friagram View Post
A param in the menu handler is the item number. You can use or store that to calculate the return menu item, just divide by 7
Okay, the divide by 7 part just confused the hell out of me. Does the menu itself store the options chosen by each user, why would I need to divide by 7? (unless you're talking about paged entries)

If you're talking about pages, I might have made a miscommunication, I'm not worrying about pages. I'm just wondering, how would I get/store X client's chosen option on the menu to execute an appropriate action based on their setting in a constantly firing callback. (If that makes sense). Does the menu handler store the chosen option by each client for the handlers lifetime? And if so, how would I retrieve a specific clients chosen menu option?

Last edited by 343N; 02-21-2017 at 20:02.
343N is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-22-2017 , 05:57   Re: Store menu selection in client?
Reply With Quote #4

Create a globally-scoped player-indexed array to store the options chosen by each client (use GetItem() to get the menu info), then just pull the data from the array when you need it.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-22-2017 , 07:20   Re: Store menu selection in client?
Reply With Quote #5

Quote:
Originally Posted by 343N View Post
Okay, the divide by 7 part just confused the hell out of me. Does the menu itself store the options chosen by each user, why would I need to divide by 7? (unless you're talking about paged entries)

If you're talking about pages, I might have made a miscommunication, I'm not worrying about pages. I'm just wondering, how would I get/store X client's chosen option on the menu to execute an appropriate action based on their setting in a constantly firing callback. (If that makes sense). Does the menu handler store the chosen option by each client for the handlers lifetime? And if so, how would I retrieve a specific clients chosen menu option?
Oh, the menu gives you the selection in the handler when it is type MenuAction_Select
https://wiki.alliedmods.net/Menu_API...od)#Basic_Menu
Param1 will be the client index, param2 is the menu item.
You can get the strings from the item if you need there too.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-22-2017 , 08:45   Re: Store menu selection in client?
Reply With Quote #6

Param2 will always yield the position of the item in a MenuAction_Select.

Position of an item =/= the button (number) it was pressed.

If you want to return the "Page" to be used in a https://sm.alliedmods.net/new-api/menus/Menu/DisplayAt function, you can use https://sm.alliedmods.net/new-api/menus/Menu/Selection
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 02-22-2017 at 08:46.
OSWO is offline
343N
Member
Join Date: Jul 2015
Old 02-22-2017 , 11:47   Re: Store menu selection in client?
Reply With Quote #7

Quote:
Originally Posted by nosoop View Post
Create a globally-scoped player-indexed array to store the options chosen by each client (use GetItem() to get the menu info), then just pull the data from the array when you need it.
Ah, thought so. This was what I was looking for, I thought there might be a more elegant solution to this. How would I go about storing this data so that when the map changes/server crashes, the data is retained?
343N is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-22-2017 , 19:23   Re: Store menu selection in client?
Reply With Quote #8

Quote:
Originally Posted by 343N View Post
How would I go about storing this data so that when the map changes/server crashes, the data is retained?
You'd likely want to store it in a database. The easiest way to store account-specific information persistently would be to use the Client Preferences API, which abstracts SQL / SQLite database storage.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-22-2017 at 19:24.
nosoop is offline
343N
Member
Join Date: Jul 2015
Old 02-23-2017 , 00:49   Re: Store menu selection in client?
Reply With Quote #9

Quote:
Originally Posted by nosoop View Post
You'd likely want to store it in a database. The easiest way to store account-specific information persistently would be to use the Client Preferences API, which abstracts SQL / SQLite database storage.
Looks good, thank you for your help, much appreciated.
343N 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 15:06.


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