Putnam3145Grandmaster Rawsmith•

Usually "for k,v in ipairs(list)" is preferred over for i=0,#list-1,1. Also, it would make the code run faster, since the "unit=df.global.world.units.all[i]" bit can be skipped (make it "for k,unit in ipairs(df.global.world.units.active)" and you don't even need to rewrite anything).

Also, Lua doesn't scope variables locally automatically--any variable that isn't explicitly defined as "local" is global, so you may want to add a "local" or two.

7
MapariensisOPAbod Ber•

Thanks! I don't use lua very often, so I'm not familiar with the idioms. I appreciate the feedback.

EDIT: Modified the snippet accordingly.

5
sentient8has been struck down.•

THANK YOU

2
troyortroy•

How does this work? I type it but nothing happens? This is gonna be awesome once I figure out how it works lol

1
MapariensisOPAbod Ber•

Say you're in a crowded fortress looking for a dwarf named Asmel Raghalls. There are 200 dwarves in the fortress, so going around asking everyone's names would take far too much time. Assuming Asmel actually resides in the fortress (i.e. on the map you're currently on), you can type "whereis Asmel" into the DFhack console, and it should reply with something like "Asmel Raghalls is at (29,30,63)".

What you can't do is type "whereis Asmel" in a neighbouring town, because at that point Asmel's unit isn't loaded, so it won't show up in df.global.world.units. Fortunately, asking NPC's in which settlement an individual lives isn't too hard most of the time.

EDIT: Of course you can also locate yourself by typing "whereis <your-name-here>", the script wouldn't be very useful otherwise.

3
troyortroy•

For some reason, im not getting a reply. I also tried locating myself. I'm using Dwarf Fortress 40_15 Starter Pack r2 if that makes a difference.

EDIT. Stupid me didn't realize it was case sensitive. Thanks a bunch this is awesome. now for another stupid question. Whats these numbers?

1
MapariensisOPAbod Ber•

The numbers are (x,y,z) coordinates. Try calling the script with your adventurer's name to get a feel for how close you are to the target.

1
PeridexisErrant•

How hard would it be to provide relative coordinates? It would be pretty cool if it output "y tiles North, x East, z Up" with your adventurer at the center. Non case sensitive would also be more intuitive.

All this in the context of an already-amazing tool!

3