AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Tutorial] ClientPrefs (https://forums.alliedmods.net/showthread.php?t=228244)

KyleS 11-26-2013 10:50

Re: [Tutorial] ClientPrefs
 
Quote:

Originally Posted by Arkarr (Post 2065549)
Yep, I did, but cookies still lost.

Can you show your more up to date code?

Arkarr 11-26-2013 12:31

Re: [Tutorial] ClientPrefs
 
(plugin bugged. removed.)

RedSword 11-26-2013 17:19

Re: [Tutorial] ClientPrefs
 
Because when the plugins load, it doesn't get the clients' cookie. What it does is check that the clients have their cookie loaded (but not in your plugin's memory) using OnClientCookiesCached ==> why even do this ?.

Try to simply run OnClientPutInServer() for every InGame client OnPluginStart() rather than L33-37.


EDIT nvm; misread code; didn't notice at 2 places you were getting client cookies

KyleS 11-26-2013 19:04

Re: [Tutorial] ClientPrefs
 
Quote:

Originally Posted by RedSword (Post 2065770)
Because when the plugins load, it doesn't get the clients' cookie. What it does is check that the clients have their cookie loaded (but not in your plugin's memory) using OnClientCookiesCached ==> why even do this ?.

Try to simply run OnClientPutInServer() for every InGame client OnPluginStart() rather than L33-37.

:?

Quote:

Originally Posted by Arkarr (Post 2065661)
Here is it.

It looks like you've preserved the load code in OnClientPutInServer, which is horribly incorrect. It also looks like you only store the client data when they disconnect, which would reproduce the plugin reload bug. If you're worried about the overhead of updating your cookie data over and over again in your timer, you can use OnPluginEnd; but that's a thing.


EDIT: Unrelated to ClientPrefs, you should return Plugin_Stop in your Timer, otherwise you're leaking timers. Your plugin will eventually auto-unload after enough clients connect, from running out of Handles. You should also pass the flag TIMER_FLAG_NO_MAPCHANGE, as all of your timers should die then anyways.

friagram 11-27-2013 03:57

Re: [Tutorial] ClientPrefs
 
...
Ok

Mabye you are writing over them. Are you by chance using onclientputinserver to initialize stuff! Because careclientcookiescached can happen before or after that. You may want to use onclientdonnected instead, to pre-initialize vars while you wait for cookies to load in. It may be that they are loading, but you are overwriting them with junk data later.

Edit:didnt see this second page, but looks like is still probly relevant.

Arkarr 11-27-2013 12:44

Re: [Tutorial] ClientPrefs
 
Oka, thanks for help. I updated this plugin.

ddhoward 01-16-2014 16:34

Re: [Tutorial] ClientPrefs
 
Does clientprefs keep track of which plugin assigned which cookie? Or should plugin authors be careful to ensure that the cookie name is unique?

Root_ 01-16-2014 17:33

Re: [Tutorial] ClientPrefs
 
Quote:

Originally Posted by ddhoward (Post 2086911)
Does clientprefs keep track of which plugin assigned which cookie?

Not really.
Quote:

Originally Posted by ddhoward (Post 2086911)
Or should plugin authors be careful to ensure that the cookie name is unique?

This. For example, in some of my plugins I retrieve quake sounds client preferences this way.
Code:
new bool:QPreferences[MAXPLAYERS + 1]; public OnClientCookiesCached(client) {     if (AreClientCookiesCached(client))     {         decl String:value[5], Handle:preferences;         preferences = FindClientCookie("Quake Sound Pref");         GetClientCookie(client, preferences, value, sizeof(value));         CloseHandle(preferences);         QPreferences[client] = bool:!StringToInt(value);     } }

ddhoward 01-18-2014 19:06

Re: [Tutorial] ClientPrefs
 
Good to know. I recently saw a plugin (not on this site) that named its cookie "cookie." Was wondering if this might conflict with any other plugin with the same non-descriptive cookie name. Now I know it will lol

Mitchell 01-20-2014 10:47

Re: [Tutorial] ClientPrefs
 
Should also mention that cookies should not be used to store stats, as in time played. It makes it nearly impossible to reset all the players in that cookie back to 0, etc. Should only be used as preferences.


All times are GMT -4. The time now is 22:25.

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