I'm wondering this as well. What I've done is just store a default value to my variable that's supposed to hold the player's cookie value if they're joining for the first time.
You can do this by setting the default value in the "player_connect" event since that always fires before "OnClientCookiesCached". Then inside "OnClientCookiesCached" you can check whether the stored cookie value of the client is empty to determine if you should overwrite the default value that the client was assigned when they initially connected to the server.
PHP Code:
public void OnPluginStart()
{
HookEvent("player_connect", vEventPlayerConnect, EventHookMode_Pre);
}
public void vEventPlayerConnect(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
g_iCookieData[client] = 1; // assign default value (assuming this player doesn't have a previous cookie yet since we cannot retrieve their cookies at the time of this event)
}
public void OnClientCookiesCached(int client)
{
char sValue[3];
g_hCookie.Get(client, sValue, sizeof(sValue));
if (sValue[0] != '\0') // only overwrite if cookie stored a previous value (not empty)
{
g_iCookieData[client] = StringToInt(sValue);
}
}
After doing this, you can store the value of "g_iCookieData" so the client will have their cookie value saved.
__________________