ID:148420
 
This ISNT working because of.....

proc
Night()
for(var/turf/T in world)//for all turfs
if(T.icon_state == "night")//if its night turf
T.icon_state = ""//make them day
else//if its day
T.icon_state = "night"//make the icons night
for(var/obj/O in world)//for all obj

if(O.icon_state == "night")//if its a night icon
O.icon_state = ""//make them day
else//if its day
O.icon_state = "night"//make the icons night
for(var/area/A in world)//for all area
if(A.roof2 == 1)
if(A.roof == 1)
A.roof = 0
else
A.roof = 1
else

if(A.icon_state == "night")//if its a night icon
A.icon_state = ""//make them day
else//if its day
A.icon_state = "night"//make the icons night


spawn(1200)//20 min
Night()//again
world
New()// at the creation of the world
..()
spawn(1)// call it after a few seconds
Night()//calls the night proc



something below here, can anyone help me out?


area
var/image_icon
ceiling
roof2 = 1
Entered(mob/M)
for (var/area/A in world)
if (istype(A, /area/ceiling))
return
M << A.image_icon
M.client.images -= image_icon
..()
Exited(mob/M)
for (var/area/A in world)
if (istype(A, /area/ceiling))
return
M.client.images -= A.image_icon
M << image_icon
..()
entrance

world
New()
for (var/area/A in world)
if (istype(A, /area/ceiling))
if(A.roof == 0)
A.image_icon = image('nroof.dmi', A, "ceiling")
else
A.image_icon = image('roof.dmi', A, "ceiling")
else

A.image_icon = image('roof.dmi', A, "blackness")


mob = /mob

mob
Login()
if(!src.client)
else
for (var/area/ceiling/C in world)
src << C.image_icon
..()

area/entrance


area
var
roof
roof2
Erdrickthegreat2 wrote:
This ISNT working because of.....

What is it doing wrong? It's hard to troubleshoot when I don't know what to look for.

One thing I would recommend is changing the loop structure in the Night proc. You are looping through the world contents 3 times, when you could just do it once. Even though all three loops have different filters (turf/T , obj/O, and area/A), internally BYOND goes through all the world contents for each loop and only passes atoms that fit your filter.
proc
Night()
for(var/atom/A in world) // check all atoms
if(ismob(A)) continue // don't do anything to mobs
if(A.icon_state == "night")//if its night turf
A.icon_state = ""//make them day
else//if its day
A.icon_state = "night"//make the icons night
if(isarea(A)) // if it's an area
var/area/Area = A
if(Area.roof2) // if roof2 is not 0
Area.roof = !Area.roof // toggle between 1 and 0

spawn(1200)//20 min
Night()//again

In a large world, even one world.contents loop can hog computer resources, resulting in terrible lag. You may want to consider alternatives.
In response to Shadowdarke
any Idea for a way to change all my icons to night?
This ISNT working, maening for somereason when the roof bit is removed the Night proc works fine, but when i added the roof snippet the icons didnt change...
proc
Night()
for(var/turf/T in world)//for all turfs
if(T.icon_state == "night")//if its night turf
T.icon_state = ""//make them day
else//if its day
T.icon_state = "night"//make the icons night
for(var/obj/O in world)//for all obj

if(O.icon_state == "night")//if its a night icon
O.icon_state = ""//make them day
else//if its day
O.icon_state = "night"//make the icons night
for(var/area/A in world)//for all area
if(A.roof2 == 1)
if(A.roof == 1)
A.roof = 0
else
A.roof = 1
else

if(A.icon_state == "night")//if its a night icon
A.icon_state = ""//make them day
else//if its day
A.icon_state = "night"//make the icons night


spawn(1200)//20 min
Night()//again
world
New()// at the creation of the world
..()
spawn(1)// call it after a few seconds
Night()//calls the night proc



something below here, can anyone help me out?


area
var/image_icon
ceiling
roof2 = 1
Entered(mob/M)
for (var/area/A in world)
if (istype(A, /area/ceiling))
return
M << A.image_icon
M.client.images -= image_icon
..()
Exited(mob/M)
for (var/area/A in world)
if (istype(A, /area/ceiling))
return
M.client.images -= A.image_icon
M << image_icon
..()
entrance

