I’m currently hosting two servers on a dedicated server. For a feature I require to retrieve the public IP and portnumber used for the server-instance the script is executed on.
I have tried the following:
local serverPort = GetConVarNumber("hostport"); -- always returns 27015
local serverIP = GetConVarString("ip"); -- always returns localhost
-- I've also tried the below:
local serverHostIP = GetConVarNumber("hostip"); -- this returns a negative number, I -did- try to use GetConVarString() instead with the same result
But in both instances it returns 27015, I guess that’s the value in the server.cfg. Though, when I launch the second instance of the server it says:
In the above situation I’d like to retrieve the value “27017”.
Also, as seen in the comment in my codesnippet, the ip can’t be found either.
I am confident there is -some- way to get these values, because typing “status” in the console displays me these values…!
Any ideas how this is achieved? I need this because I want the script to be dynamic.
I don’t think there are any functions to get the port you’re running from. It’s generally a good idea to set the hostport convar to the port you want to run, though, instead of just letting it auto assign to a different port, which can be done in the batch file you use to open the server.