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

Get the server name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zack771
Senior Member
Join Date: Apr 2012
Old 09-29-2013 , 12:23   Get the server name
Reply With Quote #1

Hello,

I wanted to know if there a way to know the name of the server on which the plugin is executed please ?
Zack771 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-29-2013 , 12:59   Re: Get the server name
Reply With Quote #2

You can get the name from the 'hostname' convar, here is a stock for it.
PHP Code:
GetHostName(String:str[], size)
{
    static 
Handle:hHostName;
    
    if(
hHostName == INVALID_HANDLE)
    {
        
// Oh noes :O
        
if( (hHostName FindConVar("hostname")) == INVALID_HANDLE)
        {
            return;
        }
    }
    
    
GetConVarString(hHostNamestrsize);

__________________

Last edited by Impact123; 09-29-2013 at 14:18.
Impact123 is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 09-29-2013 , 13:59   Re: Get the server name
Reply With Quote #3

I just started in sourcemod codding script and i don't understand you're code
PHP Code:
GetHostName(String:str[], size)
{
    static 
Handle:hHostName;
    
    if(
hHostName == INVALID_HANDLE)
    {
        
// Oh noes :O
        
if( (hHostName hHostNameFindConVar("hostname")) == INVALID_HANDLE)
        {
            return;
        }
    }
    
GetConVarString(hHostNamestrsize);

Why just don't you do :
PHP Code:
new hHostName Findconver("hostname");

GetConVarString(hHostnamestrsize); 
? ^^'
Zack771 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-29-2013 , 14:09   Re: Get the server name
Reply With Quote #4

You should cache the handle you get from FindConvar if you plan to use it more than once, this has performance reasons.
The other reason is that you should verify your data to avoid error logs and buggy code.
This was only meant as an example to show you how it's done, what exacly is it what you don't understand?.
__________________

Last edited by Impact123; 09-29-2013 at 14:14.
Impact123 is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 09-29-2013 , 14:14   Re: Get the server name
Reply With Quote #5

Ok thanks for explain. But in your code you have this :
PHP Code:
if( (hHostName hHostNameFindConVar("hostname")) == INVALID_HANDLE
        { 
            return; 
        } 
Why does you make
PHP Code:
hHostName hHostName 
?
Why not :
PHP Code:
if((hHostNameFindConVar("hostname")) == INVALID_HANDLE
        { 
            return; 
        } 
?
Zack771 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-29-2013 , 14:19   Re: Get the server name
Reply With Quote #6

Sorry if i confused you, i fixed my code above.
__________________

Last edited by Impact123; 09-29-2013 at 14:27.
Impact123 is offline
Zack771
Senior Member
Join Date: Apr 2012
Old 09-29-2013 , 14:28   Re: Get the server name
Reply With Quote #7

Ok, i test that code. Thanks a lot for help =D
Zack771 is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 09-29-2013 , 14:38   Re: Get the server name
Reply With Quote #8

You do understand FindConVar("hostname")) == INVALID_HANDLE returns a boolean?
Caching convar handle OnPluginStart will do just fine.
xf117 is offline
Send a message via ICQ to xf117
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-29-2013 , 15:09   Re: Get the server name
Reply With Quote #9

No, i think it's called a nested assignment, you can try for yourself what such a statement returns.
__________________

Last edited by Impact123; 09-29-2013 at 15:10.
Impact123 is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 09-29-2013 , 15:23   Re: Get the server name
Reply With Quote #10

Omg sorry about that. I completely missed the parentheses. My bad.
xf117 is offline
Send a message via ICQ to xf117
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 08:46.


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