AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   how to save and load cookies (https://forums.alliedmods.net/showthread.php?t=329493)

Nicker 12-26-2020 15:47

how to save and load cookies
 
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);
}


GsiX 12-27-2020 01:50

Re: how to save and load cookies
 
Spoiler


All times are GMT -4. The time now is 06:04.

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