Hello all,
I'm hosting a dedicated L4D2 server, using SM 1.6.2 and everything is working fine except Clientprefs.
I want to store some data for players like buy credit and so I've read the clientprefs API and rewritten the buy menu plugin to work with clientprefs. So, I've managed to do it as it stores and retrives data correctly, but if I restart the server(or shut it down), it doesn't get the correct cookie value and sets it to the default value(100 as seen in the code). I've searched the forums but didn't find anything which would help me. Any ideas?
Edit:
Code:
public OnClientPostAdminCheck(client)
{
//Create a timer to check the status of the player's cookie
if(!IsFakeClient(client))
CreateTimer(0.0, Timer_Check, client, TIMER_FLAG_NO_MAPCHANGE);
}
//This timer will loop until the client's cookies are loaded, or until the client leaves
public Action:Timer_Check(Handle:timer, any:client)
{
if(client)
{
if(AreClientCookiesCached(client))
CreateTimer(0.0, Timer_Process, client, TIMER_FLAG_NO_MAPCHANGE);
else if(IsClientInGame(client))
CreateTimer(5.0, Timer_Check, client, TIMER_FLAG_NO_MAPCHANGE);
}
return Plugin_Continue;
}
//Called after a client's cookies have been processed by the server
public Action:Timer_Process(Handle:timer, any:client)
{
//For whatever reason, make sure the client is still in game
if(IsClientInGame(client) && !IsFakeClient(client))
{
//Declare a temporary string and store the contents of the client's cookie
decl String:c_sBuyMenuPoints[5] = "";
GetClientCookie(client, c_hBuyMenuPoints, c_sBuyMenuPoints, sizeof(c_sBuyMenuPoints));
//If the cookie is empty, throw some data into it. If the cookie is disabled, we turn off the client's setting
if(StrEqual(c_sBuyMenuPoints, "") || StrEqual(c_sBuyMenuPoints, "0"))
{
SetClientCookie(client, c_hBuyMenuPoints, "100"); // 100 for new players
points[client] = 100;
}
// If the cookie isn't empty, set client's points
else
{
points[client] = StringToInt(c_sBuyMenuPoints);
}
}
return Plugin_Continue;
}
public OnClientDisconnect(client)
{
decl String:c_sPointsToStore[5];
if(!IsFakeClient(client))
{
IntToString(points[client], c_sPointsToStore, sizeof(c_sPointsToStore));
SetClientCookie(client, c_hBuyMenuPoints, c_sPointsToStore);
}
}
Also, in OnPluginStart i have
Code:
c_hBuyMenuPoints = RegClientCookie("BuyMenuPoints", "Buy Menu Points", CookieAccess_Protected);