ID:168132
 
Hey wondering how i could do a check if a player is within a certain area and define them as M
This is really two problems. First you need to define the area you're searching in. Secondly, you need to find the mob in it.

How you do the first part really depends on what kind of area you're looking for. You could use block() to get a list of turfs between two sets of coordinates, for example:

block(locate(1,1,1), locate(3,3,1))


Or you might want to get everything within two spaces of src:

oview(2,src)


The second part is either easy or complicated, depending on how you did the first part. This is the easy way:

var/mob/M = locate() in oview(2,src) // Works!


This will work fine. However, if you try this with block()...

var/mob/M = locate() in block(locate(1,1,1), locate(3,3,1)) // Doesn't work!


...it doesn't work!

Why? Because while oview() returns a list of atoms (which includes mobs), block() only returns turfs. So you're looking for a mob in a list of turfs, which is a bit like looking for an apple in a bag of oranges.

So if you can use oview() (or a similar proc, like view() or range()) then do so. If it has to be between two coordinates, though, you're stuck with block().

What you'll need to do in the latter case is loop through every turf in block(), looking for mobs in each one individually. If you need to do this, I can provide example code on request.

Hope that helped!
You'll want the block(), range(), orange(), view() or oview() procs depending on what you want to accomplish. Take a look at them in the reference and see which would best serve your needs.
In response to Crispy
It needs to be within a block unfortunately rather than in oview is there a way to do it using an area tile perhaps because sounds like using block would lag the game.
In response to Sheepywoolyfluff
Sheepywoolyfluff wrote:
It needs to be within a block unfortunately rather than in oview is there a way to do it using an area tile perhaps

Not that's better than using block(), AFAIK.

because sounds like using block would lag the game.

Nope, it'd be fine. This seems to be a common misconception; people think that "loop" automatically implies "lag", which is quite wrong. Loops themselves don't lag games. Unless you're planning to do this search a few thousand times per second, I wouldn't worry.
In response to Crispy
can you give me an example of how to do it because I dont tend to use loops :P
In response to Sheepywoolyfluff
for (var/turf/T in block(locate(1,1,1), locate(2,3,1)))
for (var/mob/M in T)
// M is a mob within the given coordinates
// Any code here will be executed once for every mob within the coords given to block()