Change hostname via Lua RunConsoleCommand?

Hello, dear friends.
Today I had the very dumb problem.
Anyway, I don’t know why it’s don’t work.
For one moment it’s started to work for me but after server restart it’s stopeed and don’t work anymore…

So… What I’m talking about?

It’s very simple script which should change server’s name every XX seconds.



function hChange()
	RunConsoleCommand("hostname", table.Random(HCHANGER_HNAMES))
	timer.Simple(5, hChange)
timer.Simple( 5, hChange) 

This script placed in garrysmod/lua/autorun/server/hostname.lua.

Question: Why this simple sh*t don’t work and how to make it work?

The host name in the scoreboard does not update FYI.

Your code should work, but here’s some code I think you’d like better

local i = 1
function hChange()
i = i + 1
if i > #HCHANGER_HNAMES then
i = 1
RunConsoleCommand(“hostname”, HCHANGER_HNAMES[ i ])
timer.Simple(5, function()

This will change the hostname in order of the table, rather than a random hostname each time.

You should be using timer.Create instead of timer.Simple. It’s better suited for these sort of situations. Now you have this odd self referential timer function.

As I understand it, the server name in the search is not updated immediately.

Of course I know It xD

Thank you for better code.