Most effecient way of generating a table of allowed maps from a filter?
0 replies, posted
I bet that was confusing. Here's a better explanation:
I'm making a map vote system. First, I want to generate a table of allowed maps, from a set table of prefixes. Here's what I have so far:
[code]
local allowedmaps = {"^zs_", "^cs_", "^de_", "^zm_", "^zh_"}
availmaps = {}
function init()
print("Filling availmaps table...")
local maps = file.Find( "../maps/*.bsp" )
print("Found a total of "..#maps.." maps in the maps folder.")
for _, map in ipairs( maps ) do
map = map:sub( 1, -5 ) -- Take off .bsp
--if allowedmaps[ map ] then
if string.find(map, allowedmaps) then
table.insert( availmaps, map )
print("Found available map named "..map..".")
end
end
print("Found "..#availmaps.." available maps!")
table.sort(availmaps)
end
hook.Add("InitPostEntity", "MapStartTrigger", init)
[/code]
So far, it doesn't work. Is there any quick way to have string.find automatically check the allowed maps table against the map string, or do I have to do another for function?
Sorry, you need to Log In to post a reply to this thread.