View Single Post
Cruze
Veteran Member
Join Date: May 2017
Old 08-03-2019 , 07:43   Re: Auto-reconnect for particles [ZR]
Reply With Quote #3

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<= MaxClientsi++)
    {
        if (!
AreClientCookiesCached(i))
        {
            continue;
        }
        
OnClientCookiesCached(i);
    }
}

public 
void OnClientCookiesCached(int client
{
    
CreateTimer(3.0CheckSettingsclientTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action CheckSettings(Handle timerany client)
{
    
char sValue[PLATFORM_MAX_PATH], map[32];
    
GetCurrentMap(mapsizeof(map));
    
GetClientCookie(clientg_hPreviouslyConnectedsValuesizeof(sValue));
    
#if defined DEBUG
    
PrintToServer("FRNP: %s"map);
    
PrintToServer("FRNP: client cookie value %s"sValue);
    
#endif 
    
if(StrContains(sValuemapfalse) == -1)
    {
        
Format(sValuesizeof(sValue), "%s %s"sValuemap);
        
#if defined DEBUG
        
PrintToServer("FRNP: %s"sValue);
        
#endif 
        
SetClientCookie(clientg_hPreviouslyConnectedsValue);
        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.0Reconnectclient);
        }
    }
    else
    {
        
#if defined DEBUG
        
PrintToServer("FRNP: Not first connect of %N"client);
        
#endif 
    
}
}

public 
void OnClientPostAdminCheck(int client)
{
    
OnClientCookiesCached(client);
}

public 
Action Reconnect(Handle timerany client)
{
    if(
IsValidClient(client))
    {
        
ClientCommand(client"retry");
    }
}

stock bool IsValidClient(int client)
{
    if(
client <= ) 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
__________________
Taking paid private requests! Contact me
Cruze is offline