ID:2296459
 
(See the best response by Ter13.)
Code:
var/global
list/holder=list("Time"=new/obj/Time)

proc
GrabHolder(wh as text)//grabs something out of the holder associated list by name.
if(holder.Find(wh))
return holder[wh]
else
return null

mob/combative/player
Login()
..()
var/obj/Time/T=GrabHolder("Time")
if(!isnull(T))
T.Apply(src)

obj/Time
New()
spawn(5)
DayCycle()
..()
icon = 'DayNNite.dmi'
icon_state = "still"
mouse_opacity = 0
screen_loc = "SOUTHWEST to NORTHEAST"
//
alpha = 50
plane = 1
//
var
rev = 0
cTOD = "morning"//time of the day
list/TOD = list("morning","midmorning","noon",
"afternoon","dusk","sunset","nightfall","night")//time of day goes here, should match the name of your icon states.
chg_wait = 50 //3000//5 mins per change.
proc
Apply(mob/m)
if(!isnull(m.client))
m.client.screen+=src

DayColor(wh)//simply changes the color of the day based on the time of the day.
switch(wh)
if("midmorning")
return rgb(255,255,204,46)
if("morning")
return rgb(255,255,204,46)
if("noon")
return rgb(255,255,204,0)
if("afternoon")
return rgb(255,255,204,0)
if("sunset")
return rgb(255,153,0,60)
if("nightfall")
return rgb(0,0,102,102)
if("night")
return rgb(0,0,102,160)
if("dusk")
return rgb(0,153,153,46)//you can play with these for various effects.

DayCycle()
if(!rev)
rev=1
var/r=TOD.Find(cTOD)
if(r==TOD.len)
r=1
else
r=min(TOD.len,r+1)
animate(src,color=DayColor(TOD[r]),time=round(chg_wait/3))
cTOD=TOD[r]
spawn(chg_wait)
rev=0
.()
//light stuff
mob/combative/player
verb
Light_Size(n as num) //change size of the light
if(!light) return
var/matrix/m = matrix()
m.Scale(n)
light.transform = m

Light_alpha(n as num) //change alpha of the light
if(light) light.alpha = n

obj
light
plane = 1
icon = 'light.dmi'
icon_state = "circle"
mouse_opacity = 0

mob/combative/player
var
obj/light/light
Login()
..()
light = new(src.loc)
light.alpha = 150

Move()
..()
if(light) light.loc = src.loc


What I'm trying to do is make a daytime/night time system on a 60 minute cycle. This part of the system works perfectly as I want it to. The issue I'm having is making a flash light or lamp function. As it gets darker outside, I want players to be able to use a lamp to light up the area around them. The light shows up, but it doesn't glow the way I want it to. This is all uncharted territory for me, so if there are obvious and stupid mistakes, I apologize. What I currently have is: the night time system works perfectly, but the lamp does not light up the area around them. It instead forms a white circle that doesn't do what I'm trying to do.

The light currently: https://gyazo.com/c3c45ca8a417c68914d4c6cefae943a3

As you can see, it not only does not light up the area and glow, it gets dimmer as it gets darker outside. I understand there's some sort of blending I can do, but I have absolutely no idea where to go from here. Would anyone be able to help me fix this and explain to me what I'm doing wrong?

Not related to your issue, but do not use a screen_loc of southwest to northeast. That creates lots of tiles and degrades performance. Use CENTER instead, and transform the icon with a large scale.
Yeah I can do that. Do you have any ideas on my problem with the light?
Best response
You want to create a full-screen blackness layer on its own plane, and set it as a PLANE_MASTER object. This will use BLEND_MULTIPLY as a blend_mode.

Then you want to create the light objects as white-to-black radial gradient. Black on the outside, white at the center. Set BLEND_ADD as a blend_mode.

Set their plane to be the same as the master blackness plane.


All objects on the same plane as the master plane object will be drawn in a single pass as though they were all part of the same object, and then the plane_master will be drawn from an offscreen texture into the screen.

You can change the global illumination by changing the alpha of the darkness plane. You can then use client.color as a global lighting tint, and you can also tint the individual lights using their atom color variables.

Login to reply.