How to use HUD API?

PeterKabin
Member
 
Posts: 23
Joined: Sun Jun 09, 2013 08:33

How to use HUD API?

by PeterKabin » Sun Dec 28, 2014 21:31

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},
})
 

PeterKabin
Member
 
Posts: 23
Joined: Sun Jun 09, 2013 08:33

Re: How to use HUD API?

by PeterKabin » Mon Dec 29, 2014 15:29

Did anybody understood how to do it?
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: How to use HUD API?

by Krock » Mon Dec 29, 2014 15:34

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.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How to use HUD API?

by rubenwardy » Mon Dec 29, 2014 17:22

Please can you explain what you want to do?
 

PeterKabin
Member
 
Posts: 23
Joined: Sun Jun 09, 2013 08:33

Re: How to use HUD API?

by PeterKabin » Mon Dec 29, 2014 18:30

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
Last edited by PeterKabin on Mon Dec 29, 2014 18:38, edited 1 time in total.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: How to use HUD API?

by Krock » Mon Dec 29, 2014 18:37

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.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

PeterKabin
Member
 
Posts: 23
Joined: Sun Jun 09, 2013 08:33

Re: How to use HUD API?

by PeterKabin » Tue Dec 30, 2014 10:05

Thanks.
 

PeterKabin
Member
 
Posts: 23
Joined: Sun Jun 09, 2013 08:33

Re: How to use HUD API?

by PeterKabin » Sat Jan 10, 2015 16:26

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?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How to use HUD API?

by rubenwardy » Sat Jan 10, 2015 16:32

Use minetest.after to change the color after a delay.
 

PeterKabin
Member
 
Posts: 23
Joined: Sun Jun 09, 2013 08:33

Re: How to use HUD API?

by PeterKabin » Sat Jan 10, 2015 17:08

thanks!
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 16 guests

cron