From bfc17867c00757d41a30eb687e265c548d6aa37b Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Sat, 29 Jun 2024 22:34:09 +0330 Subject: [PATCH 1/4] add feature to steal from enemy teamchest while it is open in classic --- .../sounds/ctf_teams_teamchest_steal.ogg | Bin 0 -> 4241 bytes mods/ctf/ctf_teams/team_chest.lua | 257 +++++++++++++----- 2 files changed, 187 insertions(+), 70 deletions(-) create mode 100644 mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg diff --git a/mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg b/mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg new file mode 100644 index 0000000000000000000000000000000000000000..7688d9bef69f99db53e43be80c1ba98a719a3264 GIT binary patch literal 4241 zcmahMd0bORdVl}{5yNT3XrU&OAhrYp5)OrM2T~yLI2#c#UNK%FuC|3m5{^b-X&QoJ zWI>67f;P0E=&GoI2#6vkfJi~91ibKCz}m{r3+i_N+WF0!_r33&`R4m(z8A4+Q#8;A zAKDH)orr?|Et$*pmg?=6;>f&K0dgL)f5C_uZaS%6d zFJ8bnS0<{ZLuR5|NTkS!K28u{btX%)TU^fBiZO2Fg6!X1+V6_yG4jhqp>8vF;!S>g zZRczd{X&XGMt<#hagZOJff4uVhrl1`F zoNtu%^<9J;KM-!H2=lP>6Aa-#04(GSkyM2g{T3o6CP+!TKKA`d=gxXvch!l901z2v z7P!mWSSPmu0BnVaL>VtpZkA~Ci?HI{T78fO00x?&`A2&P%K~o2AbpMe!N2q*Id_px z9QqJGMMk=PfYZpbkhrvDeROgbo@sv6q>etU7_CS!FJr3cOB5ju`=o~@ zO?0h7(0yY}LG6anQAL7T8RXL{S}GDu=O9PbzT0I^C~jBx#CnBA8-$kE?JF)TY=Dqq z-Ik)VFcpMCn)a~|hoLwDs!BIJZk-?~tkBQui%s&ww_70;(Khj`0{4kU$ER~LT(2)K zw=m^C1$#%k**?f3)y{RoZ+hIt#7?AOJnk9a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&*6K_`6G`=0F!l<~|H(4rLd-D7p{#1WXaN4ZDz-FD( zAPkWWgC$=L`VtRj5^ma`%JlhmeyFnd{IZfPqjE*2tk3!W-m3x4ldB(WOrPw+2Lk~f zzpjhcV{#>{;$2?Gad*zE3)e8m52x_&X}wZ;7OBT4^Cl*>v9S>g?YK+K9a&G8{#{hL z&GyUBS46%XZrDpP%L$?#Q_=?pzH8q4kGovlPWzPkqt|0|uD?%RZLPU9aQp3;)%|tU zDB9aUmyP79Gag#BSKoi?8aw~gp{`d=`=7Mj&2ybPEYS>VH2YJv@;}UN-A|lYa1xAz zOZVS5eVG#1j0rIWEZXm)A#PE^%lo}=RLnMZUfQRAQfa80RuEaD!zP|e0+JZ-K(=x6Rf~%hj!>S_X_u_ zr}jUH%J1`rvCxba?M`= literal 0 HcmV?d00001 diff --git a/mods/ctf/ctf_teams/team_chest.lua b/mods/ctf/ctf_teams/team_chest.lua index cbbf48530b..b44f84b31b 100644 --- a/mods/ctf/ctf_teams/team_chest.lua +++ b/mods/ctf/ctf_teams/team_chest.lua @@ -54,13 +54,41 @@ local item_value = { } --]] +local open_chests = { + -- team_color = { + -- opener0, + -- opener1, + -- opener2, + -- ... + -- }, + -- ... +} +local function is_chest_open(team_name) + if open_chests[team_name] and #open_chests[team_name] ~= 0 then + return true + else + return false + end +end - +local function can_open_teamchest(teamname, pname) + if ctf_teams.get(pname) == teamname then + return true + elseif ctf_modebase.flag_captured[teamname] then + return true + elseif is_chest_open(teamname) and ctf_modebase:get_current_mode() == "classic" then + return true + else + return false + end +end local function get_chest_access(name) local current_mode = ctf_modebase:get_current_mode() - if not current_mode then return false, false end + if not current_mode then + return false, false + end return current_mode.get_chest_access(name) end @@ -79,17 +107,20 @@ function ctf_teams.is_allowed_in_team_chest(listname, stack, player) return true end +local TEAMCHEST_FORMSPEC_NAME = "ctf_teams:chest" + for _, team in ipairs(ctf_teams.teamlist) do if not ctf_teams.team[team].not_playing then local chestcolor = ctf_teams.team[team].color + local team_name = tostring(team) local function get_chest_texture(chest_side, color, mask, extra) return string.format( - "(default_chest_%s.png" .. - "^[colorize:%s:130)" .. - "^(default_chest_%s.png" .. - "^[mask:ctf_teams_chest_%s_mask.png" .. - "^[colorize:%s:60)" .. - "%s", + "(default_chest_%s.png" + .. "^[colorize:%s:130)" + .. "^(default_chest_%s.png" + .. "^[mask:ctf_teams_chest_%s_mask.png" + .. "^[colorize:%s:60)" + .. "%s", chest_side, color, chest_side, @@ -99,8 +130,27 @@ for _, team in ipairs(ctf_teams.teamlist) do ) end + minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= TEAMCHEST_FORMSPEC_NAME then + return + end + if fields.quit ~= "true" then + return + end + + local pname = player:get_player_name() + if pname == "" then + return + end + local pteam = ctf_teams.get(pname) + for idx, name in ipairs(open_chests[pteam]) do + if name == pname then + table.remove(open_chests, idx) + end + end + end) local def = { - description = HumanReadable(team).." Team's Chest", + description = HumanReadable(team) .. " Team's Chest", tiles = { get_chest_texture("top", chestcolor, "top"), get_chest_texture("top", chestcolor, "top"), @@ -110,7 +160,7 @@ for _, team in ipairs(ctf_teams.teamlist) do get_chest_texture("front", chestcolor, "side", "^ctf_teams_lock.png"), }, paramtype2 = "facedir", - groups = {immortal = 1, team_chest=1}, + groups = { immortal = 1, team_chest = 1 }, legacy_facedir_simple = true, is_ground_content = false, sounds = default.node_sound_wood_defaults(), @@ -118,7 +168,10 @@ for _, team in ipairs(ctf_teams.teamlist) do function def.on_construct(pos) local meta = minetest.get_meta(pos) - meta:set_string("infotext", string.format("%s Team's Chest", HumanReadable(team))) + meta:set_string( + "infotext", + string.format("%s Team's Chest", HumanReadable(team)) + ) local inv = meta:get_inventory() inv:set_size("main", 6 * 7) @@ -132,9 +185,8 @@ for _, team in ipairs(ctf_teams.teamlist) do function def.on_rightclick(pos, node, player) local name = player:get_player_name() - - local flag_captured = ctf_modebase.flag_captured[team] - if not flag_captured and team ~= ctf_teams.get(name) then + local flag_captured = ctf_modebase.flag_captured[team_name] + if not can_open_teamchest(team_name, name) then hud_events.new(player, { quick = true, text = "You're not on team " .. team, @@ -142,10 +194,21 @@ for _, team in ipairs(ctf_teams.teamlist) do }) return end + if not open_chests[team_name] then + open_chests[team_name] = {} + end + table.insert(open_chests[team_name], name) + minetest.after(30, function() + for idx, name2 in ipairs(open_chests[team_name]) do + if name2 == name then + table.remove(open_chests[team_name], idx) + end + end + end) local formspec = table.concat({ "size[10,12]", - default.get_hotbar_bg(1,7.85), + default.get_hotbar_bg(1, 7.85), "list[current_player;main;1,7.85;8,1;]", "list[current_player;main;1,9.08;8,3;8]", }, "") @@ -158,12 +221,15 @@ for _, team in ipairs(ctf_teams.teamlist) do end if reg_access ~= true then - formspec = formspec .. "label[0.75,3;" .. - minetest.formspec_escape(minetest.wrap_text( - reg_access or "You aren't allowed to access the team chest", - 60 - )) .. - "]" + formspec = formspec + .. "label[0.75,3;" + .. minetest.formspec_escape( + minetest.wrap_text( + reg_access or "You aren't allowed to access the team chest", + 60 + ) + ) + .. "]" minetest.show_formspec(name, "ctf_teams:no_access", formspec) return @@ -171,33 +237,56 @@ for _, team in ipairs(ctf_teams.teamlist) do local chestinv = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z - formspec = formspec .. "list[" .. chestinv .. ";main;0,0.3;6,7;]" .. - "background[6,-0.2;4.15,7.7;ctf_map_pro_section.png;false]" + formspec = formspec + .. "list[" + .. chestinv + .. ";main;0,0.3;6,7;]" + .. "background[6,-0.2;4.15,7.7;ctf_map_pro_section.png;false]" if pro_access == true then - formspec = formspec .. "list[" .. chestinv .. ";pro;6,0.3;4,7;]" .. - "listring[" .. chestinv ..";pro]" .. - "listring[" .. chestinv .. ";helper]" .. - "label[7,-0.2;" .. - minetest.formspec_escape("Pro players only") .. "]" + formspec = formspec + .. "list[" + .. chestinv + .. ";pro;6,0.3;4,7;]" + .. "listring[" + .. chestinv + .. ";pro]" + .. "listring[" + .. chestinv + .. ";helper]" + .. "label[7,-0.2;" + .. minetest.formspec_escape("Pro players only") + .. "]" else - formspec = formspec .. "label[6.5,2;" .. - minetest.formspec_escape(minetest.wrap_text( - pro_access or "You aren't allowed to access the pro section", - 20 - )) .. - "]" + formspec = formspec + .. "label[6.5,2;" + .. minetest.formspec_escape( + minetest.wrap_text( + pro_access or "You aren't allowed to access the pro section", + 20 + ) + ) + .. "]" end - formspec = formspec .. - "listring[" .. chestinv ..";main]" .. - "listring[current_player;main]" + formspec = formspec + .. "listring[" + .. chestinv + .. ";main]" + .. "listring[current_player;main]" - minetest.show_formspec(name, "ctf_teams:chest", formspec) + minetest.show_formspec(name, TEAMCHEST_FORMSPEC_NAME, formspec) end - function def.allow_metadata_inventory_move(pos, from_list, from_index, - to_list, to_index, count, player) + function def.allow_metadata_inventory_move( + pos, + from_list, + from_index, + to_list, + to_index, + count, + player + ) local name = player:get_player_name() if team ~= ctf_teams.get(name) then @@ -211,10 +300,13 @@ for _, team in ipairs(ctf_teams.teamlist) do local reg_access, pro_access = get_chest_access(name) - if reg_access == true and (pro_access == true or from_list ~= "pro" and to_list ~= "pro") then + if + reg_access == true + and (pro_access == true or from_list ~= "pro" and to_list ~= "pro") + then if to_list == "helper" then -- handle move & overflow - local chestinv = minetest.get_inventory({type = "node", pos = pos}) + local chestinv = minetest.get_inventory({ type = "node", pos = pos }) local playerinv = player:get_inventory() local stack = chestinv:get_stack(from_list, from_index) local leftover = playerinv:add_item("main", stack) @@ -252,7 +344,7 @@ for _, team in ipairs(ctf_teams.teamlist) do local reg_access, pro_access = get_chest_access(name) if reg_access == true and (pro_access == true or listname ~= "pro") then - local chestinv = minetest.get_inventory({type = "node", pos = pos}) + local chestinv = minetest.get_inventory({ type = "node", pos = pos }) if chestinv:room_for_item("pro", stack) then return stack:get_count() else @@ -281,7 +373,7 @@ for _, team in ipairs(ctf_teams.teamlist) do local name = player:get_player_name() - if team ~= ctf_teams.get(name) then + if not can_open_teamchest(team_name, name) then hud_events.new(player, { quick = true, text = "You're not on team " .. team, @@ -299,36 +391,61 @@ for _, team in ipairs(ctf_teams.teamlist) do end end - - function def.on_metadata_inventory_put(pos, listname, index, stack, player) - minetest.log("action", string.format("%s puts %s to team chest at %s", - player:get_player_name(), - stack:to_string(), - minetest.pos_to_string(pos) - )) - local meta = stack:get_meta() - local dropped_by = meta:get_string("dropped_by") - local pname = player:get_player_name() - if dropped_by ~= pname and dropped_by ~= "" then - local cur_mode = ctf_modebase:get_current_mode() - if pname and cur_mode then - --local score = (item_value[stack:get_name()] or 0) * stack:get_count() - cur_mode.recent_rankings.add(pname, { score = 1 }, false) + function def.on_metadata_inventory_put(pos, listname, index, stack, player) + minetest.log( + "action", + string.format( + "%s puts %s to team chest at %s", + player:get_player_name(), + stack:to_string(), + minetest.pos_to_string(pos) + ) + ) + local meta = stack:get_meta() + local dropped_by = meta:get_string("dropped_by") + local pname = player:get_player_name() + if dropped_by ~= pname and dropped_by ~= "" then + local cur_mode = ctf_modebase:get_current_mode() + if pname and cur_mode then + --local score = (item_value[stack:get_name()] or 0) * stack:get_count() + cur_mode.recent_rankings.add(pname, { score = 1 }, false) + end end + meta:set_string("dropped_by", "") + local inv = minetest.get_inventory({ type = "node", pos = pos }) + local stack_ = inv:get_stack(listname, index) + stack_:get_meta():set_string("dropped_by", "") + inv:set_stack(listname, index, stack_) end - meta:set_string("dropped_by", "") - local inv = minetest.get_inventory({ type="node", pos=pos }) - local stack_ = inv:get_stack(listname,index) - stack_:get_meta():set_string("dropped_by", "") - inv:set_stack(listname, index, stack_) - end function def.on_metadata_inventory_take(pos, listname, index, stack, player) - minetest.log("action", string.format("%s takes %s from team chest at %s", - player:get_player_name(), - stack:to_string(), - minetest.pos_to_string(pos) - )) + minetest.log( + "action", + string.format( + "%s takes %s from team chest at %s", + player:get_player_name(), + stack:to_string(), + minetest.pos_to_string(pos) + ) + ) + if ctf_teams.get(player:get_player_name()) ~= team_name then + for _i in 1, stack:get_count(), 1 do + minetest.sound_play( + { name = "ctf_teams_teamchest_steal" }, + { pos = pos, max_hearing_distance = 12 } + ) + end + for pname, pteam in pairs(ctf_teams.player_team) do + if pteam == team then + hud_events.new(pname, { + text = player:get_player_name() + .. " is stealing from your team's chest!", + color = "warning", + quick = true, + }) + end + end + end end minetest.register_node("ctf_teams:chest_" .. team, def) From a5da9930a71275297fdb8cee9afdcb70262c8cba Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Sun, 30 Jun 2024 16:43:46 +0330 Subject: [PATCH 2/4] dedicated mod for ctf team items --- mods/ctf/ctf_teamitems/init.lua | 1 + mods/ctf/ctf_teamitems/mod.conf | 2 + .../sounds/ctf_teamitems_teamchest_steal.ogg} | Bin .../team_chest.lua | 41 +++++++------ .../team_door.lua | 54 ++++++++++++------ .../ctf_teamitems_chest_side_mask.png} | Bin .../ctf_teamitems_chest_top_mask.png} | Bin .../textures/ctf_teamitems_door_steel.png} | Bin .../ctf_teamitems_door_steel_mask.png} | Bin .../textures/ctf_teamitems_lock.png} | Bin .../textures/license.txt | 10 ++-- mods/ctf/ctf_teams/init.lua | 38 +++++++----- 12 files changed, 89 insertions(+), 57 deletions(-) create mode 100644 mods/ctf/ctf_teamitems/init.lua create mode 100644 mods/ctf/ctf_teamitems/mod.conf rename mods/ctf/{ctf_teams/sounds/ctf_teams_teamchest_steal.ogg => ctf_teamitems/sounds/ctf_teamitems_teamchest_steal.ogg} (100%) rename mods/ctf/{ctf_teams => ctf_teamitems}/team_chest.lua (91%) rename mods/ctf/{ctf_teams => ctf_teamitems}/team_door.lua (51%) rename mods/ctf/{ctf_teams/textures/ctf_teams_chest_side_mask.png => ctf_teamitems/textures/ctf_teamitems_chest_side_mask.png} (100%) rename mods/ctf/{ctf_teams/textures/ctf_teams_chest_top_mask.png => ctf_teamitems/textures/ctf_teamitems_chest_top_mask.png} (100%) rename mods/ctf/{ctf_teams/textures/ctf_teams_door_steel.png => ctf_teamitems/textures/ctf_teamitems_door_steel.png} (100%) rename mods/ctf/{ctf_teams/textures/ctf_teams_door_steel_mask.png => ctf_teamitems/textures/ctf_teamitems_door_steel_mask.png} (100%) rename mods/ctf/{ctf_teams/textures/ctf_teams_lock.png => ctf_teamitems/textures/ctf_teamitems_lock.png} (100%) rename mods/ctf/{ctf_teams => ctf_teamitems}/textures/license.txt (55%) diff --git a/mods/ctf/ctf_teamitems/init.lua b/mods/ctf/ctf_teamitems/init.lua new file mode 100644 index 0000000000..ba801352b1 --- /dev/null +++ b/mods/ctf/ctf_teamitems/init.lua @@ -0,0 +1 @@ +ctf_core.include_files("team_chest.lua", "team_door.lua") diff --git a/mods/ctf/ctf_teamitems/mod.conf b/mods/ctf/ctf_teamitems/mod.conf new file mode 100644 index 0000000000..8ca904e3fb --- /dev/null +++ b/mods/ctf/ctf_teamitems/mod.conf @@ -0,0 +1,2 @@ +name = ctf_teamitems +depends = ctf_core, ctf_modebase, ctf_teams diff --git a/mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg b/mods/ctf/ctf_teamitems/sounds/ctf_teamitems_teamchest_steal.ogg similarity index 100% rename from mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg rename to mods/ctf/ctf_teamitems/sounds/ctf_teamitems_teamchest_steal.ogg diff --git a/mods/ctf/ctf_teams/team_chest.lua b/mods/ctf/ctf_teamitems/team_chest.lua similarity index 91% rename from mods/ctf/ctf_teams/team_chest.lua rename to mods/ctf/ctf_teamitems/team_chest.lua index b44f84b31b..325af61ebf 100644 --- a/mods/ctf/ctf_teams/team_chest.lua +++ b/mods/ctf/ctf_teamitems/team_chest.lua @@ -77,7 +77,7 @@ local function can_open_teamchest(teamname, pname) return true elseif ctf_modebase.flag_captured[teamname] then return true - elseif is_chest_open(teamname) and ctf_modebase:get_current_mode() == "classic" then + elseif is_chest_open(teamname) and ctf_modebase.current_mode == "classic" then return true else return false @@ -107,7 +107,7 @@ function ctf_teams.is_allowed_in_team_chest(listname, stack, player) return true end -local TEAMCHEST_FORMSPEC_NAME = "ctf_teams:chest" +local TEAMCHEST_FORMSPEC_NAME = "ctf_teamitemss:chest" for _, team in ipairs(ctf_teams.teamlist) do if not ctf_teams.team[team].not_playing then @@ -118,7 +118,7 @@ for _, team in ipairs(ctf_teams.teamlist) do "(default_chest_%s.png" .. "^[colorize:%s:130)" .. "^(default_chest_%s.png" - .. "^[mask:ctf_teams_chest_%s_mask.png" + .. "^[mask:ctf_teamitems_chest_%s_mask.png" .. "^[colorize:%s:60)" .. "%s", chest_side, @@ -143,7 +143,7 @@ for _, team in ipairs(ctf_teams.teamlist) do return end local pteam = ctf_teams.get(pname) - for idx, name in ipairs(open_chests[pteam]) do + for idx, name in ipairs(open_chests[pteam] or {}) do if name == pname then table.remove(open_chests, idx) end @@ -157,7 +157,7 @@ for _, team in ipairs(ctf_teams.teamlist) do get_chest_texture("side", chestcolor, "side"), get_chest_texture("side", chestcolor, "side"), get_chest_texture("side", chestcolor, "side"), - get_chest_texture("front", chestcolor, "side", "^ctf_teams_lock.png"), + get_chest_texture("front", chestcolor, "side", "^ctf_teamitems_lock.png"), }, paramtype2 = "facedir", groups = { immortal = 1, team_chest = 1 }, @@ -186,6 +186,7 @@ for _, team in ipairs(ctf_teams.teamlist) do function def.on_rightclick(pos, node, player) local name = player:get_player_name() local flag_captured = ctf_modebase.flag_captured[team_name] + minetest.log("info", "open_chests" .. minetest.serialize(open_chests)) if not can_open_teamchest(team_name, name) then hud_events.new(player, { quick = true, @@ -194,17 +195,19 @@ for _, team in ipairs(ctf_teams.teamlist) do }) return end - if not open_chests[team_name] then - open_chests[team_name] = {} - end - table.insert(open_chests[team_name], name) - minetest.after(30, function() - for idx, name2 in ipairs(open_chests[team_name]) do - if name2 == name then - table.remove(open_chests[team_name], idx) - end + if ctf_teams.get(name) == team_name then + if not open_chests[team_name] then + open_chests[team_name] = {} end - end) + table.insert(open_chests[team_name], name) + minetest.after(30, function() + for idx, name2 in ipairs(open_chests[team_name]) do + if name2 == name then + table.remove(open_chests[team_name], idx) + end + end + end) + end local formspec = table.concat({ "size[10,12]", @@ -231,7 +234,7 @@ for _, team in ipairs(ctf_teams.teamlist) do ) .. "]" - minetest.show_formspec(name, "ctf_teams:no_access", formspec) + minetest.show_formspec(name, "ctf_teamitems:no_access", formspec) return end @@ -429,9 +432,9 @@ for _, team in ipairs(ctf_teams.teamlist) do ) ) if ctf_teams.get(player:get_player_name()) ~= team_name then - for _i in 1, stack:get_count(), 1 do + for _i = 1, stack:get_count(), 0 do minetest.sound_play( - { name = "ctf_teams_teamchest_steal" }, + { name = "ctf_teamitems_teamchest_steal" }, { pos = pos, max_hearing_distance = 12 } ) end @@ -448,6 +451,6 @@ for _, team in ipairs(ctf_teams.teamlist) do end end - minetest.register_node("ctf_teams:chest_" .. team, def) + minetest.register_node("ctf_teamitems:chest_" .. team, def) end end diff --git a/mods/ctf/ctf_teams/team_door.lua b/mods/ctf/ctf_teamitems/team_door.lua similarity index 51% rename from mods/ctf/ctf_teams/team_door.lua rename to mods/ctf/ctf_teamitems/team_door.lua index 7974da3d06..51c20e70f1 100644 --- a/mods/ctf/ctf_teams/team_door.lua +++ b/mods/ctf/ctf_teamitems/team_door.lua @@ -1,8 +1,8 @@ -doors.register("ctf_teams:door_steel", { - tiles = {{name = "doors_door_steel.png", backface_culling = true}}, +doors.register("ctf_teamitems:door_steel", { + tiles = { { name = "doors_door_steel.png", backface_culling = true } }, description = "Team Door", inventory_image = "doors_item_steel.png", - groups = {node = 1, cracky = 1, level = 2}, + groups = { node = 1, cracky = 1, level = 2 }, sounds = default.node_sound_metal_defaults(), sound_open = "doors_steel_door_open", sound_close = "doors_steel_door_close", @@ -10,21 +10,30 @@ doors.register("ctf_teams:door_steel", { gain_close = 0.2, }) -local old_on_place = minetest.registered_craftitems["ctf_teams:door_steel"].on_place -minetest.override_item("ctf_teams:door_steel", { +local old_on_place = minetest.registered_craftitems["ctf_teamitems:door_steel"].on_place +minetest.override_item("ctf_teamitems:door_steel", { on_place = function(itemstack, placer, pointed_thing) local pteam = ctf_teams.get(placer) if pteam then - if not ctf_core.pos_inside(pointed_thing.above, ctf_teams.get_team_territory(pteam)) then - minetest.chat_send_player(placer:get_player_name(), "You can only place team doors in your own territory!") + if + not ctf_core.pos_inside( + pointed_thing.above, + ctf_teams.get_team_territory(pteam) + ) + then + minetest.chat_send_player( + placer:get_player_name(), + "You can only place team doors in your own territory!" + ) return itemstack end - local newitemstack = ItemStack("ctf_teams:door_steel_"..pteam) + local newitemstack = ItemStack("ctf_teamitems:door_steel_" .. pteam) newitemstack:set_count(itemstack:get_count()) - local item = minetest.registered_craftitems["ctf_teams:door_steel_" .. pteam] + local item = + minetest.registered_craftitems["ctf_teamitems:door_steel_" .. pteam] local result = item.on_place(newitemstack, placer, pointed_thing) if result then @@ -35,14 +44,14 @@ minetest.override_item("ctf_teams:door_steel", { end return old_on_place(itemstack, placer, pointed_thing) - end + end, }) local old_handle = minetest.handle_node_drops minetest.handle_node_drops = function(pos, drops, digger) for i, item in ipairs(drops) do - if item:match("ctf_teams:door_steel_") then - drops[i] = "ctf_teams:door_steel" + if item:match("ctf_teamitems:door_steel_") then + drops[i] = "ctf_teamitems:door_steel" end end @@ -50,14 +59,21 @@ minetest.handle_node_drops = function(pos, drops, digger) end for team, def in pairs(ctf_teams.team) do - local doorname = "ctf_teams:door_steel_%s" - local modifier = "^[colorize:%s:190)^(ctf_teams_door_steel.png^[mask:ctf_teams_door_steel_mask.png^[colorize:%s:42)" + local doorname = "ctf_teamitems:door_steel_%s" + local modifier = + "^[colorize:%s:190)^(ctf_teams_door_steel.png^[mask:ctf_teams_door_steel_mask.png^[colorize:%s:42)" doors.register(doorname:format(team), { - tiles = {{name = "(ctf_teams_door_steel.png"..modifier:format(def.color, def.color), backface_culling = true}}, + tiles = { + { + name = "(ctf_teamitems_door_steel.png" + .. modifier:format(def.color, def.color), + backface_culling = true, + }, + }, description = "Steel Team Door", - inventory_image = "doors_item_steel.png^[multiply:"..def.color, - groups = {node = 1, cracky = 1, level = 2}, + inventory_image = "doors_item_steel.png^[multiply:" .. def.color, + groups = { node = 1, cracky = 1, level = 2 }, sounds = default.node_sound_metal_defaults(), sound_open = "doors_steel_door_open", sound_close = "doors_steel_door_close", @@ -71,8 +87,8 @@ default.can_interact_with_node = function(player, pos) local pteam = ctf_teams.get(player) local name = minetest.get_node(pos).name - if name:find("ctf_teams:") and pteam then - if pteam == name:match("ctf_teams:door_steel_(.-)[_$]") then + if name:find("ctf_teamitems:") and pteam then + if pteam == name:match("ctf_teamitems:door_steel_(.-)[_$]") then return true else return false diff --git a/mods/ctf/ctf_teams/textures/ctf_teams_chest_side_mask.png b/mods/ctf/ctf_teamitems/textures/ctf_teamitems_chest_side_mask.png similarity index 100% rename from mods/ctf/ctf_teams/textures/ctf_teams_chest_side_mask.png rename to mods/ctf/ctf_teamitems/textures/ctf_teamitems_chest_side_mask.png diff --git a/mods/ctf/ctf_teams/textures/ctf_teams_chest_top_mask.png b/mods/ctf/ctf_teamitems/textures/ctf_teamitems_chest_top_mask.png similarity index 100% rename from mods/ctf/ctf_teams/textures/ctf_teams_chest_top_mask.png rename to mods/ctf/ctf_teamitems/textures/ctf_teamitems_chest_top_mask.png diff --git a/mods/ctf/ctf_teams/textures/ctf_teams_door_steel.png b/mods/ctf/ctf_teamitems/textures/ctf_teamitems_door_steel.png similarity index 100% rename from mods/ctf/ctf_teams/textures/ctf_teams_door_steel.png rename to mods/ctf/ctf_teamitems/textures/ctf_teamitems_door_steel.png diff --git a/mods/ctf/ctf_teams/textures/ctf_teams_door_steel_mask.png b/mods/ctf/ctf_teamitems/textures/ctf_teamitems_door_steel_mask.png similarity index 100% rename from mods/ctf/ctf_teams/textures/ctf_teams_door_steel_mask.png rename to mods/ctf/ctf_teamitems/textures/ctf_teamitems_door_steel_mask.png diff --git a/mods/ctf/ctf_teams/textures/ctf_teams_lock.png b/mods/ctf/ctf_teamitems/textures/ctf_teamitems_lock.png similarity index 100% rename from mods/ctf/ctf_teams/textures/ctf_teams_lock.png rename to mods/ctf/ctf_teamitems/textures/ctf_teamitems_lock.png diff --git a/mods/ctf/ctf_teams/textures/license.txt b/mods/ctf/ctf_teamitems/textures/license.txt similarity index 55% rename from mods/ctf/ctf_teams/textures/license.txt rename to mods/ctf/ctf_teamitems/textures/license.txt index ba3d09c36f..6d5abed15c 100644 --- a/mods/ctf/ctf_teams/textures/license.txt +++ b/mods/ctf/ctf_teamitems/textures/license.txt @@ -1,8 +1,8 @@ See mods/mtg/mtg_default/license.txt for license of the textures the following were derived from: - ctf_teams_chest_side_mask.png - ctf_teams_chest_top_mask.png - ctf_teams_lock.png + ctf_teamitems_chest_side_mask.png + ctf_teamitems_chest_top_mask.png + ctf_teamitems_lock.png See mods/mtg/mtg_doors/license.txt for license of the textures the following were derived from: - ctf_teams_door_steel_mask.png - ctf_teams_door_steel.png + ctf_teamitems_door_steel_mask.png + ctf_teamitems_door_steel.png diff --git a/mods/ctf/ctf_teams/init.lua b/mods/ctf/ctf_teams/init.lua index d282d746e8..450d7365b9 100644 --- a/mods/ctf/ctf_teams/init.lua +++ b/mods/ctf/ctf_teams/init.lua @@ -44,7 +44,7 @@ ctf_teams = { for team, def in pairs(ctf_teams.team) do table.insert(ctf_teams.teamlist, team) - ctf_teams.team[team].color_hex = tonumber("0x"..def.color:sub(2)) + ctf_teams.team[team].color_hex = tonumber("0x" .. def.color:sub(2)) end minetest.register_privilege("ctf_team_admin", { @@ -53,13 +53,7 @@ minetest.register_privilege("ctf_team_admin", { give_to_admin = false, }) -ctf_core.include_files( - "functions.lua", - "commands.lua", - "register.lua", - "team_chest.lua", - "team_door.lua" -) +ctf_core.include_files("functions.lua", "commands.lua", "register.lua") minetest.register_on_mods_loaded(function() local old_join_func = minetest.send_join_message @@ -90,8 +84,11 @@ minetest.register_on_mods_loaded(function() else local tcolor = ctf_teams.team[pteam].color - minetest.chat_send_all(string.format("*** %s joined the game.", - minetest.colorize(tcolor, name)) + minetest.chat_send_all( + string.format( + "*** %s joined the game.", + minetest.colorize(tcolor, name) + ) ) end end) @@ -107,10 +104,23 @@ minetest.register_on_mods_loaded(function() local tcolor = ctf_teams.team[pteam].color - minetest.chat_send_all(string.format("*** %s left the game%s.", - minetest.colorize(tcolor, player:get_player_name()), - timed_out and " (timed out)" or "" - )) + minetest.chat_send_all( + string.format( + "*** %s left the game%s.", + minetest.colorize(tcolor, player:get_player_name()), + timed_out and " (timed out)" or "" + ) + ) end end) end) + +for team, _ in pairs(ctf_teams.team) do + local new_chestname = string.format("ctf_teams:chest_%s", team) + local new_doorname = string.format("ctf_teams:door_steel_%s", team) + local old_chestname = string.format("ctf_teamitems:chest_%s", team) + local old_doorname = string.format("ctf_teamitems:door_steel_%s", team) + minetest.register_alias(new_chestname, old_chestname) + minetest.register_alias(new_doorname, old_doorname) + minetest.register_alias("ctf_teams:door_steel", "ctf_teamitems:door_steel") +end From edb95e3cc5cb6a4e1983666fc5e8812f3fb7b98a Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Mon, 1 Jul 2024 14:12:41 +0330 Subject: [PATCH 3/4] solve problem with teamchest closing --- mods/ctf/ctf_teamitems/team_chest.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ctf/ctf_teamitems/team_chest.lua b/mods/ctf/ctf_teamitems/team_chest.lua index 325af61ebf..6af80940fc 100644 --- a/mods/ctf/ctf_teamitems/team_chest.lua +++ b/mods/ctf/ctf_teamitems/team_chest.lua @@ -145,7 +145,7 @@ for _, team in ipairs(ctf_teams.teamlist) do local pteam = ctf_teams.get(pname) for idx, name in ipairs(open_chests[pteam] or {}) do if name == pname then - table.remove(open_chests, idx) + table.remove(open_chests[pteam], idx) end end end) From 11728aa7db8fcd12eb7865f3760b37ae3dd64947 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Tue, 9 Jul 2024 21:07:20 +0330 Subject: [PATCH 4/4] fix bug with teamdoor textures --- mods/ctf/ctf_teamitems/team_door.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ctf/ctf_teamitems/team_door.lua b/mods/ctf/ctf_teamitems/team_door.lua index 51c20e70f1..9ae4397a02 100644 --- a/mods/ctf/ctf_teamitems/team_door.lua +++ b/mods/ctf/ctf_teamitems/team_door.lua @@ -61,7 +61,7 @@ end for team, def in pairs(ctf_teams.team) do local doorname = "ctf_teamitems:door_steel_%s" local modifier = - "^[colorize:%s:190)^(ctf_teams_door_steel.png^[mask:ctf_teams_door_steel_mask.png^[colorize:%s:42)" + "^[colorize:%s:190)^(ctf_teamitems_door_steel.png^[mask:ctf_teamitems_door_steel_mask.png^[colorize:%s:42)" doors.register(doorname:format(team), { tiles = {