ID:155973
![]() Jan 23 2011, 12:25 am
|
|
Is it possible to have like a command where like it checks like a certain area. Here is a Diagram to show what I am talking about:
|
mob I'm not going to do it for you if that's what you're asking. |
view("5x2")
|
I was going to reply with this until I realized that it's much more tedious code to have a result shown in the OP's picture.
Not the best way, but the easiest I can think of off the top of my head. mob/proc/get_rectangle_ahead() |
That I think is the absolute worst possible way to go about this. Don't give advice to people on the Developers Forums if you yourself are not an experienced developer and advocate bad practices.
To the OP: for(var/turf/T in Block(locate(x-3,y+2,z),locate(x+3,y+1,z)) I'd say using Block() and specifying the range you check(By top left tile, to bottom left tile) would be a simple way of achieving this. |
for(var/obj/cards/C in Block(locate(x-3,y+2,z),locate(x+3,y+1,z)) It seems when I put this in, it always comes up with errors. Errors include loading Duel Monsters Game.dme |
add an end parenthesis in the for, he forgot one
block() is really slow also, but you're not using too big of an area so it shouldn't matter. |
It still doesn't work.
Here is the code now: for(var/obj/cards/C in block(locate(usr.x-3,usr.y+2,usr.z),locate(usr.x+3,usr.y+2,usr.z))) |
What, specifically, isn't working?
Also, the block() proc works with the lower-left corner of the block for the first argument, and the top-right corner for the second. |
DeltaMaster wrote:
It still doesn't work. for(var/obj/cards/C in block(locate(usr.x-3,usr.y+2,usr.z),locate(usr.x+3,usr.y+2,usr.z))) block() returns a list of turfs, which your card objects won't be explicitly included in (unlike with view()). What you have to do is loop through the turfs in the block, and then use locate() to check for a card object in each turf (as Bakasensei showed you, so look at his code more carefully. Just instead of mobs, you'll be locating /obj/cards) |
Kaiochao wrote:
I was going to reply with this until I realized that it's much more tedious code to have a result shown in the OP's picture. Ah, right. Well then, perhaps you could do something like... mob/proc/get_view_ahead(a,b, distance) Then you could do get_view_ahead("5x2", src, 2) to get a 5x2 viewing offset by two tiles in the direction you are facing. Oh, and you'd have to account for the direction if you want to rotate the rectangle, that is, you'd have to be able to change it from 5x2 to 2x5. Also, this will not take the mob's special view status into consideration. For example, if the mob has see_invisible or a change to its sight variable or anything else, the view from the turf's point of view is not going to take that into account. Kaiochao's version will work for the specific situation in the picture you showed, and mine will allow for different translations if you don't want it just directly ahead. Mine, as I said, requires you to handle the special cases where you need to rotate the rectangle according to your direction (north/south vs east/west), but Kaiochao's takes care of that automatically. |
This now gives the exact location of that tile. So.. You want a few tiles so just save them all as variables like this :
The rest should be pretty basic but if you need any more help just drop another post.