Map voting system, getting maps based on those set in info.txt?

I’m not sure if this is a very newbie question or not, sorry for wasting your time.
Anyways, I’m trying to create a map vote system for ZombieSurvival, since it tries to call a map voting function which doesn’t exist. I pulled the Gamemode/map voter from Fretta, (hope you don’t mind,) so at least I have something to start with. Now I want it to only list maps on the server starting with ones my gamemode supports, which can be set in the gamemode’s info.txt file. So does anyone know if it’s possible to read the support maps out of that file, then list only those maps? (And what would the code look like?)

Thanks in advance.

why not just create a table, then a function that adds it to the table, then call the function in your gamemode? thats how i would do i anyway :3

Thank you, but what do you mean by “it”? The list of map prefixes? I guess I could, but I would prefer that the gamemode would just get the list from it’s info.txt file, if possible.

Why not use **[File.Find

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=File.Find)**
and list all of the maps in your map folder with the ZombieSurvival map prefix?

'spose that would work too. So say I wanted to run a function that filtered out the maps I didn’t want, would I use a filter like “zm_.”?

string.find(filename, “^zm_”) would return true if the filename starts with “zm_”.

Ninjaed

Ah, so it is just like in the info.txt files, thank you. There are so many things that could go wrong here, with me trying to adapt a fretta voting system to a non-fretta gamemode, so this will be interesting for the first few times :wink:

And let me get something else straight here, after I run AddCSLuaFile(“vgui/vgui_mapvote.lua”) in the init.lua file, will I be able to later run


timer.Simple(INTERMISSION_TIME * 0.4, gmod.BroadcastLua, "PANEL:ChooseMap", "zombiesurvival")

In order to begin the voting? (The function looks like function PANEL:ChooseMap( gamemode ))

Why not just code your own system it wouldnt be too hard just use
**[Game.ConsoleCommand

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Game.ConsoleCommand)**
To change the map

[editline]05:58PM[/editline]

AddCSLuaFile is for client downloading file on join
**[G.include

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=G.include)**
Is so you can use functions you make in one lua file in another

So far I’m just stuck on the timer function, when it calls:


timer.Simple(INTERMISSION_TIME * 0.4, PANEL:ChooseMap, "zombiesurvival")

It usually complains about the second part, the PANEL:ChooseMap. That is the actual function in the vgui vote system, so what am I doing wrong?

PANEL.ChooseMap

[editline]06:26PM[/editline]


timer.Simple(INTERMISSION_TIME*0.4, PANEL.ChooseMap, PANEL, "zombiesurvival")

Ok, for whatever reason, I now get an error saying this: “Timer Error: ZombieSurvival\gamemode\sv_mapchangehandler.lua:27: attempt to index field ‘?’ (a nil value)”

This occurs in this area of code:



local g_PlayableGamemodes = {"ZombieSurvival"}


fretta_votesneeded = CreateConVar( "fretta_votesneeded", "0.7", { FCVAR_ARCHIVE } )
fretta_votetime = CreateConVar( "fretta_votetime", "20", { FCVAR_ARCHIVE } )
fretta_votegraceperiod = CreateConVar( "fretta_votegraceperiod", "30", { FCVAR_ARCHIVE } )

function GetRandomGamemodeMap( gm )

	return table.Random( g_PlayableGamemodes[ gm ].maps )
	
end

function GetNumberOfGamemodeMaps( gm )
	print("More debugging...")
	print("Number of children in g_PlayableGamemodes: "..#g_PlayableGamemodes)
	print("The last object's name is: "..tostring(g_PlayableGamemodes[#g_PlayableGamemodes]))
	return table.Count( g_PlayableGamemodes[gm].maps )
	
end

function setup() --This is the first function run in the entire file, it starts up necessary things for voting.
	print("Setup has been called, starting up!")
	local AllMaps = file.Find( "../maps/*.bsp" )
	for key, map in pairs( AllMaps ) do
		AllMaps[ key ] = string.gsub( map, ".bsp", "" )
	end
	gm = gmod.GetGamemode()
	print("The current gamemode.name is: "..tostring(GAMEMODE.Name))
	
	local info = file.Read( "../gamemodes/"..gm.Name.."/info.txt" )
	if ( info ) then
	
		local info = KeyValuesToTable( info )
		
		if ( info.selectable == 1 ) then
		
			g_PlayableGamemodes[ gm.Name ] = {}
			g_PlayableGamemodes[ gm.Name ].name = gm.Name
			g_PlayableGamemodes[ gm.Name ].label = info.name
			g_PlayableGamemodes[ gm.Name ].description = info.description
			g_PlayableGamemodes[ gm.Name ].author = info.author_name
			g_PlayableGamemodes[ gm.Name ].authorurl = info.author_url
			
			g_PlayableGamemodes[ gm.Name ].maps = {}


(The maps get filled later on, my main focus is at
return table.Count(g_PlayableGamemodes[gm].maps ).

I don’t really know why it’s nil. There should be something in it.