ID:149193
 
How would you make stoplights and an area that if the light is red u can't pass?
Make an icon for the light and give it several states (I've assumed they're called "on" and "off" for this example).

area
stoparea //Stops you moving past if light is on
density=0 //Assume the light is off at the start
item
stoplight
name="Stop light"
icon='stoplight.dmi'
icon_state="off"
density=1
//Put any other settings you want in here
proc
turnon()
world << "The light turns on"
icon_state="on"
for (stoparea/A in world)
A.density=1 //Makes all stopareas dense
turnoff()
world << "The light turns off"
icon_state="off"
for (stoparea/A in world)
A.density=0 //Makes all stopareas dense


This is very rough, I haven't tried it out so I hope it works. :)
FireEmblem wrote:
How would you make stoplights and an area that if the light is red u can't pass?

Perhaps try something like this:
mob/Move(atom/newloc)
if(newloc && istype(newloc,/turf/))
var/area/A=newloc.loc
if(A.light==RED)
return 0
else if(A.light==GREEN)
..()

area
var
light=GREEN // pass by default
proc/ToggleLight()
light=!light // if green then red, if red then green

var
const
RED=0
GREEN=1


This ignores any 'light' objects, but you could just have them call loc.loc.ToggleLight(the .loc of a turf is almost always an area, unless you delete it. Im not even sure if its replaced by a default /area/ if you do, so.)

Alathon\\
In response to Alathon
mob/Move(atom/newloc)
if(newloc && istype(newloc,/turf/))
var/area/A=newloc.loc
if(A.light==RED)
return 0
else if(A.light==GREEN)
..()

This looks good, though I'd probably override area/Enter() instead of putting the check in mob/Move, since Enter() is specifically for checking whether the area can be entered. (As opposed to Entered(), which checks whether the area really was entered.)

Like so:

area/trafficBoundary
Enter(mob/M)
if(light == RED) return 0
return ..()

Of course, for an intersection (which is usually where you'd find lights), you only want to block traffic coming from one direction. You could do this by adding this code:

East //Subtype that faces east (blocks westbound traffic)
dir = EAST

//(And so on for the other directions...)

And alter Enter() to look like this:

Enter(mob/M)
if(light == RED)
if(dir == turn(M.dir, 180)) return 0
return ..()

If you really wanted to get fancy, you could stymie would-be diagonal movers by adding checks for turn(M.dir, 135) and turn(M.dir, -135).

In response to Crispy
Where did you come from? All of sudden, a good programmer comes out of nowhere?
In response to Sariat
Who? Me? A good programmer? Don't you mean someone else? :P

(Who were you talking about anyway?)