Removing local hud elements

User avatar
PolySaken
Member
 
Posts: 471
Joined: Thu Nov 09, 2017 05:18
Location: djelibabi
GitHub: PolySaken-I-Am
In-game: PolySaken

Removing local hud elements

by PolySaken » Sat Feb 08, 2020 05:13

Does anyone know how to remove hud elements from the client side? I want to replace them with custom elems.
 

User avatar
Krock
Developer
 
Posts: 4475
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: Removing local hud elements

by Krock » Sat Feb 08, 2020 10:36

Search the HUD by its properties. CSM code example:
Code: Select all
minetest.register_chatcommand("health", {
   params = "",
   description = "Remove healthbar",
   func = function(param)
      local player = minetest.localplayer
      local id
      for i = 0, 10 do
         local def = player:hud_get(i)
         if def and
               def.type == "statbar" and
               def.text == "heart.png" then
            id = i
            break
         end
      end
      if not id then
         return false, "Health statbar not found"
      end
      player:hud_remove(id)
      return true, "Removed!"
   end
})
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
PolySaken
Member
 
Posts: 471
Joined: Thu Nov 09, 2017 05:18
Location: djelibabi
GitHub: PolySaken-I-Am
In-game: PolySaken

Re: Removing local hud elements

by PolySaken » Sun Feb 09, 2020 01:10

Krock wrote:Search the HUD by its properties. CSM code example:
Code: Select all
minetest.register_chatcommand("health", {
   params = "",
   description = "Remove healthbar",
   func = function(param)
      local player = minetest.localplayer
      local id
      for i = 0, 10 do
         local def = player:hud_get(i)
         if def and
               def.type == "statbar" and
               def.text == "heart.png" then
            id = i
            break
         end
      end
      if not id then
         return false, "Health statbar not found"
      end
      player:hud_remove(id)
      return true, "Removed!"
   end
})

cool, thanks.
 


Return to Client-side modding



Who is online

Users browsing this forum: No registered users and 0 guests