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);
}