world
New()
for (var/area/A in world)
if (istype(A, /area/ceiling))
if(A.roof == 0)
A.image_icon = image('nroof.dmi', A, "ceiling")
else
A.image_icon = image('roof.dmi', A, "ceiling")
else

A.image_icon = image('roof.dmi', A, "blackness")


mob = /mob

mob
Login()
if(!src.client)
else
for (var/area/ceiling/C in world)
src << C.image_icon
..()

area/entrance


area
var
roof
roof2
In response to Erdrickthegreat2
the iconstate thing causes some lag doesn't it? this is a stupid way, but when i did it i replaced all the turfs in the world with night turfs, by using a variable to store there names in like this
turf
var/namen
New()
src.namen = src.name
and then just do something like
proc/nightime
for(var/turf/T in world)
var/path = "turf/night/[T.namen]"
new path(T)

like this though, you have to define some more turfs, and the paths HAVE to be right, it worked for me
but...im not sure if New() accepts text strings
In response to Magnus VI
eh, well I'd like to keep the proc i have,It hasnt caused lag, but my problem is in my roof part with night
In response to Erdrickthegreat2
hmmm.... the roofs are your problem huh? well i suppose since you just show and image as the icon for the roofs, stick in some variable that will show clients a night icon there instead... You'd probably need a looping proc for continuously checking, it though, and thats not good
In response to Erdrickthegreat2
Ah! It doesn't change because you are changing the area's actual icon instead ot the image_icon that players see.

The fix isn't pretty. For areas with a roof, you'll have to loop through all the clients, remove the old image_icon from client.images, then replace it with the new image.


My suggestion is to make a list of clients that is updated in client/New() and client/Del() so you don't have to worry with filters.

Then in your Night() proc keep two lists, one for area images to remove and one for images to add. Then after you finish updating all the images you can loop through the clients once to add/remove them all.

for(var.client/C in ClientList)
C.images -= removed_images
C.images += new_images
In response to Shadowdarke
Huh? Shadowdarke, so instead of chaging the icon i need to loop through all the players and change the image in there screen and delete the old ones.... Can you explain a little better or show me an example so i better understand
if its not too much of a problem.

ETG
In response to Erdrickthegreat2
Your roof system uses area images to display them to specific clients, much like my own RoofLib does. Changing the icon has no effect on that image, so you have to remove the image from the client, change the image, and show the changed image to the client again.
proc
Night()
var/list
old_images = list()
new_images = list()

for(var/atom/A in world) // check all atoms
if(ismob(A)) continue // don't do anything to mobs
if(A.icon_state == "night")//if its night turf
A.icon_state = ""//make them day
else//if its day
A.icon_state = "night"//make the icons night
if(isarea(A)) // if it's an area
var/area/Area = A
if(Area.roof2) // if roof2 is not 0
old_images += Area.image_icon
Area.roof = !Area.roof // toggle between 1 and 0
Area.image_icon = image(Area.roof_icon, A, Area.icon_state)
New_images += Area.image_icon

for(var.client/C in ClientList)
C.images -= old_images
C.images += new_images

//get the area the mob is in
var/area/A = C.mob.loc
while(A && !istype(A)) A = A.loc

// perform the area Entered() to clear this roof
if(A) A.Entered(C.mob)

spawn(1200)//20 min
Night()//again


Note that I used Area.roof_icon instead of the complex if structure in your world.New() proc, so you'll want to include that as an area var or redo the proc above to include your if() statements. It also uses the "" and "night" icon_states of the roof_icon, so you'll need to change your icons a bit.
In response to Shadowdarke
Shadowdarke wrote:
Your roof system uses area images to display them to specific clients, much like my own RoofLib does. Changing the icon has no effect on that image, so you have to remove the image from the client, change the image, and show the changed image to the client again.
> proc
> Night()
> var/list
> old_images = list()
> new_images = list()
>
> for(var/atom/A in world) // check all atoms
> if(ismob(A)) continue // don't do anything to mobs
> if(A.icon_state == "night")//if its night turf
> A.icon_state = ""//make them day
> else//if its day
> A.icon_state = "night"//make the icons night
> if(isarea(A)) // if it's an area
> var/area/Area = A
> if(Area.roof2) // if roof2 is not 0
> old_images += Area.image_icon
> Area.roof = !Area.roof // toggle between 1 and 0
> Area.image_icon = image(Area.roof_icon, A, Area.icon_state)
> New_images += Area.image_icon
>
> for(var.client/C in ClientList)
> C.images -= old_images
> C.images += new_images
>
> //get the area the mob is in
> var/area/A = C.mob.loc
> while(A && !istype(A)) A = A.loc
>
> // perform the area Entered() to clear this roof
> if(A) A.Entered(C.mob)
>
> spawn(1200)//20 min
> Night()//again
>

