From 2abfca12bd36128fce935631f64aa4e3d364121f Mon Sep 17 00:00:00 2001 From: Xx_Crazyminer_xX Date: Tue, 14 Apr 2020 13:26:33 +0200 Subject: [PATCH] Initial Commit --- .gitignore | 1 + api.lua | 89 ++++++++++++++++++++++++++++++ init.lua | 6 ++ mod.conf | 2 + test.lua | 22 ++++++++ textures/heart.png | Bin 0 -> 258 bytes textures/quake_leaderboard_bg.png | Bin 0 -> 16850 bytes textures/scoreboard_bg.png | Bin 0 -> 15902 bytes 8 files changed, 120 insertions(+) create mode 100644 .gitignore create mode 100644 api.lua create mode 100644 init.lua create mode 100644 mod.conf create mode 100644 test.lua create mode 100644 textures/heart.png create mode 100644 textures/quake_leaderboard_bg.png create mode 100644 textures/scoreboard_bg.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..6733483 --- /dev/null +++ b/api.lua @@ -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 \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..1893b25 --- /dev/null +++ b/init.lua @@ -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") \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..c882dbf --- /dev/null +++ b/mod.conf @@ -0,0 +1,2 @@ +name = scoreboard_lib +depends = default diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..4f5e1f6 --- /dev/null +++ b/test.lua @@ -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) diff --git a/textures/heart.png b/textures/heart.png new file mode 100644 index 0000000000000000000000000000000000000000..8a0ad7b636b46943916e158967a6dc0cc6a5d33b GIT binary patch literal 258 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|_ISEDhFJ6_ zCoB*!Si~*y;>F+gjruV=k92tRtY$pH^^q~f`2o+2XI^!2Y|;15^MF8{ze3UN6ooGj z&+p-RD{sG8;!uaTv0g(Shwvs9A7l3=g3Lf1#(Y6H;n1osmIF=iY(P5gr_DdSGVzqW zBpX|s`izopr0RMknIk#?@9EBGsZKlXplOA`qa_8l_0-Xlr$nOkgz0#3YaeZ55OX z)|N=YH$7}uj}NRhuCldaTNReNU8?Q6RjWt3K7h8m6v4ID2YV;s5k{C}ALs1ZJu~Md zlka}_`@VaB-@V_={4ps>pZ#oD==e|ugAq1Elac|>8;H;FVc=UiWa(vadd#YsXJ;_N z>xj>gifQ4G1C<`jgdMPUmO_u4d58hmp*)w_3VH+Gbe9#;FF_q_9h!|<5;$!~KIX77 zLjvbTiI%Ums?i)wlW#-k=FiU5=P%LA4V>w!P^C)&9GFoD!giTW7Q4cg!14K2fZs$j z#9{loIF=-El8At8SewpP<2IBn;YqoAfhe9Wlk)@;dAv{@#}@JhQiv~y1Y#~4euqq(P>2&g(A|7tbh6HlC9O4Thp^yuDaP4l3 z195RJ_DOyxJ$_P9yWWOb9T;w56MhjLp6f{9aEL&?NB6wU*4{uCdpA2k5pp3`NWkMm z0~s0gy*Acdo5?pcgC0Uns2R05?7&Vipq(`bci{FMe2|d6>Olj8oM^SZu?HNl**suq zyCXFZAm~Oqprt+2ZAGCB)Q;!c^k`}xn98JqX79j^eaY$PiO>u>cGQIpVn%5EX1=B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KvtDjpO&C2=g5AC@ZJ&cxGb#m!HSeqJxu+lN>LZfAeBA6LzYqp++p4>kr z@%RPV?HltebEkL{w`76|t8X;PoGWTS+Iz24_RKI|W95ajE${O$v&DvT^<+(SSY42N zel%-)SlB40WA>fPEM0+OuO_a_y{4i(d5hCCx&Zc^uN8HKcfz0SiV#j0Mlu~{f$rGt z%If>eH0LKI>W;OKHS@e7k<2XFnZ!6xXnkutRR8ZqHdv`{a!JaMii-TiWdqe7i zFhj6z$c~7tNm)ZhZ65yk5$d>4HE}bex8H)18pOHsKom-+Uz;;A}jy9`<~tAGfd}49q_%F1vZcfynBL)Vz?V>ldHQ zePKGA|DcKgr_rhn_|7M`Y&Ku&a#z2`^3L4%t)P`vM+g2;eP-Ddm!fk literal 0 HcmV?d00001 diff --git a/textures/scoreboard_bg.png b/textures/scoreboard_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..4078e8e54c0867d86993fb40757808762d7d5d56 GIT binary patch literal 15902 zcmeI3&5zqe6u{k9RP9zRLWr`!0V@>()O9>|5+^oEs_mv_S0ZJ#4QhI#6VD`TZDOak zcavQS@g)w3iUU#+e*qkjkb33-Lckw@)B_y3fsiKxJCkIzv{eykEal_9H}Acf z-y1*M2YE|rHC3DCnKl!v{p8(70iCW>p3|5UAJ6+sr zZxFm(R#}&%-bplEgCVZ!KnDuQDSE!40V}6lnsJ_POppo^k7Q!hJ><0ar(={FTHeYT zmR3r~NR4D;kn;z@5FRQ@dTc5VvaPn~_h49cda#4lzS}9Qi83{Eva75$uj~0_TDY1k ztMk-zy=tDlOSko^YvX_vBS;mAlqx!LFT&2Wc5LW6RZ^5Ja*&nFnb6h|R!VupP;{6# zlol=^C1(J`Y!ymH4H#vWp030xnF);)X{U3f7r>h#EquLhZMZ=Q$pSWN(R>^-AEY6S zS|wY7W{!U4TjZ;a6f>{2^gM>qTl1XnSLnlW$YDgBeX_Kzn^gPF?tWIf@X|Zn3Y&j3Nz2f*O z_r*B|+t}sxi8xd=YH^UjYlj2qp>W78SpZnNf)JB)x{3A6%PSmeZ7=6YUV=$W#NJmX@eo(-Z4S*#^b9^|1% zojmo-T;nEJpojSOT}!3&b~&ij(| z*FEz4ncfBEAl?Fk8-knU`K)Lmb#9AAFs z$&+tCfBWahKYr^ZIQ!#w%^NGXKDhI3bNQ70?j52yYQvRVj}iUyDWV5wi5{*z!hw%$ iE_=r$>E69#(%tIO&tG}!%MN{md*jlT+E*8Ey!SV&_C1~e literal 0 HcmV?d00001