[Tutorial] ClientPrefs
Alrighty, so using ClientPrefs is pretty straight forward. However, not a lot of plugins include support for it. Hopefully this helps someone.
The first thing you need to determine is what you need to store. Is it just a simple on off value? A name? In this case, let's store a simple bool. PHP Code:
PHP Code:
PHP Code:
We now need to define our CookieMenuHandler. The handler is pretty straight forward if you've used the menu API. If not, you may need to brush up on Menus. In this specific case, we only need to worry about the CookieMenuAction_SelectOption. We need to simply cover setting the boolean so our internal state holds consistent. The major failure of the API is when the setting changes, buffer is always "", which makes me sad, but oh well. PHP Code:
PHP Code:
Last but not least, the magical OnClientCookiesCached forward. Here you're just reading a value out of a cookie. You can definitely register multiple cookies, or no cookies. OnClientCookiesCached has no defined order, and can happen before or after OnClientPostAdminCheck. If you have a protected admin cookie, you're going to need to have your own custom handler, which is beyond the scope of this tutorial (at the moment). In our case, we're reading a simple one byte value from a String. In our case, we're going to use 8 bytes. PHP Code:
EDIT: The final Plugin Looks Like: PHP Code:
|
Re: [Tutorial] ClientPrefs
Thank you... learned something new about SetCookiePrefabMenu
|
Re: [Tutorial] ClientPrefs
Thanks :)
The way you loop through players is unique :O |
Re: [Tutorial] ClientPrefs
Appreciate the example! Any quick leads on how to have a specific message pop up when the client select on or off in the menu? Can't seem to find much after searching a bit.
|
Re: [Tutorial] ClientPrefs
Quote:
|
Re: [Tutorial] ClientPrefs
Quote:
Spoiler
|
Re: [Tutorial] ClientPrefs
Quote:
|
Re: [Tutorial] ClientPrefs
I don't get it... Why my cookie are always lost when I reload my plugin and players are in game ?
I can restart my server and player have their correct cookie [OK] I can restart map and player have their correct cookie [OK] I reload my plugin and players are in game, they lost their cookies !!! [X] NOTE: I didn't understand everything you wrote, so I'm not sure if you speak about this... Original thread |
Re: [Tutorial] ClientPrefs
OnClientCookiesCached will only fire when they connect. If you yeload the plugin, you need to loop over the players and do AreClientCookiesCached in OnPluginStart... Look at the example.
|
Re: [Tutorial] ClientPrefs
Yep, I did, but cookies still lost.
|
All times are GMT -4. The time now is 15:30. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.