#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <geoip>
#include <vip_core>
#include <clientprefs>
#include <colors>
#define VIP_ConnectTag "VCT"
#define VIP_ConnectHideCountry "VCHC"
#define TAG_INFO "[BSIW]"
#define TEAM_SPECTATORS 1
#define TEAM_SURVIVORS 2
#define TEAM_INFECTED 3
Handle g_hcCookie, g_hccCookie;
public Plugin myinfo =
{
name = "VIP Connect/Disconnect",
description = "VIP Connect/Disconnect Messages",
author = "BS/IW",
version = "1.0",
url = "N/A"
}
//Special Thanks: "[L4D2] Player Death/Team/Disconnect Messages" by "Dirka_Dirka, def (user00111), BHaType"
public void OnPluginStart()
{
LoadTranslations("vip_modules.phrases");
LoadTranslations("VIP_Connect_Disconnect_Team_Death.phrases");
g_hcCookie = RegClientCookie("VIP_ConnectTag", "VIP_ConnectTag", CookieAccess_Public);
g_hccCookie = RegClientCookie("VIP_ConnectHideCountry", "VIP_ConnectHideCountry", CookieAccess_Public);
HookEvent("player_death", PlayerDeath);
HookEvent("player_disconnect", PlayerDisconnect, EventHookMode_Pre);
HookEvent("player_team", PlayerTeam);
}
public void VIP_OnVIPLoaded()
{
VIP_RegisterFeature(VIP_ConnectTag, BOOL, _, OnToggleHideConnectItem);
VIP_RegisterFeature(VIP_ConnectHideCountry, BOOL, _, OnToggleHideConnectCountryItem);
}
public Action OnToggleHideConnectItem(int client, const char[] sFeatureName, VIP_ToggleState OldStatus, VIP_ToggleState &NewStatus)
{
if(NewStatus == ENABLED) SetClientCookie(client, g_hcCookie, "1");
else SetClientCookie(client, g_hcCookie, "0");
return Plugin_Continue;
}
public Action OnToggleHideConnectCountryItem(int client, const char[] sFeatureName, VIP_ToggleState OldStatus, VIP_ToggleState &NewStatus)
{
if(NewStatus == ENABLED) SetClientCookie(client, g_hccCookie, "1");
else SetClientCookie(client, g_hccCookie, "0");
return Plugin_Continue;
}
public void OnClientPutInServer(int client)
{
if(!IsFakeClient(client)) CreateTimer(3.0, Timer_Welcome, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}
public Action Timer_Welcome(Handle hTimer, any UserId) // Каллбек нашего таймера
{
int client = GetClientOfUserId(UserId);
if(client)
{
char ip[16], country[46], sConnect[64], sConnectHideCountry[64];
GetClientIP(client, ip, 16);
GetClientCookie(client, g_hcCookie, sConnect, sizeof(sConnect));
GetClientCookie(client, g_hccCookie, sConnectHideCountry, sizeof(sConnectHideCountry));
if(GeoipCountry(ip, country, 45))
{
if (VIP_IsClientVIP(client))
{
if(VIP_IsClientFeatureUse(client, VIP_ConnectTag) && VIP_IsClientFeatureUse(client, VIP_ConnectHideCountry))
{
if(StringToInt(sConnect) == 0 && StringToInt(sConnectHideCountry) == 1)
CPrintToChatAll("%t", "%s Player %N has joined the game", TAG_INFO, client);
else if(StringToInt(sConnect) == 1 && StringToInt(sConnectHideCountry) == 0)
CPrintToChatAll("%t", "%s [VIP] %N (%s) has joined the game", TAG_INFO, client, country);
else if(StringToInt(sConnect) == 1 && StringToInt(sConnectHideCountry) == 1)
CPrintToChatAll("%t", "%s [VIP] %N has joined the game", TAG_INFO, client);
else
CPrintToChatAll("%t", "%s Player %N (%s) has joined the game", TAG_INFO, client, country);
}
if(VIP_IsClientFeatureUse(client, VIP_ConnectTag) && !VIP_IsClientFeatureUse(client, VIP_ConnectHideCountry))
{
if(StringToInt(sConnect) == 1)
CPrintToChatAll("%t", "%s [VIP] %N (%s) has joined the game", TAG_INFO, client, country);
else
CPrintToChatAll("%t", "%s Player %N (%s) has joined the game", TAG_INFO, client, country);
}
if(VIP_IsClientFeatureUse(client, VIP_ConnectHideCountry) && !VIP_IsClientFeatureUse(client, VIP_ConnectTag))
{
if(StringToInt(sConnectHideCountry) == 1)
CPrintToChatAll("%t", "%s [VIP] %N has joined the game", TAG_INFO, client);
else
CPrintToChatAll("%t", "%s Player %N (%s) has joined the game", TAG_INFO, client, country);
}
}
else CPrintToChatAll("%t", "%s Player %N (%s) has joined the game", TAG_INFO, client, country);
}
else
{
if (VIP_IsClientVIP(client))
{
if(VIP_IsClientFeatureUse(client, VIP_ConnectTag))
{
if(StringToInt(sConnect) == 1)
CPrintToChatAll("%t", "%s [VIP] %N has joined the game", TAG_INFO, client);
else
CPrintToChatAll("%t", "%s Player %N has joined the game", TAG_INFO, client);
}
}
else CPrintToChatAll("%t", "%s Player %N has joined the game", TAG_INFO, client);
}
}
return Plugin_Stop;
}
public Action PlayerDisconnect(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if ((client > 0) && !IsFakeClient(client))
{
char reason[100];
event.GetString("reason", reason, sizeof(reason));
if (StrContains(reason, "kicked", false) != -1)
Format(reason, sizeof(reason), "%t", "Kicked");
else if (StrContains(reason, "banned", false) != -1)
Format(reason, sizeof(reason), "%t", "Banned");
else if (StrContains(reason, "timed out", false) != -1)
Format(reason, sizeof(reason), "%t", "Lost Connection");
else if (StrContains(reason, "No Steam Logon", false) != -1)
Format(reason, sizeof(reason), "%t", "Game crashed");
char player_name[MAX_NAME_LENGTH], sConnect[64];
event.GetString("name", player_name, sizeof(player_name));
GetClientCookie(client, g_hcCookie, sConnect, sizeof(sConnect));
if (VIP_IsClientVIP(client))
{
if(VIP_IsClientFeatureUse(client, VIP_ConnectTag))
{
if(StringToInt(sConnect) == 1)
CPrintToChatAll("%t", "%s [VIP] %s left the game. (%s)", TAG_INFO, player_name, reason);
else
CPrintToChatAll("%t", "%s Player %s left the game. (%s)", TAG_INFO, player_name, reason);
}
}
else CPrintToChatAll("%t", "%s Player %s left the game. (%s)", TAG_INFO, player_name, reason);
if (!dontBroadcast) SetEventBroadcast(event, true);
}
return Plugin_Continue;
}
public Action PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client))
{
char sConnect[64];
GetClientCookie(client, g_hcCookie, sConnect, sizeof(sConnect));
if (VIP_IsClientVIP(client))
{
if(VIP_IsClientFeatureUse(client, VIP_ConnectTag))
{
if(StringToInt(sConnect) == 1)
{
CPrintToChatAll("%t", "[VIP] %N is dead. Message: Meet me in hell!", client);
return Plugin_Handled;
}
else
{
CPrintToChatAll("%t", "%N is dead. Message: Meet me in hell!", client);
return Plugin_Handled;
}
}
}
else
{
CPrintToChatAll("%t", "%N is dead. Message: Meet me in hell!", client);
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action PlayerTeam(Event event, char[] event_name, bool dontBroadcast)
{
bool IsDissconect = event.GetBool("disconnect");
if(IsDissconect) return;
int client = GetClientOfUserId(event.GetInt("userid"));
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
{
if (IsFakeClient(client)) return; // a bot
if (!IsFakeClient(client))
{
char sTeam[32], sConnect[64];
GetClientCookie(client, g_hcCookie, sConnect, sizeof(sConnect));
int team = event.GetInt("team");
switch (team)
{
case TEAM_SPECTATORS: Format(sTeam, sizeof(sTeam), "%t", "Spectators");
case TEAM_SURVIVORS: Format(sTeam, sizeof(sTeam), "%t", "Survivors");
case TEAM_INFECTED: Format(sTeam, sizeof(sTeam), "%t", "Infected");
}
if (VIP_IsClientVIP(client))
{
if(VIP_IsClientFeatureUse(client, VIP_ConnectTag))
{
if(StringToInt(sConnect) == 1)
CPrintToChatAll("%t", "%s [VIP] %N has joined the %s.", TAG_INFO, client, sTeam);
else
CPrintToChatAll("%t", "%s Player %N has joined the %s.", TAG_INFO, client, sTeam);
}
}
else CPrintToChatAll("%t", "%s Player %N has joined the %s.", TAG_INFO, client, sTeam);
}
}
}
public void OnPluginEnd()
{
if(CanTestFeatures())
{
if(GetFeatureStatus(FeatureType_Native, "VIP_ConnectTag") == FeatureStatus_Available)
VIP_UnregisterFeature(VIP_ConnectTag);
if(GetFeatureStatus(FeatureType_Native, "VIP_ConnectHideCountry") == FeatureStatus_Available)
VIP_UnregisterFeature(VIP_ConnectHideCountry);
}
}