From 82529b56e3c3585af874162ee3fa5218d4af228f Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 12 Oct 2017 01:19:23 +0100 Subject: [PATCH] Add pro-only area in chest --- mods/ctf_stats/gui.lua | 1 + mods/ctf_stats/init.lua | 3 +- mods/ctf_team_base/depends.txt | 1 + mods/ctf_team_base/init.lua | 85 ++++++++++++++---- .../textures/ctf_team_base_pro_only.png | Bin 0 -> 140 bytes 5 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 mods/ctf_team_base/textures/ctf_team_base_pro_only.png diff --git a/mods/ctf_stats/gui.lua b/mods/ctf_stats/gui.lua index d2345b7..9ba2ccc 100644 --- a/mods/ctf_stats/gui.lua +++ b/mods/ctf_stats/gui.lua @@ -41,6 +41,7 @@ local function calc_scores(players) return one.score > two.score end) end +ctf_stats.calc_scores = calc_scores function ctf_stats.get_formspec(title, players) calc_scores(players) diff --git a/mods/ctf_stats/init.lua b/mods/ctf_stats/init.lua index 00139c2..b8e49d4 100644 --- a/mods/ctf_stats/init.lua +++ b/mods/ctf_stats/init.lua @@ -53,7 +53,8 @@ function ctf_stats.player(name) kills = 0, deaths = 0, captures = 0, - attempts = 0 + attempts = 0, + score = -1, } ctf_stats.players[name] = player end diff --git a/mods/ctf_team_base/depends.txt b/mods/ctf_team_base/depends.txt index dcd7be6..a0d3d36 100644 --- a/mods/ctf_team_base/depends.txt +++ b/mods/ctf_team_base/depends.txt @@ -2,3 +2,4 @@ ctf ctf_flag ctf_match ctf_barrier +ctf_stats diff --git a/mods/ctf_team_base/init.lua b/mods/ctf_team_base/init.lua index ce946b4..f0cafe3 100644 --- a/mods/ctf_team_base/init.lua +++ b/mods/ctf_team_base/init.lua @@ -35,18 +35,16 @@ function ctf.get_spawn(tname) end end - -local chest_formspec = - "size[8,9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_name;main;0,0.3;8,4;]" .. - "list[current_player;main;0,4.85;8,1;]" .. - "list[current_player;main;0,6.08;8,3;8]" .. - "listring[current_name;main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85) +local function get_is_player_pro(player) + local players = {} + for pname, pstat in pairs(ctf_stats.players) do + pstat.name = pname + pstat.color = nil + table.insert(players, pstat) + end + ctf_stats.calc_scores(players) + return ctf_stats.player(player:get_player_name()).score > 0 +end local colors = {"red", "blue"} for _, color in pairs(colors) do @@ -66,18 +64,67 @@ for _, color in pairs(colors) do sounds = default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", chest_formspec) meta:set_string("infotext", "Chest") local inv = meta:get_inventory() - inv:set_size("main", 8*4) + inv:set_size("main", 5*4) + inv:set_size("pro", 3*4) end, - can_dig = function(pos,player) - return false + on_rightclick = function(pos, node, player) + local chestinv = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z + local is_pro = get_is_player_pro(player) + + local formspec = + "size[8,9]" .. + "label[0,-0.2;" .. minetest.formspec_escape("Any player can take from here, including enemies") .. "]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[" .. chestinv .. ";main;0,0.3;5,4;]" .. + "background[5,-0.2;3.15,4.7;ctf_team_base_pro_only.png;false]" .. + "list[" .. chestinv .. ";pro;5,0.3;3,4;]" .. + "list[current_player;main;0,4.85;8,1;]" .. + "list[current_player;main;0,6.08;8,3;8]" + + if is_pro then + formspec = formspec .. "listring[current_name;pro]" .. + "label[5,-0.2;" .. minetest.formspec_escape("Pro players only (score 200+)") .. "]" + else + formspec = formspec .. "listring[current_name;pro]" .. + "label[5,-0.2;" .. minetest.formspec_escape("You need more score (200+)") .. "]" + end + + formspec = formspec .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,4.85) + + minetest.show_formspec(player:get_player_name(), "ctf_team_base:chest", formspec) end, - on_metadata_inventory_move = function(pos, from_list, from_index, + + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", player:get_player_name() .. - " moves stuff in chest at " .. minetest.pos_to_string(pos)) + if (from_list ~= "pro" and to_list ~= "pro") or get_is_player_pro(player) then + return count + else + return 0 + end + end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if listname ~= "pro" or get_is_player_pro(player) then + return stack:get_count() + else + return 0 + end + end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if listname ~= "pro" or get_is_player_pro(player) then + return stack:get_count() + else + return 0 + end + end, + can_dig = function(pos, player) + return false end, on_metadata_inventory_put = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. diff --git a/mods/ctf_team_base/textures/ctf_team_base_pro_only.png b/mods/ctf_team_base/textures/ctf_team_base_pro_only.png new file mode 100644 index 0000000000000000000000000000000000000000..ae5a52f33d8161c64f7de6931bc5183ea9c82c63 GIT binary patch literal 140 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPt7q>W{)VHs5)PO>go-U3d8t0Rzd?`#&U^OtDz~N@v dlOa5N`{sR5{n!PC{xWt~$(696|XAsYYy literal 0 HcmV?d00001