From 17bab2b11ac100e1fb059f8591d3b93485a61d25 Mon Sep 17 00:00:00 2001 From: DoganGFL Date: Wed, 8 Aug 2018 01:21:12 +0200 Subject: [PATCH] add plugin: playerscount hostname --- .../scripting/Playerscount_In_Hostname.sp | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Playerscount_In_Hostname/scripting/Playerscount_In_Hostname.sp diff --git a/Playerscount_In_Hostname/scripting/Playerscount_In_Hostname.sp b/Playerscount_In_Hostname/scripting/Playerscount_In_Hostname.sp new file mode 100644 index 00000000..7bb52cb4 --- /dev/null +++ b/Playerscount_In_Hostname/scripting/Playerscount_In_Hostname.sp @@ -0,0 +1,61 @@ +#include +#pragma semicolon 1 + +public Plugin:myinfo = +{ + name = "Players count in hostname", + author = "D1maxa", + description = "Showing number of players in name of server", + version = "1.11", + url = "http://forums.alliedmods.net/showthread.php?t=126060" +}; + +new g_NumClients=0; +new Handle:hostname = INVALID_HANDLE; +new Handle:sv_visiblemaxplayers = INVALID_HANDLE; +new Handle:formatted_hostname = INVALID_HANDLE; + +public OnPluginStart() +{ + hostname = FindConVar("hostname"); + sv_visiblemaxplayers = FindConVar("sv_visiblemaxplayers"); + formatted_hostname=CreateConVar("sm_formatted_hostname", "My Server %d/%d", "Formatted string for dynamic hostname",FCVAR_PLUGIN); +} + +public OnMapStart() +{ + g_NumClients=0; +} + + public OnConfigsExecuted() +{ + SetNumberOfPlayersInHostname(); +} + +public OnClientConnected(client) +{ + if(!IsFakeClient(client)) + { + g_NumClients++; + SetNumberOfPlayersInHostname(); + } +} + +public OnClientDisconnect(client) +{ + if(!IsFakeClient(client)) + { + g_NumClients--; + SetNumberOfPlayersInHostname(); + } +} + +SetNumberOfPlayersInHostname() +{ + decl String:my_buf[64]; + decl String:f_hostname[64]; + GetConVarString(formatted_hostname,f_hostname,sizeof(f_hostname)); + Format(my_buf,sizeof(my_buf),f_hostname,g_NumClients,GetConVarInt(sv_visiblemaxplayers)); + SetConVarString(hostname,my_buf); + ServerCommand("heartbeat"); +}