AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] Client Preferences Stocks (https://forums.alliedmods.net/showthread.php?t=306620)

xXDeathreusXx 04-07-2018 15:34

[INC] Client Preferences Stocks
 
1 Attachment(s)
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)

ThatKidWhoGames 04-11-2018 07:53

Re: [INC] Client Preferences Stocks
 
Thanks for this!

xXDeathreusXx 08-21-2019 21:32

Re: [INC] Client Preferences Stocks
 
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

Halt 08-22-2019 10:03

Re: [INC] Client Preferences Stocks
 
Sick! Already thinking of what I can use this for.


All times are GMT -4. The time now is 03:18.

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