PHP Code:
#include <sourcemod>
#include <morecolors>
#include <steamtools>
new Handle:h_Enabled = INVALID_HANDLE;
new Handle:h_Timer = INVALID_HANDLE;
new Handle:h_Repeat = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "ServerIP",
author = "Benjamin",
description = "Prints server ip to chat when typing sm_ip",
version = "1.5",
url = "http://steamcommunity.com/id/BenjaminHT/"
}
public OnPluginStart()
{
RegConsoleCmd("sm_ip", ServerIP);
h_Enabled = CreateConVar("sm_timerenable", "1", "Enable chat messages with server ip. 1 = enabled.", FCVAR_PLUGIN, true, 0.0, true, 1.0);
h_Timer = CreateConVar("sm_timer", "30", "The time before trigger.", FCVAR_PLUGIN, true, 30.0, true, 600.0);
AutoExecConfig(true, "ServerIP.cfg");
}
public OnMapStart()
{
if(GetConVarInt(h_Enabled))
h_Repeat = CreateTimer(GetConVarFloat(h_Timer), TimerCallBack, _, TIMER_REPEAT);
}
public OnMapEnd()
{
if(h_Repeat != INVALID_HANDLE && CloseHandle(h_Repeat))
h_Repeat = INVALID_HANDLE;
}
public Action:TimerCallBack(Handle:timer, any:client)
{
new soos = GetConVarInt(FindConVar("hostport"));
new octets[4];
Steam_GetPublicIP(octets);
CPrintToChat(client, "{green}=========================");
CPrintToChat(client, "{default}Server IP is: {green}%d.%d.%d.%d:%d", octets[0], octets[1], octets[2], octets[3], soos);
CPrintToChat(client, "{green}=========================");
}
public Action:ServerIP(client, args)
{
new IsEnabled = GetConVarInt(h_Enabled);
if(IsEnabled == 1)
{
new soos = GetConVarInt(FindConVar("hostport"));
new octets[4];
Steam_GetPublicIP(octets);
CPrintToChat(client, "{green}=========================");
CPrintToChat(client, "{default}Server IP is: {green}%d.%d.%d.%d:%d", octets[0], octets[1], octets[2], octets[3], soos);
CPrintToChat(client, "{green}=========================");
}
return Plugin_Handled;
}