From anonymous, 1 Year ago, written in Lua.
Embed
  1. concommand.Add("listmissing", function(ply, com, arg)
  2.  
  3.         local map = arg[1] or game.GetMap()
  4.         local allmodels = {}
  5.         local materials = {}
  6.         local missing_mod = {}
  7.         local missing_mat = {}
  8.  
  9.         print("Checking models & materials on " .. map )
  10.        
  11.         -- read map file
  12.         local data = file.Read( "maps/" .. map .. ".bsp", "GAME")
  13.  
  14.         -- extract models
  15.         local models = data:gmatch("models/([A-Za-z0-9_/]+).mdl")
  16.         for w in models do
  17.                 local mdl = "models/" .. w .. ".mdl"
  18.                 allmodels[mdl] = true
  19.                 -- if not missing_mod[mdl] and not file.Exists( mdl , "GAME" ) then missing_mod[mdl] = true end
  20.         end
  21.        
  22.         -- extract textures    
  23.         local embed_mats = data:gmatch("maps/" .. map .. "/([A-Za-z0-9_%-/]+)")
  24.         local filter_mats = data:gmatch("([A-Z0-9%-_/\\]+)%z")
  25.         local decals = data:gmatch("\"texture\" \"([A-Za-z0-9%-_/\\]+)\"")
  26.  
  27.         data = nil -- gc?
  28.  
  29.         -- walk through all
  30.         for w in decals do
  31.                 if not w or w == "" or #w < 5 then continue end
  32.                 local mat = "materials/" .. tostring(w):lower() .. ".vmt"
  33.                 materials[ mat ] = true
  34.         end
  35.  
  36.         for w in filter_mats do
  37.                 if not w or w == "" or #w < 5 then continue end
  38.                 local mat = "materials/" .. tostring(w):lower() .. ".vmt"
  39.                 mat = string.Replace(mat, "_wvt_patch", "")
  40.                 materials[ mat ] = true
  41.         end
  42.  
  43.         for w in embed_mats do
  44.                
  45.                 if not w or w == "" or #w < 5 then continue end
  46.                 local mat = w
  47.                 mat = string.gsub(w, "%_(%-?[0-9]+_%-?[0-9]+_%-?[0-9]+)$", "") -- clean up names
  48.                 mat = string.Replace(mat, "_wvt_patch", "")
  49.                 mat = "materials/" .. tostring(mat):lower() .. ".vmt"
  50.                
  51.                 materials[ mat ] = true
  52.        
  53.         end
  54.  
  55.         print("Materials amount: " .. table.Count(materials) )
  56.         print("Materials missing amount: " .. table.Count(missing_mat) )
  57.         print("Models amount: " .. table.Count(allmodels) )
  58.         print("Models missing amount: " .. table.Count(missing_mod) )
  59.        
  60.         for k,v in SortedPairs(missing_mod) do
  61.                 MsgC( Color(255,128,0), "Model missing: " .. k )
  62.                 if k == "models/props_c17/hospital_bed01.mdl" then MsgC( Color(255,0,0), " (Half-Life 2: Episode 1)") end
  63.                 if k == "models/props_silo/camera.mdl" then MsgC( Color(255,0,0), " (Half-Life 2: Episode 2)") end
  64.                 MsgN("")
  65.         end
  66.        
  67.         for k,v in SortedPairs(missing_mat) do
  68.                 MsgC( Color(255,128,0), "Material missing: " .. k )
  69.                 MsgN("")
  70.         end
  71.  
  72.         print("File lists written to disk.")
  73.  
  74.         local mk = table.GetKeys(materials)
  75.         table.sort(mk)
  76.         file.Write("braxnetrp/" .. map .. "_materials.txt", string.Implode("\r\n", mk ) )
  77.  
  78.         local mk = table.GetKeys(allmodels)
  79.         table.sort(mk)
  80.         file.Write("braxnetrp/" .. map .. "_models.txt", string.Implode("\r\n", mk ) )
  81.  
  82. end)

Replies to Untitled rss

Title Name Language When
Re: Untitled anonymous lua 1 Year ago.