Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -----------------------------------------------------------
- ----------------Dr. Matt's Simple Day/Night ---------------
- -----------------------------------------------------------
- */
- local skypaint
- local sun
- hook.Add("InitPostEntity", "Abyss-SkyPaint", function()
- if SERVER then
- RunConsoleCommand("sv_skyname", "painted")
- local skypaints=ents.FindByClass("env_skypaint")
- if #skypaints==0 then
- skypaint = ents.Create("env_skypaint")
- skypaint:Spawn()
- skypaint:Activate()
- elseif #skypaints >= 1 then
- skypaint=skypaints[1]
- end
- local suns=ents.FindByClass("env_sun")
- if #suns >= 1 then
- sun=suns[1]
- end
- end
- end)
- local function NoFog()
- render.FogMode( 1 )
- render.FogStart( 0 )
- render.FogEnd( 0 )
- render.FogMaxDensity( 0 )
- render.FogColor( 255, 255, 255 )
- return true
- end
- hook.Add( "SetupWorldFog", "Abyss-SkyPaint", NoFog )
- hook.Add( "SetupSkyboxFog", "Abyss-SkyPaint", NoFog )
- local function UpdateDusk(p)
- if p > 160 and p < 200 then
- skypaint:SetDuskIntensity( math.sqrt(((5/-20)*(p-160)+5)^2)*-1+5 )
- elseif p > 340 and p < 380 then
- skypaint:SetDuskIntensity( math.sqrt(((5/-20)*(p-340)+5)^2)*-1+5 )
- else
- skypaint:SetDuskIntensity( 0 )
- end
- end
- local function SetSunAngle(ang)
- sun:SetKeyValue( "sun_dir", tostring( ang:Forward() ) )
- UpdateDusk(ang.p)
- end
- local function SetSkyColor(top,bottom)
- skypaint:SetTopColor( top )
- skypaint:SetBottomColor( bottom )
- end
- local function UpdateSky(h,m)
- local dawn={}
- dawn.top=Vector(0.46, 0.47, 0.32)
- dawn.bottom=Vector(0.10, 0.26, 0.31)
- local day={}
- day.top=Vector( 0.2, 0.5, 1.0 )
- day.bottom=Vector( 0.8, 1.0, 1.0 )
- local dusk={}
- dusk.top=Vector(0.05, 0.05, 0.05)
- dusk.bottom=Vector(0.23, 0.15, 0.08)
- local night={}
- night.top=Vector( 0, 0, 0 )
- night.bottom=Vector( 0, 0, 0 )
- local skys={night,night,night,night,night,dawn,dawn,day,day,day,day,day,day,day,day,day,day,dusk,dusk,night,night,night,night}
- skys[0]=night
- local currentsky=skys[h]
- local nextsky=skys[h+1]
- if h==23 then nextsky=skys[0] end
- local lerptime=m*(1+(2/3))/100
- local top=LerpVector(lerptime, currentsky.top, nextsky.top)
- local bottom=LerpVector(lerptime, currentsky.bottom, nextsky.bottom)
- SetSkyColor(top,bottom)
- end
- local function UpdateSun(time)
- SetSunAngle(Angle((time*15)+90,0,0))
- end
- local function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- local function UpdateLighting(h)
- local L={"b","b","b","b","d","f","h","j","l","l","l","l","l","l","l","j","h","f","d","b","b","b","b"}
- L[0]="b"
- engine.LightStyle(0,L[h])
- timer.Simple(0.5,function()
- umsg.Start("UpdateLighting")
- umsg.End()
- end)
- end
- usermessage.Hook("UpdateLighting",function()
- render.RedownloadAllLightmaps()
- end)
- if SERVER then
- timer.Create("UpdateSky", 60, 0, function()
- local h=tonumber(os.date("%H"))
- local m=tonumber(os.date("%M"))
- local t=h+(os.date("%M")*(1+(2/3))/100)
- UpdateSky(h,m)
- if IsValid(sun) then
- UpdateSun(t)
- end
- UpdateLighting(h)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement