• Is it possible to turn the result of a console command into a string?
    4 replies, posted
For an addon I am making, I am trying to get info from the 'status' command that isn't otherwise accessible by a function or a GetConVarString. How can I turn the result of the command into a string?
First you need a c module. [editline]19th July 2015[/editline] Surely there are better ways to get "status" info than using the status command and ripping the output.
[QUOTE=BFG9000;48248003]First you need a c module. [editline]19th July 2015[/editline] Surely there are better ways to get "status" info than using the status command and ripping the output.[/QUOTE] Turns out there isn't. I am just trying to get the server host IP and Port. Which GetConVarString("hostip") and GetConVarString("hostport") dont do very well for some reason.
[lua]function game.GetIP() local hostip = GetConVarString( "hostip" ) -- GetConVarNumber is inaccurate hostip = tonumber( hostip ) local ip = {} ip[ 1 ] = bit.rshift( bit.band( hostip, 0xFF000000 ), 24 ) ip[ 2 ] = bit.rshift( bit.band( hostip, 0x00FF0000 ), 16 ) ip[ 3 ] = bit.rshift( bit.band( hostip, 0x0000FF00 ), 8 ) ip[ 4 ] = bit.band( hostip, 0x000000FF ) return table.concat( ip, "." ) end[/lua] Use that there to get a server IP. GetConVarString( "hostport" ) Works fine.
[QUOTE=AIX-Who;48248482][lua]function game.GetIP() local hostip = GetConVarString( "hostip" ) -- GetConVarNumber is inaccurate hostip = tonumber( hostip ) local ip = {} ip[ 1 ] = bit.rshift( bit.band( hostip, 0xFF000000 ), 24 ) ip[ 2 ] = bit.rshift( bit.band( hostip, 0x00FF0000 ), 16 ) ip[ 3 ] = bit.rshift( bit.band( hostip, 0x0000FF00 ), 8 ) ip[ 4 ] = bit.band( hostip, 0x000000FF ) return table.concat( ip, "." ) end[/lua] Use that there to get a server IP. GetConVarString( "hostport" ) Works fine.[/QUOTE] I tried using the GetConVarString("hostport") but on some servers I tested it on reported they it just brought back '27015' when the port was something else (yet sometimes it DOES give the custom port, weird).
Sorry, you need to Log In to post a reply to this thread.