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

User avatar
bdjnk
Member
 
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk

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

by bdjnk » Fri Mar 22, 2013 09:28

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.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Fri Mar 22, 2013 09:43

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.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
bdjnk
Member
 
Posts: 104
Joined: Wed Mar 20, 2013 21:03
GitHub: bdjnk

by bdjnk » Fri Mar 22, 2013 09:46

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.
Last edited by bdjnk on Fri Mar 22, 2013 09:47, edited 1 time in total.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Fri Mar 22, 2013 10:03

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!
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 17 guests