rendered paste body--[[
Quick Day Night Script
~ Statement
]]
----------------
-- Time stuff --
----------------
function IncrTime( toIncr )
theTime[ 3 ] = theTime[ 3 ] + toIncr[ 3 ]
if ( theTime[ 3 ] >= 60 ) then theTime[ 2 ] = theTime[ 2 ] + 1 theTime[ 3 ] = 0 end
theTime[ 2 ] = theTime[ 2 ] + toIncr[ 2 ]
if ( theTime[ 2 ] >= 60 ) then theTime[ 1 ] = theTime[ 1 ] + 1 theTime[ 2 ] = 0 end
theTime[ 1 ] = theTime[ 1 ] + toIncr[ 1 ]
if ( theTime[ 1 ] > 24 ) then theTime[ 1 ] = 0 end
end
---------------
-- Day/Night --
---------------
local theTime = { 0, 0, 0 } -- hh:mm:ss
local nextIcr = CurTime( ) + 1
function DayNight( )
if ( nextIcr <= CurTime( ) ) then
nextIrc = CurTime( ) + 1
IncrTime( { 0, 1, 0 } )
DoLight( )
end
end
hook.Add( "Think", "DayNight", DayNight )
function DoLight( )
local EnvLight = ent.FindByClass( "light_environment" )
if ( #EnvLight > 0 ) then
local H = theTime[ 1 ]
local D
if ( H > 12 ) then H = 12 - ( H - 12 ) end
D = math.floor( H / 12 + ( 60 / theTime[ 2 ] ) )
local Light = math.floor( 255 * D / 100 )
local LightStr = table.concat( { Light, Light, Light }, " " )
EnvLight[ 1 ]:SetKeyValue( "_light", LightStr )
end
end