Page 1 of 1

How to use HUD API?

PostPosted: Sun Dec 28, 2014 21:31
by PeterKabin
That doesn't work.
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
player:hud_add({
    hud_elem_type = "statbar",
    position = {x=0,y=1},
    size = "",
    text = "ui_heart_bg.png",
    number = 20,
    alignment = {x=0,y=1},
    offset = {x=0, y=-32},
})
health_hud[name] = player:hud_add({
    hud_elem_type = "statbar",
    position = {x=0,y=1},
    size = "",
    text = "ui_heart_fg.png",
    number = player:get_hp(),
    alignment = {x=0,y=1},
    offset = {x=0, y=-32},
})

Re: How to use HUD API?

PostPosted: Mon Dec 29, 2014 15:29
by PeterKabin
Did anybody understood how to do it?

Re: How to use HUD API?

PostPosted: Mon Dec 29, 2014 15:34
by Krock
It added the HUD but could be invisible for you (out of the window).
Look at mods which use HUD elements and compare the codes.

Re: How to use HUD API?

PostPosted: Mon Dec 29, 2014 17:22
by rubenwardy
Please can you explain what you want to do?

Re: How to use HUD API?

PostPosted: Mon Dec 29, 2014 18:30
by PeterKabin
I made that mod and it does not show any text. I want to make mod, which show rules of the server.
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
tekstik="azazazaza"
while player~=nil do
    player:hud_add({
        hud_elem_type = {"text"},
        position = {x=0.5,y=0.5},
        size = {x=-20,y=-20},
        text = tekstik,
        alignment = {x=0,y=0},
        offset = {x=0,y=0},
    })
end

Image

Re: How to use HUD API?

PostPosted: Mon Dec 29, 2014 18:37
by Krock
PeterKabin wrote:I made that mod and it does not show any text. I want to make mod, which show rules of the server.

Getting a player object does not work like this.
Example code:
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
local initial_text = "hello world!"
minetest.register_on_joinplayer(function(player)

    local my_hud = player:hud_add({
        hud_elem_type = "text",
        position = {x=0.5,y=0.5},
        size = {x=-20,y=-20},
        text = initial_text,
        alignment = {x=0,y=0},
        offset = {x=0,y=0},
    })

end)

This adds the text as HUD of a new joined player.

Re: How to use HUD API?

PostPosted: Tue Dec 30, 2014 10:05
by PeterKabin
Thanks.

Re: How to use HUD API?

PostPosted: Sat Jan 10, 2015 16:26
by PeterKabin
I'm trying to make a mod, showing first white, then green text, but this mod works only sometimes:
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_craftitem("testiki:tul", {
    description = "beret vesh",
    inventory_image = "testiki.png",
    on_use = function(itemstack, player, pointed_thing)
    -- Takes one item from the stack
    local tekst = itemstack:take_item()
    local hud = player:hud_add({hud_elem_type = "text",position = {x=0.3,y=0.5},direction = 0,text = tostring(tekst),scale={x=100,y=100},number = 0xFFFFFF,alignment = {x=0,y=0},offset = {x=0,y=0},})
     
    player:hud_change(hud,number,0x00FF00)
   
    return itemstack
    end,
})

How to make it always workable?

Re: How to use HUD API?

PostPosted: Sat Jan 10, 2015 16:32
by rubenwardy
Use minetest.after to change the color after a delay.

Re: How to use HUD API?

PostPosted: Sat Jan 10, 2015 17:08
by PeterKabin
thanks!