Initial Commit

master
Xx_Crazyminer_xX 2020-04-14 13:26:33 +02:00
commit 2abfca12bd
8 changed files with 120 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

89
api.lua Normal file
View File

@ -0,0 +1,89 @@
scoreboard_lib.scoreboards = {}
Scoreboard = {
-- players to show the scoreboard to - key index value player
players = {},
-- table containing ids of the huds of all the players - key player value {bg_hud_id = 1, text_hud_id = 1}
hud_ids = {},
-- because the scoreboard is composed by a background and a text we need to
-- define the two HUD to use later
background_def = {
hud_elem_type = "image",
position = { x = 1, y = 0.5 },
scale = { x = 1, y = 1 },
alignment = { x = -1, y = 0 },
text = "scoreboard_bg.png",
},
text_def = {
hud_elem_type = "text",
position = {x = 1, y = 0.5},
alignment = {x = 1, y = 1},
offset = {x = -100, y = -70},
number = 0xFFFFFF,
text = "Default"
}
}
--[[
{
position = { x = 1, y = 0.5 },
alignment = { x = -1, y = 0 },
text = "Default",
text_color = 0xFFFFFF,
players = {}
}
--]]
function Scoreboard:new(def)
local scoreboard = {}
setmetatable(scoreboard, self)
self.__index = self
if (def.position) then
scoreboard.background_def.position = def.position
scoreboard.text_def.position = def.position
end
if (def.alignment) then
scoreboard.background_def.alignment = def.alignment
scoreboard.text_def.alignment = def.alignment
end
if (def.text) then
scoreboard.text_def.text = def.text
end
if (def.text_color) then
scoreboard.text_def.number = def.text_color
end
if (def.players) then
for i, player in pairs(def.players) do
local player_name = player:get_player_name()
scoreboard.players[player_name] = player
scoreboard.hud_ids[player_name] = {bg_hud_id = nil, text_hud_id = nil}
end
end
table.insert(scoreboard_lib.scoreboards, scoreboard)
return scoreboard
end
function Scoreboard:show()
for player_name, player_hud_ids in pairs(self.hud_ids) do
local player = minetest.get_player_by_name(player_name)
if (player_hud_ids) then
if (player_hud_ids.bg_hud_id ~= nil) then
player:hud_remove(player_hud_ids.bg_hud_id)
end
if (player_hud_ids.text_hud_id ~= nil) then
player:hud_remove(player_hud_ids.text_hud_id)
end
end
player_hud_ids.bg_hud_id = player:hud_add(self.background_def)
player_hud_ids.text_hud_id = player:hud_add(self.text_def)
end
end
function Scoreboard:update_players(players)
for i, player in pairs(players) do
if (self.players[player:get_player_name()] == nil) then
self.players[player:get_player_name()] = player
self.hud_ids[player:get_player_name()] = {bg_hud_id = nil, text_hud_id = nil }
end
end
end

6
init.lua Normal file
View File

@ -0,0 +1,6 @@
scoreboard_lib = {}
scoreboard_lib.path = minetest.get_modpath(minetest.get_current_modname())
dofile(scoreboard_lib.path.."/api.lua")
dofile(scoreboard_lib.path.."/test.lua")

2
mod.conf Normal file
View File

@ -0,0 +1,2 @@
name = scoreboard_lib
depends = default

22
test.lua Normal file
View File

@ -0,0 +1,22 @@
local scoreboard
minetest.register_on_joinplayer(function(player)
if scoreboard == nil then
scoreboard = Scoreboard:new({
position = { x = 1, y = 0.5 },
alignment = { x = -1, y = 0 },
text = "NINOOO",
text_color = 0xFF0000,
players = {}
})
end
scoreboard:show()
end)
minetest.register_on_chat_message(function(name, message)
if string.match(message, "mettilacera") then
minetest.chat_send_player(name, "Ti aggiungo la sb "..name)
scoreboard:update_players({minetest.get_player_by_name(name)})
scoreboard:show()
end
end)

BIN
textures/heart.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
textures/scoreboard_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB