Hi
this is not really my script but right now I try to learn Source
awn...
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