Page 1 of 1

[mod] (sorta) Depth Finder - command to get your y axis, in game

PostPosted: Fri Mar 22, 2013 09:28
by bdjnk
After installing More Ores and digging deep into the bowels of the earth, I began to really regret not having a way to calculate my depth. I mean, I felt like I'd been digger for an eternity, but how close was I to the mystical Mithril layer?

For that matter, what about the depths of mese and lava. Though I can't currently figure out how deep they normally are (even by searching the source), I'm sure if I did it would only make my desire to know my depth even stronger.

After a bit of reading up on Lua and scraping code from other mods, here is what I came up with (works):

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("depth", {
    params = "",
    description = "depth: Get current depth",
    func = function(name, param)
        local player = minetest.env:get_player_by_name(name)
        if not player then
            return
        end
        depth = (player:getpos()).y - 0.5;
        minetest.chat_send_player(name, "You are currently "..(math.abs(depth)).." blocks "..(depth < 0 and 'below' or 'above').." sea level");
    end,
})


The "- 0.5" is necessary to give the expected whole number value, likely because depth is calculated from the head / camera (don't know though).

Anyway, enjoy.

PostPosted: Fri Mar 22, 2013 09:43
by kaeza
bdjnk wrote:After installing More Ores and digging deep into the bowels of the earth, I began to really regret not having a way to calculate my depth. I mean, I felt like I'd been digger for an eternity, but how close was I to the mystical Mithril layer?

For that matter, what about the depths of mese and lava. Though I can't currently figure out how deep they normally are (even by searching the source), I'm sure if I did it would only make my desire to know my depth even stronger.

After a bit of reading up on Lua and scraping code from other mods, here is what I came up with (works):

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("depth", {
    params = "",
    description = "depth: Get current depth",
    func = function(name, param)
        local player = minetest.env:get_player_by_name(name)
        if not player then
            return
        end
        depth = (player:getpos()).y - 0.5;
        minetest.chat_send_player(name, "You are currently "..(math.abs(depth)).." blocks "..(depth < 0 and 'below' or 'above').." sea level");
    end,
})


The "- 0.5" is necessary to give the expected whole number value, likely because depth is calculated from the head / camera (don't know though).

Anyway, enjoy.

Nice you took the time to code this, but by just pressing F5 you can get your current pos.

PostPosted: Fri Mar 22, 2013 09:46
by bdjnk
kaeza wrote:Nice you took the time to code this, but by just pressing F5 you can get your current pos.


Haha, thanks :)

I like the simplicity of my script output, but if I knew about F5 I probably wouldn't have made it. At least it was a learning experience.

PostPosted: Fri Mar 22, 2013 10:03
by kaeza
bdjnk wrote:
kaeza wrote:Nice you took the time to code this, but by just pressing F5 you can get your current pos.


Haha, thanks :)

I like the simplicity of my script output, but if I knew about F5 I probably wouldn't have made it. At least it was a learning experience.

Well, at least you are on the positive side of things :) Hope you bring new stuff to the game.
Welcome to the community!