HUD Problems

Post Reply
User avatar
debiankaios
Member
Posts: 320
Joined: Thu Dec 03, 2020 12:48
In-game: debiankaios Nowe
Location: germany
Contact:

HUD Problems

by debiankaios » Post

Hi I have problems with HUD can you please help me:

Code: Select all

local S = minetest.get_translator("tntrun")

arena_lib.on_load("tntrun", function(arena)
  local pos1 = arena.tnt_area_pos_1
  local pos2 = arena.tnt_area_pos_2
  local x1 = pos1.x
  local x2 = pos2.x
  local y1 = pos1.y
  local y2 = pos2.y
  local z1 = pos1.z
  local z2 = pos2.z
  if x1 > x2 then
      local temp = x2
      x2 = x1
      x1 = temp
  end
  if y1 > y2 then
      local temp = y2
      y2 = y1
      y1 = temp
  end
  if z1 > z2 then
      local temp = z2
      z2 = z1
      z1 = temp
  end

  for x = x1,x2 do
      for y = y1,y2 do
          for z = z1,z2 do

                  minetest.set_node({x=x,y=y,z=z}, {name="tntrun:tnt"})



          end
      end
  end
  arena_lib.HUD_send_msg_all("title", arena, S("Fight!"), 3,nil,0xf70000)
  local item = ItemStack("tntrun:torch")

    for pl_name, stats in pairs(arena.players) do
        local player = minetest.get_player_by_name(pl_name)
        player:get_inventory():set_stack("main", 1, item)
    end

    for pl_name, stats in pairs(arena.players) do
      local message = S('How it works:')
      minetest.chat_send_player(pl_name,message)
      message = minetest.colorize('Yellow', S('Punch TNT with the torch to make other players fall!'))
      minetest.chat_send_player(pl_name,message)
      message = minetest.colorize('Red', S("WARNING: Don't stay in one place!"))
      minetest.chat_send_player(pl_name,message)
      arena.players[pl_name].lives = arena.lives

  end
  local orginal_player_in_arena = arena.players_amount
  for pl_name, stats in pairs(arena.players) do
    local player = minetest.get_player_by_name(pl_name)
    local idx = player:hud_add({
        hud_elem_type = "text",
        position  = {x = 0.55, y = 0},
        offset    = {x = -215, y = 23},
        text      = tostring(arena.players_amount) .. "/" .. tostring(orginal_player_in_arena),
        alignment = -1,
        scale     = { x = 50, y = 10},
        number    = 0xFFFFFF,
    })
  end

end)

arena_lib.on_death('tntrun', function(arena, p_name, reason)
    arena_lib.remove_player_from_arena(p_name, 1)
    minetest.sound_play('lose', {
    to_player = p_name,
    pl_name:hud_change(idx, "text", ""),
    gain = 2.0,
})
end)
minetest.register_on_joinplayer(function(player)
	local inv = player:get_inventory()
	local stack = ItemStack("tntrun:torch")
	local taken = inv:remove_item("main", stack)
end)

arena_lib.on_end('tntrun', function(arena, players, winner_name)
  minetest.sound_play('win', {
  to_player = winner_name,
  gain = 2.0,
})
end)

Code: Select all

AsyncErr: ServerThread::run Lua: Runtime error from mod '*builtin*' in callback on_dieplayer(): /home/exp/.minetest/mods/tntrun/auto.lua:77: attempt to index global 'pl_name' (a nil value)
stack traceback:
	/home/exp/.minetest/mods/tntrun/auto.lua:77: in function 'on_death'
	/home/exp/.minetest/mods/arena_lib/player_manager.lua:94: in function </home/exp/.minetest/mods/arena_lib/player_manager.lua:83>
	/usr/share/games/minetest/builtin/game/register.lua:429: in function </usr/share/games/minetest/builtin/game/register.lua:413>
Thank you for help!

PS: If i type player:remove_hud… come the same problem

User avatar
cx384
Member
Posts: 519
Joined: Wed Apr 23, 2014 09:38
GitHub: cx384
IRC: cx384

Re: HUD Problems

by cx384 » Post

I don't know what "arena_lib.on_death" does, but I guess pl_name is not an ObjectRef but just the player's name.
You probably have to use minetest.get_player_by_name(pl_name) at line 77 to get the player's ObjectRef so that you can call hud_change.
Otherwise note that an ObjectRef often can be nil so you may have to check that.
Can your read this?

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests