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

[Help] Dynamic Hostname Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chanz
Veteran Member
Join Date: Aug 2008
Location: Germany - Stuttgart
Old 08-08-2008 , 20:34   [Help] Dynamic Hostname Plugin
Reply With Quote #1

Hi dudes

well I saw the plugin from Hell Phoenix the Timeleft Hostname Plugin.
now I took his script (I hope this is okey) and rewrite a bit of it.
but now I got no clue how to solve my problem.

This plugin should replace certain strings within the hostname as example:

Half-Life 2 Server nextmap:%nextmap%

the %nextmap% tag should be replaced by the sm_nextmap var.

right now it supports (or should support) %tl% for timeleft and %nm% which stands for nextmap.

Code:
/*
Dynamic Hostname
GitS2125 aka Chanz

Description:
  This plugin is a modification from Hell Phoenix's "Timeleft Hostname" plugin. With Dynamic Hostname 
  you can replace variables within your hostname such things like timeleft or friendlyfire...

Thanks To:
    Hell Phoenix for the orginal plugin
    and all @ #sourcemod. :P
    
Versions:
    1.0
        * First Public Release!

Cvars:
    sm_dh_frequency 2.0  - How often in seconds to update the hostname with variables.

*/


#include <sourcemod>
#include <string>

#pragma semicolon 1

#define PLUGIN_VERSION "1.0"

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

public Plugin:myinfo = 
{
    name = "Dynamic Hostname",
    author = "GitS2125",
    description = "Lets you replace variables within your hostname",
    version = PLUGIN_VERSION,
    url = "http://www.sourcemod.net/"
};

public OnPluginStart(){
    CreateConVar("sm_dh_version", PLUGIN_VERSION, "Dynamic Hostname Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    cvarTLHNfrequency = CreateConVar("sm_dh_frequency","5.0","How often in seconds to update the hostname with variables",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, realHN, sizeof(realHN));
        getHN = true;
    }
    newHN = realHN;

    //timeleft################
    new timeleft;
    decl String: time[30];
    GetMapTimeLeft(timeleft);

      
    Format(time, sizeof(time),"%d:%02d",(timeleft / 60),(timeleft % 60));

    //nextmap############
    decl String:nextmap[30];
    decl String:next[30];
    GetConVarString(FindConVar("sm_nextmap"), nextmap, sizeof(nextmap));
    Format(next, sizeof(next),"%s",nextmap);


    //replace################################

    ReplaceString(newHN, sizeof(newHN), "%tl%", time);
    ReplaceString(newHN, sizeof(newHN), "%nm%", next);

    SetConVarString(Hostname, newHN);
    return Plugin_Continue;
}

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

public OnPluginEnd(){
  CloseHandle(TLHNhandle);
  SetConVarString(Hostname, oldHN);
}
well please help me.

thank you

Chanz
Chanz is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 08-08-2008 , 20:51   Re: [Help] Dynamic Hostname Plugin
Reply With Quote #2

Code:
newHN = realHN;
You should use strcopy.

And I usually do:
Code:
ServerCommand("hostname %s", string);
I don't know if either of those will fix it (what's the exact problem with it?) but you should definitely use strcopy.
__________________
Greyscale is offline
Chanz
Veteran Member
Join Date: Aug 2008
Location: Germany - Stuttgart
Old 08-09-2008 , 06:32   Re: [Help] Dynamic Hostname Plugin
Reply With Quote #3

grrr

Thanks for help.

the problem was I tested my plugin with sourceforts and there is no normal map time limit, its round based time limit thats why it screwed up so much.

hmm now how can I find intern vars of a mod? like this round time?
and how do I read out those varas and edit them?


PS:the nextmap is already working.

thanks. ^^
Chanz 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 19:45.


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