Note that I used Area.roof_icon instead of the complex if structure in your world.New() proc, so you'll want to include that as an area var or redo the proc above to include your if() statements. It also uses the "" and "night" icon_states of the roof_icon, so you'll need to change your icons a bit.

Ok, I get the snippet of code, but what do you mean by this,

Note that I used Area.roof_icon instead of the complex if structure in your world.New() proc, so you'll want to include that as an area var or redo the proc above to include your if() statements. It also uses the "" and "night" icon_states of the roof_icon, so you'll need to change your icons a bit.

and how would i have to change my icons?

And on another note, could you suggest another way of making a night proc like this without the major lag

ETG
In response to Erdrickthegreat2
Erdrickthegreat2 wrote:
Ok, I get the snippet of code, but what do you mean by this,

Note that I used Area.roof_icon instead of the complex if structure in your world.New() proc, so you'll want to include that as an area var or redo the proc above to include your if() statements. It also uses the "" and "night" icon_states of the roof_icon, so you'll need to change your icons a bit.

Your system uses this to create the roof icons:
world
New()
for (var/area/A in world)
if (istype(A, /area/ceiling))
if(A.roof == 0)
A.image_icon = image('nroof.dmi', A, "ceiling")
else
A.image_icon = image('roof.dmi', A, "ceiling")
else

A.image_icon = image('roof.dmi', A, "blackness")

I would get rid of that part and add something like this:
area
var
roof_icon = 'darkness.dmi'
New()
..()
if(roof_icon)
image_icon = image_icon = image(roof_icon, src)

ceiling
roof = 2
roof_icon = 'roof.dmi'
and how would i have to change my icons?

It seems all your roof icons are in roof.dmi and nroof.dmi. I'd change them so that you had multiple icons each with "" as the daylit icon_state and "night" as the nighttime state so they conform with your day/night system.


And on another note, could you suggest another way of making a night proc like this without the major lag

The fastest day/night systems are area based. I have examples available as OutsideArea and sd_DynamicAreaLighting

Unfortunately they both rely on dithered icons for now. You can be sure that as soon as BYOND supports alpha channels, sd_DAL will be updated to make use of them. :)
In response to Shadowdarke
This is my roof system.

area
var/image_icon
ceiling
Entered(mob/PC/M)
for (var/area/A in world)
if (istype(A, /area/ceiling))
return
M << A.image_icon
M.client.images -= image_icon
..()
Exited(mob/PC/M)
for (var/area/A in world)
if (istype(A, /area/ceiling))
return
M.client.images -= A.image_icon
M << image_icon
..()

world
New()
for (var/area/A in world)
if (istype(A, /area/ceiling))
A.image_icon = image('roof.dmi', A, "ceiling")
else
A.image_icon = image('roof.dmi', A, "blackness")

mob = /mob/PC

mob/PC
Login()
for (var/area/ceiling/C in world)
src << C.image_icon
..()


SO what would you change to this so that when i call my night proc

proc
Night()
for(var/atom/A in world)//for all turfs
if(!ismob(A))
if(A.icon_state == "night")//if its night turf

A.icon_state = ""//make them day
else//if its day

A.icon_state = "night"//make the icons night
else if(ismob(A))
var/mob/M = A
if(!M.client)//if its an npc
if(M.night==1)//if its night
M.night = 0//make it day
else//otherwise
M.night = 1//its night


I understand what your saying, But I don't understand how to put that together, I learn by seeing, I'm still quite the newbie in DM, and this Roof-night confrontation has been causing me some trouble. How should i change my night proc and change my Roof system so they work together without trouble, note: I only have 2 roof icons 'roof.dmi' which consists of the roof image and and black iconstate named "blackness" the other 'nroof.dmi' with the night roof image and also the "blackness" iconstate.
Any help to better show how to construct this to me would be greatly appreciated and will add to the learning of a newbie coder.

ETG