• Using lua to load settings x.cfg on map x.bsp (or native function??)
    13 replies, posted
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. :D 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 [url=http://www.facepunch.com/threads/931152-What-do-you-need-help-with-V1?p=28302247#post28302247]problem with the GMDM Redux scoreboard[/url] :( 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 [b][url=http://wiki.garrysmod.com/?title=Game.GetMap]Game.GetMap[img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] 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. [B]EDIT:[/B] maybe I'm using it wrong? Goes in [I]\garrysmod\lua\autorun\server\autosettings.lua[/I] right? :pervert: Did found some more info about the broken scoreboard. ] [B]rcon gmdm_headshotmode 0[/B] [B]Server cvar 'gmdm_headshotmode' changed to 0[/B] [I]ConVarRef gmdm_headshotmode doesn't point to an existing ConVar[/I] [I]SetConVar: No such cvar ( gmdm_headshotmode set to 0), skipping[/I] [B]Headshot mode disabled![/B]
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 [B]"Error, bas server command sv_gravity 600"[/B]. 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\n"
Oh, never knew that!
Yeah, it's working now :) 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. :(
Check where gmdm_headshotmode is defined, because it's nil. It looks like a svar, so look for those.
[code]\gmdm\gamemode\cvars.lua (2 hits) Line 20: elseif( name == "gmdm_headshotmode" ) then Line 106: gmdm_headshotmode = CreateGMDMConvar( "headshotmode", "0" ); -- only headshots count[/code] [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: [code][PM] Jeroenz0r suicided! [gmdm\gamemode\teamplay.lua:54] attempt to index global 'gmdm_teamplay' (a nil value) [PM] Jeroenz0r won the game.[/code] teamplay.lua file: [url]http://pastebin.com/qAv8Vc2K[/url] 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 ) .. ")\n" ); 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.
Sorry, you need to Log In to post a reply to this thread.