Danke, auf minetest.after war ich nicht gekommen, aber ist irgendwie logisch sonst wird es ja nur bei einem Spieler angezeigt.
Ich habe den Code nun nochmal geändert:
Code: Select all
local players_hud_id = {}
local b = minetest.get_connected_players
minetest.register_on_joinplayer(function(player)
player_name = player:get_player_name()
players_hud_id[player_name] = player:hud_add({
hud_elem_type = "image",
position = {x = 0.97, y = 0.5},
offset = {x = -220, y = 0},
text = "anzeige.png",
scale = { x = 1, y = 1},
alignment = { x = 1, y = 0 },
})
players_hud_id[player_name] = player:hud_add({
hud_elem_type = "text",
position = {x = 0.97, y = 0.35},
offset = {x = -220, y = 0},
text = "MT Citybuild",
scale = { x = 100, y = 100},
alignment = { x = 3, y = 3 },
number = 0xFFFFFF,
})
local online = player:hud_add({
hud_elem_type = "text",
position = {x = 0.97, y = 0.4},
offset = {x = -220, y = 0},
text = #b(),
scale = { x = 100, y = 100},
alignment = { x = 1, y = 1 },
number = 0xFFFFFF,
})
end)
local player = player_name
minetest.after(10, function(player)
player:hud_change(online, "text", #b())
end)
So kommt aber diese Meldung:
.__ __ __
_____ |__| ____ _____/ |_ ____ _______/ |_
/ \| |/ \_/ __ \ __\/ __ \ / ___/\ __\
| Y Y \ | | \ ___/| | \ ___/ \___ \ | |
|__|_| /__|___| /\___ >__| \___ >____ > |__|
\/ \/ \/ \/ \/
2018-12-11 16:34:24: ACTION[Main]: World at [C:\Program Files\Minetest\minetest-0.4.17.1-win64\bin\..\worlds\virusbanwelt]
2018-12-11 16:34:24: ACTION[Main]: Server for gameid="minetest" listening on 0.0.0.0:30000.
2018-12-11 16:34:27: ACTION[Server]: Niwla [127.0.0.1] joins game.
2018-12-11 16:34:27: ACTION[Server]: Niwla joins game. List of players: Niwla
2018-12-11 16:34:27: WARNING[Server]: Assignment to undeclared global "player_name" inside a function at ...inetest\minetest-0.4.17.1-win64\bin\..\mods\hud\init.lua:8.
2018-12-11 16:34:33: ACTION[Server]: Niwla places node default:cobble at (41,9,-103)
2018-12-11 16:34:33: ACTION[Server]: Niwla places node default:cobble at (50,9,-114)
2018-12-11 16:34:34: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod 'hud' in callback environment_Step(): ...inetest\minetest-0.4.17.1-win64\bin\..\mods\hud\init.lua:44: attempt to index local 'player' (a nil value)
2018-12-11 16:34:34: ERROR[Main]: stack traceback:
2018-12-11 16:34:34: ERROR[Main]: ...inetest\minetest-0.4.17.1-win64\bin\..\mods\hud\init.lua:44: in function 'func'
2018-12-11 16:34:34: ERROR[Main]: ...\minetest-0.4.17.1-win64\bin\..\builtin\common\after.lua:18: in function <...\minetest-0.4.17.1-win64\bin\..\builtin\common\after.lua:4>
2018-12-11 16:34:34: ERROR[Main]: ...minetest-0.4.17.1-win64\bin\..\builtin\game\register.lua:420: in function <...minetest-0.4.17.1-win64\bin\..\builtin\game\register.lua:400>
2018-12-11 16:34:34: ERROR[Main]: stack traceback:
2018-12-11 16:34:34: ACTION[Server]: Niwla leaves game. List of players: