Advertisement
mattjeanes

Abyss Custom Sky v1

Jan 6th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. // Abyss custom sky stuff
  2. local skypaint
  3. local sun
  4.  
  5. hook.Add("InitPostEntity", "SkyPaint", function()
  6.     if SERVER then
  7.         RunConsoleCommand("sv_skyname", "painted")
  8.         local skypaints=ents.FindByClass("env_skypaint")
  9.         if #skypaints==0 then
  10.             skypaint = ents.Create("env_skypaint")
  11.             skypaint:Spawn()
  12.             skypaint:Activate()
  13.         elseif #skypaints >= 1 then
  14.             skypaint=skypaints[1]
  15.         end
  16.         local suns=ents.FindByClass("env_sun")
  17.         if #suns >= 1 then
  18.             sun=suns[1]
  19.         end
  20.     end
  21. end)
  22.  
  23. /*
  24. local function UpdateDusk(p)
  25.     print(p)
  26.     if p > 135 and p < 225 then
  27.         skypaint:SetDuskIntensity( p/36 )
  28.         print(p/36)
  29.     elseif p > 360 and p < 450 then
  30.         if p > 360 and p < 405 then
  31.             skypaint:SetDuskIntensity( p/81 )
  32.             print(p/81)
  33.         else
  34.             skypaint:SetDuskIntensity( p/81 )
  35.             print( p/81 )
  36.         end
  37.     else
  38.         skypaint:SetDuskIntensity( 0 )
  39.         print(0)
  40.     end
  41. end
  42. */
  43.  
  44. local function SetSunAngle(ang)
  45.     sun:SetKeyValue( "sun_dir", tostring( ang:Forward() ) )
  46.     //UpdateDusk(ang.p)
  47. end
  48.  
  49. local function SetSkyColor(top,bottom)
  50.     skypaint:SetTopColor( top )
  51.     skypaint:SetBottomColor( bottom )
  52. end
  53.    
  54. local function UpdateSky(time)
  55.     local day={}
  56.     day.top=Vector( 0.2, 0.5, 1.0 )
  57.     day.bottom=Vector( 0.8, 1.0, 1.0 )
  58.    
  59.     local night={}
  60.     night.top=Vector( 0, 0, 0 )
  61.     night.bottom=Vector( 0, 0, 0 )
  62.    
  63.     local lerptime=math.sqrt((100-(100/12)*time)^2)/100
  64.     local top=LerpVector(lerptime, day.top, night.top)
  65.     local bottom=LerpVector(lerptime, day.bottom, night.bottom)
  66.     SetSkyColor(top,bottom)
  67. end
  68.  
  69. local function UpdateSun(time)
  70.     SetSunAngle(Angle((time*15)+90,0,0))
  71. end
  72.  
  73. local function round(num, idp)
  74.     local mult = 10^(idp or 0)
  75.     return math.floor(num * mult + 0.5) / mult
  76. end
  77.  
  78. local function round(n, mult)
  79.     mult = mult or 1
  80.     return math.floor((n + mult/2)/mult) * mult
  81. end
  82.  
  83. local function UpdateLighting(time)
  84.     local L={"a","b","c","d","e","f","g","h","i","j","k","l"}
  85.     local n=round(-math.sqrt((11-(11/12)*time)^2)+12)
  86.     engine.LightStyle(0,L[n])
  87.     timer.Simple(0.5,function()
  88.         umsg.Start("UpdateLighting")
  89.         umsg.End()
  90.     end)
  91. end
  92.  
  93. usermessage.Hook("UpdateLighting",function()
  94.     render.RedownloadAllLightmaps()
  95. end)
  96.  
  97. if SERVER then
  98.     timer.Create("UpdateSky", 60, 0, function()
  99.         local time=os.date("%H")+(os.date("%M")*(1+(2/3))/100)
  100.         UpdateSky(time)
  101.         if IsValid(sun) then
  102.             UpdateSun(time)
  103.         end
  104.         UpdateLighting(time)
  105.     end)
  106. end
  107.  
  108. function UpdateSkyManual(time)
  109.     UpdateSky(time)
  110.     if IsValid(sun) then
  111.         UpdateSun(time)
  112.     end
  113.     UpdateLighting(time)
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement