Advertisement
SneakySquid

[GMod] Simple Screengrab

May 5th, 2024
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. local ScreenMat = CreateMaterial("ScreenMat", "Fillrate", {})
  2.  
  3. local function screengrab(open_menu)
  4.     file.CreateDir("screengrabs")
  5.  
  6.     hook.Add("PostRender", "Screengrab", function()
  7.         local frame_count = FrameNumber()
  8.  
  9.         render.UpdateScreenEffectTexture(1)
  10.         ScreenMat:SetTexture("$basetexture", render.GetScreenEffectTexture(1):GetName())
  11.  
  12.         cam.Start2D()
  13.             surface.SetMaterial(ScreenMat)
  14.             surface.SetDrawColor(255, 255, 255, 255)
  15.             surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
  16.  
  17.             surface.SetDrawColor(0, 255, 0, 255)
  18.             surface.DrawRect(0, 0, 10, 10)
  19.  
  20.             file.Write(string.format("screengrabs/%i.jpg", os.time()), render.Capture{
  21.                 format = "jpg",
  22.                 quality = 100,
  23.                 x = 0, y = 0,
  24.                 w = ScrW(), h = ScrH(),
  25.             })
  26.         cam.End2D()
  27.  
  28.         if frame_count ~= FrameNumber() then
  29.             while true do end
  30.         end
  31.  
  32.         if open_menu then
  33.             gui.ActivateGameUI()
  34.         end
  35.  
  36.         hook.Remove("PostRender", "Screengrab")
  37.     end)
  38. end
  39.  
  40. concommand.Add("screengrab", function()
  41.     local escape_menu = gui.IsGameUIVisible()
  42.  
  43.     if escape_menu then
  44.         gui.HideGameUI()
  45.     end
  46.  
  47.     screengrab(escape_menu)
  48. end)
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement