Raised This Month: $12 Target: $400
 3% 

Cvar plus a timer problem [Solved]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HelpMe
Senior Member
Join Date: Jun 2013
Location: Home
Old 08-24-2013 , 09:59   Cvar plus a timer problem [Solved]
Reply With Quote #1

Hello! I'm pretty new to this scripting anyways I learned how to make a command there printed server IP
Then I wanted to make a timer with a cvar that triggered the Action but I can't manage to do it more than one time. so I request some help with this, if it is possible. Code is down below.

Code:
#include <sourcemod>
#include <morecolors>
#include <steamtools>

new Handle:h_Enabled = INVALID_HANDLE;
new Handle:h_Timer = 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()
{
	new IsTimer = GetConVarInt(h_Timer);
	CreateTimer((IsTimer) * 1.0, TimerCallBack, TIMER_REPEAT);
}

public Action:TimerCallBack(Handle:timer, any:client)
{
	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}=========================");
	}
}

public Action:ServerIP(client, args)
{
		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;
}

Last edited by HelpMe; 09-13-2013 at 07:48.
HelpMe is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-24-2013 , 10:14   Re: Cvar plus a timer problem
Reply With Quote #2

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_PLUGINtrue0.0true1.0);
    
h_Timer CreateConVar("sm_timer""30""The time before trigger."FCVAR_PLUGINtrue30.0true600.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:timerany: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(clientargs)
{
    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;

__________________

Last edited by thetwistedpanda; 08-24-2013 at 10:17.
thetwistedpanda is offline
HelpMe
Senior Member
Join Date: Jun 2013
Location: Home
Old 08-24-2013 , 10:45   Re: Cvar plus a timer problem
Reply With Quote #3

Quote:
Originally Posted by thetwistedpanda View Post
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_PLUGINtrue0.0true1.0);
    
h_Timer CreateConVar("sm_timer""30""The time before trigger."FCVAR_PLUGINtrue30.0true600.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:timerany: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(clientargs)
{
    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;

Thanks man
HelpMe is offline
HelpMe
Senior Member
Join Date: Jun 2013
Location: Home
Old 08-24-2013 , 11:18   Re: Cvar plus a timer problem
Reply With Quote #4

Quote:
Originally Posted by thetwistedpanda View Post
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_PLUGINtrue0.0true1.0);
    
h_Timer CreateConVar("sm_timer""30""The time before trigger."FCVAR_PLUGINtrue30.0true600.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:timerany: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(clientargs)
{
    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;

Now I get this error :
Quote:
L 08/24/2013 - 17:17:45: [SM] Plugin encountered error 25: Call was aborted
L 08/24/2013 - 17:17:45: [SM] Native "ThrowError" reported: Invalid client index 0
L 08/24/2013 - 17:17:45: [SM] Displaying call stack trace for plugin "IP.smx":
L 08/24/2013 - 17:17:45: [SM] [0] Line 39, C:\tf2server\tf\addons\sourcemod\scripting\in clude\morecolors.inc::CPrintToChat()
L 08/24/2013 - 17:17:45: [SM] [1] Line 43, C:\tf2server\tf\addons\sourcemod\scripting\IP .sp::TimerCallBack()

Last edited by HelpMe; 08-24-2013 at 11:19.
HelpMe is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-24-2013 , 12:14   Re: Cvar plus a timer problem
Reply With Quote #5

Change CPrintToChat to CReplyToCommand.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
HelpMe
Senior Member
Join Date: Jun 2013
Location: Home
Old 08-24-2013 , 12:39   Re: Cvar plus a timer problem
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
Change CPrintToChat to CReplyToCommand.
That fixed the errors thank you

But now it doesn't doesn't print it to the chat at all only the server console :I

Last edited by HelpMe; 08-24-2013 at 15:02.
HelpMe is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-24-2013 , 15:07   Re: Cvar plus a timer problem
Reply With Quote #7

Quote:
Originally Posted by HelpMe View Post
That fixed the errors thank you

But now it doesn't doesn't print it to the chat at all only the server console :I
Oh, did you want it to print to everyone? In that case, use CPrintToChatAll and remove the client argument.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
HelpMe
Senior Member
Join Date: Jun 2013
Location: Home
Old 08-24-2013 , 16:14   Re: Cvar plus a timer problem
Reply With Quote #8

Quote:
Originally Posted by Powerlord View Post
Oh, did you want it to print to everyone? In that case, use CPrintToChatAll and remove the client argument.
Thanks now it workz as I wanted.

Thanks to both of you I am very grateful for the help so just thanks
HelpMe is offline
HelpMe
Senior Member
Join Date: Jun 2013
Location: Home
Old 08-25-2013 , 03:22   Re: Cvar plus a timer problem
Reply With Quote #9

Only problem now is that in the first my when the server start up it just print random times :I
but it doesn't matter that much
HelpMe is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode