Raised This Month: $ Target: $400
 0% 

how to save and load cookies


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nicker
Junior Member
Join Date: Dec 2020
Old 12-26-2020 , 15:47   how to save and load cookies
Reply With Quote #1

How i can load and save cookies? please help
I need plugin something like that

HTML Code:
#include <sourcemod>
#include <sdktools>
#include <clientprefs>

int g_bIsEnabled[MAXPLAYERS + 1]

Handle g_hCookie; 

public void OnPluginStart()
{
    g_hCookie = RegClientCookie("prefix_cookie_name", "Cookie description", CookieAccess_Protected);
    
    RegConsoleCmd("sm_turnon", Cos);
    RegConsoleCmd("sm_turnoff", Cos2);

    HookEvent("player_spawn", Spawn);
} 

public Action Cos(int client, int args) {
    g_bIsEnabled[client] = true;
}

public Action Cos2(int client, int args) {
    g_bIsEnabled[client] = false;
}

public void OnClientCookiesCached(int client) 
{
    char sValue[8];

    GetClientCookie(client, g_hCookie, sValue, sizeof(sValue)); 
    g_bIsEnabled[client] = (sValue[0] != '\0' && StringToInt(sValue)); 
} 

public Action command_undercover(int client, int args)
{
    char sValue[8];

    g_bIsEnabled[client] = !g_bIsEnabled[client]; 
    IntToString(g_bIsEnabled[client], sValue, sizeof(sValue)); 
    SetClientCookie(client, g_hCookie, sValue); 
} 

public Action Spawn(Event event, const char[] name, bool dontBroadcast) {
    int client = GetClientOfUserId(event.GetInt("userid"));
    
    if (g_bIsEnabled[client]) {
        PrintToChat(client, "you have cookie");
    }
    
    else if (!g_bIsEnabled[client]) {
        return Plugin_Handled;
    }
    return Plugin_Continue;
}

public void OnClientPutInServer(int client) {
    char sValue[8];
    
    SetClientCookie(client, g_bIsEnabled[client], sValue); 
}
Nicker is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-27-2020 , 01:50   Re: how to save and load cookies
Reply With Quote #2

Spoiler
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX 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 20:26.


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