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

timeleft_hostname (variable support)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GitS2125
Member
Join Date: Jun 2005
Location: Erligheim
Old 09-30-2007 , 17:41   timeleft_hostname (variable support)
Reply With Quote #1

Hi

this is not really my script but right now I try to learn Sourceawn...

Well basicly its the same script like the one Hell Phoenix wrote but I tryed to give it an variable support...

Example:
-Server.cfg
-- Hostname "My Dedicated Server [FF:ON, ... Timeleft: %time%]"

-Server browser
-- My Dedicated Server [FF:ON, ... Timeleft: 24:44]

the %time% var gets replaced by the real time thats left on the map.

Code:
#include <sourcemod>
#include <string>

#pragma semicolon 1

#define PLUGIN_VERSION "1.2"

new Handle:cvarTLHNfrequency;
new Handle:TLHNhandle;
new Handle:Hostname;
new String:oldHN[256];
new bool:getHN = false;

public Plugin:myinfo = 
{
	name = "Timeleft Hostname",
	author = "Hell Phoenix",
	description = "Timeleft Hostname",
	version = PLUGIN_VERSION,
	url = "http://www.charliemaurice.com/plugins/"
};

public OnPluginStart(){
	CreateConVar("sm_timeleft_hostname_version", PLUGIN_VERSION, "Timeleft Hostname Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	cvarTLHNfrequency = CreateConVar("sm_timeleft_hostname_frequency","2.0","How often in seconds to update the hostname with timeleft",FCVAR_PLUGIN);
	Hostname = FindConVar("hostname");

}

public OnMapStart(){
	TLHNhandle = CreateTimer(GetConVarFloat(cvarTLHNfrequency), Update_Hostname, INVALID_HANDLE, TIMER_REPEAT);
}

public Action:Update_Hostname(Handle:timer){
	
	if(getHN == false){
		GetConVarString(Hostname, oldHN, sizeof(oldHN));
		getHN = true;
	}
	new timeleft;
	GetMapTimeLeft(timeleft);
	if (timeleft <= 0)
		return Plugin_Handled;
	decl String:time[30];
	decl String:NewHN[256];


        Format(time, sizeof(time),"%i:%i",(timeleft / 60),(timeleft % 60));
        ReplaceString(oldHN, 256, "%time%", time);
        NewHN = oldHN;


	SetConVarString(Hostname, NewHN);
	return Plugin_Continue;
}

public OnMapEnd(){
  CloseHandle(TLHNhandle);
  SetConVarString(Hostname, oldHN);
}

public OnPluginEnd(){
  CloseHandle(TLHNhandle);
  SetConVarString(Hostname, oldHN);
}
Well as a "hard" coded version its perfect:
Code:
        decl String:string1[256];
        decl String:string2[256];
	string1 = "Hiddenbase.de - #1 [B4b / PS=Off / Bombs=limited / Weighted / Ranked / Timeleft";
	string2 = "] by g-portal.de";
        Format(NewHN, 256, "%s %d:%02d %s", string1, (timeleft / 60), (timeleft % 60), string2);
Thank you.

EDIT:
Well I solved it ... dont know why its working now but well see for yourself:
Code:
#include <sourcemod>
#include <string>

#pragma semicolon 1

#define PLUGIN_VERSION "1.2"

new Handle:cvarTLHNfrequency;
new Handle:TLHNhandle;
new Handle:Hostname;
new String:oldHN[256];
new String:realHN[256];
new bool:getHN = false;

public Plugin:myinfo = 
{
	name = "Timeleft Hostname",
	author = "Hell Phoenix",
	description = "Timeleft Hostname",
	version = PLUGIN_VERSION,
	url = "http://www.charliemaurice.com/plugins/"
};

public OnPluginStart(){
	CreateConVar("sm_timeleft_hostname_version", PLUGIN_VERSION, "Timeleft Hostname Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	cvarTLHNfrequency = CreateConVar("sm_timeleft_hostname_frequency","2.0","How often in seconds to update the hostname with timeleft",FCVAR_PLUGIN);
	Hostname = FindConVar("hostname");

}

public OnMapStart(){
	TLHNhandle = CreateTimer(GetConVarFloat(cvarTLHNfrequency), Update_Hostname, INVALID_HANDLE, TIMER_REPEAT);
}

public Action:Update_Hostname(Handle:timer){
	if(getHN == false){
		GetConVarString(Hostname, oldHN, sizeof(oldHN));
		realHN = oldHN;
		getHN = true;
	}
	new timeleft;
	GetMapTimeLeft(timeleft);
	if (timeleft <= 0)
		return Plugin_Handled;
	decl String:time[30];
	decl String:NewHN[256];

        Format(time, sizeof(time),"%i:%i",(timeleft / 60),(timeleft % 60));
        ReplaceString(oldHN, 256, "%time%", time);
        NewHN = oldHN;
        oldHN = realHN;


	SetConVarString(Hostname, NewHN);
	return Plugin_Continue;
}

public OnMapEnd(){
  CloseHandle(TLHNhandle);
  SetConVarString(Hostname, oldHN);
}

public OnPluginEnd(){
  CloseHandle(TLHNhandle);
  SetConVarString(Hostname, oldHN);
}
I thank pRED, BAILOPAN and the others who helped me with this little script.


cya GitS2125 aka Chanz

Last edited by GitS2125; 10-01-2007 at 02:26.
GitS2125 is offline
Reply



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 06:51.


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