ID:144868
 
Code:
obj/Build/Furniture
icon = 'Furniture.dmi'

Chair
icon_state = "chair"
DblClick()
var/mob/M = usr

for(var/obj/O in view(0,M))
if(!istype(O,/obj/Floors))
return

if(M.energy <= 9)
M << "You don't have enough energy.."
return
new/obj/Furniture/Chair(M.loc)
M.energy -= rand(0,2)
M.build_exp += rand(1,10)
M.Build_Level()
return


Problem description:
I am working on a kind of building game. Most stuff you build, can't be built on top of other objects so I just used this line:

        DblClick()
var/mob/M = usr

for(var/obj/O in oview(0))
M << "You need to clear the area fist.."
return


With the furniture though I wanted to make it so they could build over floors, but not stuff like walls and stuff.

Now everything works, like the walls and such, but the furniture still allows me to build on walls, windows and doors.

Can anyone help me out please?

Shades wrote:
>           for(var/obj/O in oview(0))
> M << "You need to clear the area fist.."
> return
>

oview() discludes all objects in the center. It would be smarter to use locate() to try and find objs in a certain area instead.

if(locate(/obj) in M.loc)
...


~~> Unknown Person
In response to Unknown Person (#1)
Ok thanks for pointing that out, but it still dosen't fix the problem I am having with the furniture.
In response to Shades (#2)
To disallow people to build furniture on floors, just check the turf that's in your building location.

if(istype(M.loc, /turf/wall))
// disallow building


~~> Unknown Person
In response to Unknown Person (#3)
I feel dumb, turns out I was adding the line of code to the wrong thing and thats why it wasn't working... It works now... :/
In response to Shades (#4)
M.loc is a turf.
if(locate(/obj/Walls) in M.loc) might work better.
In response to Shades (#4)
Shades wrote:
> > if(istype(M.loc, /turf/wall))
> > // disallow building
> >


~~> Unknown Person

> obj/Build/Furniture
> icon = 'Furniture.dmi'
>
> Chair
> icon_state = "chair"
> DblClick()
> var/mob/M = usr
>
> if(istype(M.loc, /obj/Walls))
> M << "You need to clear the area fist.."
> return
>

Oh, I see. Your walls are objs. You'll have to use <code>locate()</code> to check for any wall objects in the uesr's loc.

if(locate(/obj/Walls) in M.loc)
// disallow


~~> Unknown Person