Guest User

GLua Sky & Sun Editor

a guest
Feb 21st, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. local config = {
  2.     enabled = true,
  3.    
  4.     ["gm_construct_flatgrass_v6-2"] = {
  5.         enabled = true,
  6.         sun = {
  7.             ["sun_dir"]      = Vector(0.81231, -0.58252, 0.02858),
  8.             ["sunsize"]      = 33,
  9.             ["overlaysize"]  = 0,
  10.             ["suncolor"]     = Color(249, 224, 196),
  11.             ["overlaycolor"] = Color(255, 221, 163),
  12.         },
  13.         sky = {
  14.             ["topcolor"]    = Color(0, 7, 15),
  15.             ["bottomcolor"] = Color(94, 66, 153),
  16.             ["fadebias"]    = 0.25,
  17.             ["hdrscale"]    = 0.66,
  18.            
  19.             ["drawstars"]   = true,
  20.             ["startexture"] = "skybox/starfield",
  21.             ["starlayers"]  = 1,
  22.             ["starscale"]   = 1.03,
  23.             ["starfade"]    = 0.65,
  24.             ["starspeed"]   = 0.01,
  25.            
  26.             ["duskintensity"] = 1.44,
  27.             ["duskscale"]     = 0.84,
  28.             ["duskcolor"]     = Color(255, 40, 0),
  29.            
  30.             ["sunsize"]  = 0.37,
  31.             ["suncolor"] = Color(255, 119, 0),
  32.            
  33.         }
  34.     },
  35.    
  36.     ["gm_flatgrass"] = {
  37.         enabled = true,
  38.         sun = {
  39.             ["sun_dir"]      = Vector(-0.938096, -0.343581, 0.043908),
  40.             ["sunsize"]      = 33,
  41.             ["overlaysize"]  = 0,
  42.             ["suncolor"]     = Color(249, 224, 196),
  43.             ["overlaycolor"] = Color(255, 221, 163),
  44.         },
  45.         sky = {
  46.             ["topcolor"]    = Color(0, 7, 15),
  47.             ["bottomcolor"] = Color(94, 66, 153),
  48.             ["fadebias"]    = 0.25,
  49.             ["hdrscale"]    = 0.66,
  50.            
  51.             ["drawstars"]   = true,
  52.             ["startexture"] = "skybox/starfield",
  53.             ["starlayers"]  = 1,
  54.             ["starscale"]   = 1.03,
  55.             ["starfade"]    = 0.65,
  56.             ["starspeed"]   = 0.01,
  57.            
  58.             ["duskintensity"] = 1.44,
  59.             ["duskscale"]     = 0.84,
  60.             ["duskcolor"]     = Color(255, 40, 0),
  61.            
  62.             ["sunsize"]  = 0.37,
  63.             ["suncolor"] = Color(255, 119, 0),
  64.            
  65.         }
  66.     }
  67. }
  68.  
  69.  
  70. local sun, sky
  71. local map
  72.  
  73.  
  74. local function setKeys(ent, name)
  75.     if not IsValid(ent) then
  76.         print("Custom Sky: Error customizing - entity not valid")
  77.         return
  78.     end
  79.    
  80.     print("Custom Sky: Editing "..name)
  81.     for k, v in pairs(config[map][name]) do
  82.        
  83.         local t = type(v)
  84.         local val
  85.        
  86.         if t == "number"then
  87.             val = tostring(v)
  88.         elseif t == "boolean" then
  89.             val = (v == true and "1" or "0")
  90.         elseif t == "Vector" then
  91.             val = Format("%f %f %f", v.x, v.y, v.z)
  92.         elseif t == "table" then
  93.             val = Format("%f %f %f", v.r/255, v.g/255, v.b/255)
  94.         else
  95.             val = v
  96.         end
  97.        
  98.         ent:SetKeyValue(k, val)
  99.        
  100.     end
  101.    
  102. end
  103.  
  104. local function findFirst(name)
  105.     local findList = ents.FindByClass(name)
  106.     if(#findList > 0) then
  107.         return findList[1]
  108.     end
  109. end
  110.  
  111. local function init()
  112.     if not config.enabled then return end
  113.    
  114.     sun = findFirst("env_sun")
  115.     sky = findFirst("env_skypaint")
  116.     map = game.GetMap()
  117.    
  118.     local cfg = config[map]
  119.     if cfg then
  120.         if not cfg.enabled then return end
  121.        
  122.         if cfg.sun then
  123.             setKeys(sun, "sun")
  124.         end
  125.        
  126.         if cfg.sky then
  127.             setKeys(sky, "sky")
  128.         end
  129.     else
  130.         --print("Custom Sky: Config not set for "..map)
  131.     end
  132. end
  133.  
  134. init()
  135. hook.Add("Initialize", "psb_customsky", function()
  136.     timer.Simple(1, function()
  137.         init()
  138.     end)
  139. end)
Advertisement
Add Comment
Please, Sign In to add comment