for(var/mob/over9000/M in src.z)
ID:158101
![]() Oct 31 2009, 10:48 am
|
|
Is it possible? I was just wondering about it, would this work?
|
Remember, block() returns a list of turfs. So you'd have to loop through turfs in block(), then loop through mobs in the turf.
for(var/turf/T in block(a,b)) |
How would it decide what to loop "on" since z is just a number? What if I decided to do for(O on health), should all numbers be treated as z and if my health is 8 then go through all the contents of all the turfs in block() from locate(1,1,health) to locate(world.maxx, world.maxy, health)? I'm not sure how logical such a thing is anyway.
What would be better, though probably still would never happen, would be to have some object that represents all those turf objects. For example, if Byond had special built-in objects called z1, z2, z3, etc. up to zN where N was world.maxz, and each of them had a contents variable that worked specially to contain all the turfs and turfs contents of that z plane, then you could do for(var/mob/M in z8). Actually, now that I think about it, that wouldn't allow you to select z planes dynamically, so maybe have it be a list, then you could do for(var/mob/M in z[8]). Still, this would be a highly specialized functionality that doesn't really add to what Byond can do, nor would it be much more efficient than how you would already have to do it (just using 2 loops instead of 1), so it probably won't happen. |
So...
proc That will delete all mobs then? |
Yes, but if this is something you are doing often you're better off just maintaining a list of where mobs are:
var/list/moblist = list() Then, you can just loop through moblist[zlevel] to get all the mobs on that zlevel. Presumably, your mobs aren't moving between z-levels at all. |
Garthor wrote:
[...] |
Garthor wrote:
var/list/moblist = list() // Did you mean to create a multi dimensional list here, like = new/list(world.maxz,0)? |
May I ask what exactly you intend to do and how you design your map?
Using areas could be a neat and flexible solution, depending on your criteria. |
As I'm already nitpicking, I forgot to request a check for z to be set in 1 to world.maxz, since you defined this on the base mob type and it could result in trouble with player characters, or NPCs that are created on the fly(in the void).
Since BYOND lists don't take zero as index. |
I'm just using it for my Tower Offense game. Just at the end of each round when the player moves to a new z, I use something to delete all leftover mobs on the z map to reduce lag.
|
That only answered half of my question though.
You might want to check if you can lay your map out in a way to use different areas per logically separated location. That way, you are not restricted to 'z levels' and can easily loop through the area's content list (as these are special). You could even make good use of object oriented programming this way and override Exited() on area to suspend all mobs on the area you just left (or have them garbage collected, if you prefer that). This assumes proper use of Move() and not setting loc directly though. |
Ganing wrote:
So...
if(M.client==0)
Change that to if(!client). If I'm not mistaken, client is null if the mob is not attached to a client, not 0. !client will handle either 0 or null though. |
Schnitzelnagler wrote:
As I'm already nitpicking, I forgot to request a check for z to be set in 1 to world.maxz, since you defined this on the base mob type and it could result in trouble with player characters, or NPCs that are created on the fly(in the void). I'm assuming players are excluded here as I've already stated that I'm not accounting for mobs moving between z-levels. It's defined under the generic mob type only because I didn't feel like writing mob/whatever. |
however, you could achieve this using block: