Using lua to load settings x.cfg on map x.bsp (or native function??)

Howdy folks, I’m running a srcds Garry’s Mod server with the the GMDM Redux gamemode, with a few nice maps. It is working fine. :smiley:

In my mapcycle I also have ‘dm_killbox_kbh_2’ from HL2:DM. This map requires me to set sv_gravity lower. I was wondering if the orangebox engine has a ‘load config on specific map’ function.
I’ve never seen it, so I guess there is no such thing.

So I’m trying to figure: would it be possible to make a lua script that checks onload (presuming the script gets run every time a new map starts) if there is a config file with the same name as the map, and parse those commands from the file.

Also: I still have a problem with the GMDM Redux scoreboard :frowning:

So, can I use native functions for this?
Does lua gets run every time a new map starts?
Would it be possible to run specific commands on each map?

You can use **[Game.GetMap

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Game.GetMap)** to get the map.
And a table something like:
[lua]

local MapCommands = {}

MapCommands[“dm_killbox_kbh_2”] = {“sv_gravity 200”,“some other command”}
MapCommands[“gm_flatgrass”] = {“sv_gravity 800”,“some other command2”}
//Etc…

local function OnInitialize()

 for _,v in pairs((MapCommands[game.GetMap()] or {}) do
      
      game.ConsoleCommand(v)
      
 end

end

[/lua]

Or something like that. Untested I wrote that in the REply Box.

Thanks commander204.
Seen one problem: you put two (( on the pairs function.

Now thats fixed, there is no single error to chew on. Not working either.

EDIT: maybe I’m using it wrong? Goes in \garrysmod\lua\autorun\server\autosettings.lua right? :pervert:

Did found some more info about the broken scoreboard.

] rcon gmdm_headshotmode 0
Server cvar ‘gmdm_headshotmode’ changed to 0
ConVarRef gmdm_headshotmode doesn’t point to an existing ConVar
SetConVar: No such cvar ( gmdm_headshotmode set to 0), skipping
Headshot mode disabled!

Ah right, sorry it is because it does not run, add a

hook.Add(“Initialize”,“CostumInitializeNo1”,OnInitialize)

right under it.

Thanks! Added [lua]hook.Add(“Initialize”, “CostumInitializeNo1”, OnInitialize)[/lua]

Works great. Except that srcds gives me “Error, bas server command sv_gravity 600”.
Is this because it runs before it tells me that VAC secure mode is activated? (fully started?)

Thanks in advance :ohdear:

game.ConsoleCommand requires a linebreak after the command.

So you’d change your command from “sv_gravity 600” to "sv_gravity 600
"

Oh, never knew that!

Yeah, it’s working now :slight_smile:

Any of you guys know whats wrongwith the GMDM scoreboard and the headshot roll?

The GMDM Redux score board uses a simple function to check what kind of game is running:

[lua]function GM:GetModeDescription()

local prefix = "";

if( gmdm_headshotmode:GetBool() ) then
	prefix = prefix .. "Headshots only "
end

if( GAMEMODE:IsTeamPlay() ) then
	prefix = prefix .. "Team ";
end

if( gmdm_soulcollector:GetBool() ) then
	if( gmdm_instagib:GetInt() > 0 ) then
		return prefix .. "Soul Collector Insta-gib";
	else
		return prefix .. "Soul Collector";
	end
elseif( gmdm_instagib:GetInt() > 1 ) then
	return prefix .. "Instagib"
elseif( gmdm_instagib:GetInt() == 1 ) then
	return prefix .. "One Shot, One Kill DM"
else
	return prefix .. "Deathmatch"
end

end[/lua]

But when you try to open the scoreboard, gmod keeps spewing errors.
[gmdm\gamemode\shared.lua:58] attempt to index global ‘gmdm_headshotmode’ (a nil value)

I checked some examples and saw something about the ‘tostring’. Not sure tough. :frowning:

Check where gmdm_headshotmode is defined, because it’s nil. It looks like a svar, so look for those.


\gmdm\gamemode\cvars.lua (2 hits)
	Line 20: 	elseif( name == "gmdm_headshotmode" ) then
	Line 106: 	gmdm_headshotmode = CreateGMDMConvar( "headshotmode", "0" ); -- only headshots count

[lua]elseif( name == "gmdm_headshotmode" ) then -- line 20 from cvars.lua
	if( tonumber( newval ) > 0 ) then
		GMDM_PrintCenterAll( "Headshot mode enabled!" );
	else
		GMDM_PrintCenterAll( "Headshot mode disabled!" );
	end[/lua]

[lua]function GM:DoConVars()
gmdm_headshotmode = CreateGMDMConvar( “headshotmode”, “0” ); – only headshots count //line 106 from cvars.lua
– moar stuff
end[/lua]

[editline]27th February 2011[/editline]

The headshot effect also gives errors:


[PM] Jeroenz0r suicided!
[gmdm\gamemode	eamplay.lua:54] attempt to index global 'gmdm_teamplay' (a nil value)
[PM] Jeroenz0r won the game.

teamplay.lua file: http://pastebin.com/qAv8Vc2K

Function with the error:
[lua]function GM:IsPlayerTeam( teamid )
if( gmdm_teamplay:GetBool() == true ) then
return ( teamid == TEAM_RED or teamid == TEAM_BLUE )
else
return ( teamid == TEAM_FREEFORALL )
end
end[/lua]

Where is CreateGMDMConvar defined? Show the whole function

Line 88 in cvars.lua.

[lua]function CreateGMDMConvar( var, value, prefix )

if( prefix == nil ) then
	prefix = "gmdm"
end

Msg( "[GMDM] Registered console variable " .. prefix .. "_" .. var .. " (SERVER: " .. tostring( SERVER ) .. ")

" );

cvars.AddChangeCallback( prefix .. "_" .. var, CvarCallback );

if( CLIENT ) then
	return GetConVar( prefix .. "_" .. var );
end

return CreateConVar( prefix .. "_" .. var, tostring( value ), FCVAR_NOTIFY + FCVAR_REPLICATED + FCVAR_ARCHIVE + FCVAR_GAMEDLL );

end[/lua]

Oh god. GMDM. Well looking at that function I think it would be better to try and get the Cvar on both the client and server - if nil create it. You can remove the FCVAR_GAMEDLL flag when it’s FCVAR_REPLICATED.

I have no idea what to remove or what to code.
tbh I can’t lua script for shit.