From a7d2b5961f5d84836ca2c548b36e8d357212615e Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 12 Oct 2017 15:40:02 +0100 Subject: [PATCH] Remove the ability for enemies to access a team's chest --- mods/ctf_inventory/init.lua | 2 -- mods/ctf_team_base/init.lua | 37 ++++++++++++++++++++++++++++++++--- mods/random_messages/init.lua | 14 ++++++------- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/mods/ctf_inventory/init.lua b/mods/ctf_inventory/init.lua index ee235f2..57f0721 100644 --- a/mods/ctf_inventory/init.lua +++ b/mods/ctf_inventory/init.lua @@ -6,14 +6,12 @@ local items = { "* Look for guns, grenades and other resources in chests.", "* Guns can destroy blocks.", "* Good swords do more damage than guns, but need to be used at close range.", - "* If the match is getting boring, type /vote, then /yes to vote yes.", "* Use apples to replenish health.", "", minetest.colorize("#66a0ff", "Team Co-op"), "", "* Your team has a chest near your flag.", - " Be warned that other teams can steal from it.", "* Your team name is displayed in the top left.", " to talk with only your team, type: /t message", "", diff --git a/mods/ctf_team_base/init.lua b/mods/ctf_team_base/init.lua index f0cafe3..3d441bc 100644 --- a/mods/ctf_team_base/init.lua +++ b/mods/ctf_team_base/init.lua @@ -70,12 +70,19 @@ for _, color in pairs(colors) do inv:set_size("pro", 3*4) end, on_rightclick = function(pos, node, player) + local meta = minetest.get_meta(pos) + local owning_team = meta:get_string("owner_team") + if owning_team ~= ctf.player(player:get_player_name()).team then + minetest.chat_send_player(player:get_player_name(), "You're not on team " .. owning_team) + return + end + 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") .. "]" .. + "label[0,-0.2;" .. minetest.formspec_escape("Any team member can take from here") .. "]" .. default.gui_bg .. default.gui_bg_img .. default.gui_slots .. @@ -103,6 +110,13 @@ for _, color in pairs(colors) do allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local owning_team = meta:get_string("owner_team") + if owning_team ~= ctf.player(player:get_player_name()).team then + minetest.chat_send_player(player:get_player_name(), "You're not on team " .. owning_team) + return 0 + end + if (from_list ~= "pro" and to_list ~= "pro") or get_is_player_pro(player) then return count else @@ -110,6 +124,13 @@ for _, color in pairs(colors) do end end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local owning_team = meta:get_string("owner_team") + if owning_team ~= ctf.player(player:get_player_name()).team then + minetest.chat_send_player(player:get_player_name(), "You're not on team " .. owning_team) + return 0 + end + if listname ~= "pro" or get_is_player_pro(player) then return stack:get_count() else @@ -117,6 +138,13 @@ for _, color in pairs(colors) do end end, allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local owning_team = meta:get_string("owner_team") + if owning_team ~= ctf.player(player:get_player_name()).team then + minetest.chat_send_player(player:get_player_name(), "You're not on team " .. owning_team) + return 0 + end + if listname ~= "pro" or get_is_player_pro(player) then return stack:get_count() else @@ -178,11 +206,14 @@ minetest.register_on_generated(function(minp, maxp, seed) z = flag.z + dz } minetest.set_node(pos, chest) - local inv = minetest.get_inventory({type = "node", pos=pos}) + local meta = minetest.get_meta(pos) + meta:set_string("owner_team", tname) + local inv = meta:get_inventory() + inv:add_item("main", ItemStack("default:cobble 99")) inv:add_item("main", ItemStack("default:cobble 99")) inv:add_item("main", ItemStack("default:cobble 99")) inv:add_item("main", ItemStack("default:wood 99")) - inv:add_item("main", ItemStack("default:glass 10")) + inv:add_item("main", ItemStack("default:glass 5")) inv:add_item("main", ItemStack("default:torch 10")) end end diff --git a/mods/random_messages/init.lua b/mods/random_messages/init.lua index f56739e..6f46c93 100644 --- a/mods/random_messages/init.lua +++ b/mods/random_messages/init.lua @@ -48,9 +48,9 @@ end function random_messages.read_messages() random_messages.messages = { "To talk to only your team, start your messages with /t. For example, /t Hello team!", - "If the map is ruined, use /vote to start a new vote to skip the current match.", "Eat apples to restore health quickly.", - "You can steal items from the other team's chest." + "Steel swords do more damage than guns, but you need to be up close.", + "Gain more score by killing more than you die, or by capturing the flag." } end @@ -84,11 +84,11 @@ function random_messages.add_message(t) end function random_messages.save_messages() - local output = io.open(minetest.get_worldpath().."/random_messages","w") - for k,v in pairs(random_messages.messages) do - output:write(v .. "\n") - end - io.close(output) + local output = io.open(minetest.get_worldpath().."/random_messages","w") + for k,v in pairs(random_messages.messages) do + output:write(v .. "\n") + end + io.close(output) end --When server starts: