PHP Code:
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#pragma semicolon 1
#pragma newdecls required
#define DEBUG 1
Handle g_hPreviouslyConnected;
public Plugin myinfo =
{
name = "Force Reconnect New Map Players",
author = "Cruze",
description = "Force new map player to reconnect to make sure they see particles.",
version = "1.0",
url = "http://steamcommunity.com/profiles/76561198132924835"
};
public void OnPluginStart()
{
g_hPreviouslyConnected = RegClientCookie("Force Reconnect New Map Players", "FRNMP Settings", CookieAccess_Private);
for(int i = 1; i <= MaxClients; i++)
{
if (!AreClientCookiesCached(i))
{
continue;
}
OnClientCookiesCached(i);
}
}
public void OnClientCookiesCached(int client)
{
CreateTimer(3.0, CheckSettings, client, TIMER_FLAG_NO_MAPCHANGE);
}
public Action CheckSettings(Handle timer, any client)
{
char sValue[PLATFORM_MAX_PATH], map[32];
GetCurrentMap(map, sizeof(map));
GetClientCookie(client, g_hPreviouslyConnected, sValue, sizeof(sValue));
#if defined DEBUG
PrintToServer("FRNP: %s", map);
PrintToServer("FRNP: client cookie value %s", sValue);
#endif
if(StrContains(sValue, map, false) == -1)
{
Format(sValue, sizeof(sValue), "%s %s", sValue, map);
#if defined DEBUG
PrintToServer("FRNP: %s", sValue);
#endif
SetClientCookie(client, g_hPreviouslyConnected, sValue);
if(IsValidClient(client))
{
PrintToChat(client, "[SM] You will be reconnected to server as it's your first connect in this map.");
#if defined DEBUG
PrintToServer("FRNP: %N's first connect in this map.", client);
#endif
CreateTimer(3.0, Reconnect, client);
}
}
else
{
#if defined DEBUG
PrintToServer("FRNP: Not first connect of %N", client);
#endif
}
}
public void OnClientPostAdminCheck(int client)
{
OnClientCookiesCached(client);
}
public Action Reconnect(Handle timer, any client)
{
if(IsValidClient(client))
{
ClientCommand(client, "retry");
}
}
stock bool IsValidClient(int client)
{
if(client <= 0 ) return false;
if(client > MaxClients) return false;
if(!IsClientConnected(client)) return false;
if(IsClientReplay(client)) return false;
if(IsClientSourceTV(client)) return false;
return IsClientInGame(client);
}
I tried but I think
SetClientCookie is not working properly. Correct the code if you can please
__________________