Raised This Month: $7 Target: $400
 1% 

[INC] Client Preferences Stocks


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xXDeathreusXx
Veteran Member
Join Date: Mar 2013
Location: pPlayer->GetOrigin();
Old 04-07-2018 , 15:34   [INC] Client Preferences Stocks
Reply With Quote #1

A simple little include that extends functionality of the cookie system with stocks that set or get specific data types from a cookie's string value. Also includes a Cookie methodmap for you object lovers out there. All of these will error out if given an invalid handle or the given clients cookies are not cached. I provide no guarantees everything will work as intended or at all!

If you are including this, don't include clientprefs, this already includes it!

Contents:

Cookie methods:
Code:
methodmap Cookie < Handle
{
	public Cookie(const char[] name, const char[] description, CookieAccess access)
	{
		if(name[0] == 0) // If we were somehow given no name, don't try to register the cookie
			return view_as<Cookie>(INVALID_HANDLE);
		return view_as<Cookie>(RegClientCookie(name, description, access)); // Register the cookie and return it as an object
	}
	
	property bool IsValid
	{
		public get()  // Are we null?
	}

	public bool HasValue(int iClient)

	public void SetPrefabMenu(CookieMenu type, const char[] display, CookieMenuHandler handler=INVALID_FUNCTION, any info=0)
	
	public void SetValue(int iClient, const char[] sValue="")
	public void GetValue(int iClient, char[] sValue, int iMaxLen)
	
	public void SetInt(int iClient, int iNum=0)
	public int GetInt(int iClient)
	
	public void SetFloat(int iClient, float fFloat=0.0)
	public float GetFloat(int iClient)
	
	public void SetBool(int iClient, bool bEnabled=false)
	public bool GetBool(int iClient)
}
Stocks:
  • SetClientCookieInt(client, cookieHandle, int)
  • GetClientCookieInt(client, cookieHandle)
  • SetClientCookieFloat(client, cooieHandle, float)
  • GetClientCookieFloat(client, cookieHandle)
  • SetClientCookieBool(client, cookieHandle, bool)
  • GetClientCookieBool(client, cookieHandle)
Attached Files
File Type: inc clientprefs_stocks.inc (9.3 KB, 186 views)
__________________
Plugins|Profile
Requests closed

I'm a smartass by nature, get used to it

Last edited by xXDeathreusXx; 08-21-2019 at 21:31. Reason: New methods
xXDeathreusXx is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 04-11-2018 , 07:53   Re: [INC] Client Preferences Stocks
Reply With Quote #2

Thanks for this!
ThatKidWhoGames is offline
xXDeathreusXx
Veteran Member
Join Date: Mar 2013
Location: pPlayer->GetOrigin();
Old 08-21-2019 , 21:32   Re: [INC] Client Preferences Stocks
Reply With Quote #3

Updated to add a couple helpers
  • IsValid property
  • HasValue method
  • SetCookieMenuPrefab wrapper



You can also find an experiment to create a cookie value out of an array of values, I have never tested it nor proofread it, use at your own discretion
__________________
Plugins|Profile
Requests closed

I'm a smartass by nature, get used to it
xXDeathreusXx is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-22-2019 , 10:03   Re: [INC] Client Preferences Stocks
Reply With Quote #4

Sick! Already thinking of what I can use this for.
Halt 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:59.


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