Stupid question, easy fix! *I hope*

I am not a coder by any means so don’t make fun. Anyone know why this isn’t working?

[lua]
hook.Add( “Think”, “I_hate_flatgrass”, function()
local maplist = file.Find(“maps/*.bsp”, “GAME”)
local map = table.Random( maplist )
if game.GetMap() == “gm_flatgrass” then
game.ConsoleCommand("changelevel " …map… “” )
end
end)
[/lua]

I get the error:
ERROR, bad server command changelevel “map blah”

game.ConsoleCommand( "changelevel " … map … "
" )

I had that before and I got this Error:

CModelLoader::Map_IsValid: No such map ‘maps/ttt_rooftops_a2.bsp.bsp’
changelevel failed: ttt_rooftops_a2.bsp not found

Why is that in a think hook? And what stops you from simply removing gm_flatgrass from the server directory?

I was doing it for two reasons:

One gmod is crashing 6 times a day lately and players are getting sick of playing the default starting map.

Two script enforcer is not enabled after a restart, you need to change the map to enable it at least last I knew.

Why is it in a think hook? You tell me a better place to put it, like I stated I am not a coder.

I’m kind of new to this too, but I believe that you’re looking for the GM:Initialize hook.

Thanks that will be much better! Also does anyone know why I am getting that error?

game.ConsoleCommand("changelevel " …string.gsub(map, “.bsp”, “”)… "
" )

Thanks Shadow I will give it a shot when I get home from work! I tried to use the string.gsub but I was too stupid to use it properly.

Once again you have saved my ass Shadow. <3

Change the default starting map?

It works great Shadow, thanks for the help! Once you fixed it, it was grabbing every map known to man for every game but I am pretty sure I filtered them out. I tried to hook it into the GM:Initialize like this but it didn’t work, any ideas?

[lua]
hook.Add( “Initialize”, “I_hate_flatgrass”, function()
local maptypes = { “cs_”, “de_”, “ttt_”, “dm_” }

if game.GetMap() == "gm_flatgrass" then

	for k, v in RandomPairs( file.Find( "maps/*.bsp", "GAME" ) ) do

		for _, Prefix in pairs( maptypes ) do

			if string.find( v, Prefix ) then
			if string.gsub( v, ".bsp", "" ) then

	game.ConsoleCommand("changelevel " ..string.gsub(v, ".bsp", "").. "

" )
end
end
end
end
end

end)
[/lua]