From 19a01d8557aa1e4a80b0b0b9e5f6cb5e84a7c168 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 10:11:28 +0330 Subject: [PATCH 01/13] make spikes have perk for the placer --- mods/ctf/ctf_map/ctf_traps.lua | 29 ++++++++++++++++++++++++++--- mods/ctf/ctf_modebase/features.lua | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index acb580a8c..84aa269e8 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -36,7 +36,7 @@ minetest.register_node("ctf_map:spike", { paramtype2 = "meshoptions", sunlight_propagates = true, walkable = false, - damage_per_second = 7, + damage_per_second = 5, groups = {cracky=1, level=2}, selection_box = { type = "fixed", @@ -80,7 +80,7 @@ for _, team in ipairs(ctf_teams.teamlist) do paramtype2 = "meshoptions", sunlight_propagates = true, walkable = false, - damage_per_second = 7, + damage_per_second = 5, groups = {cracky=1, level=2}, drop = "ctf_map:spike", selection_box = { @@ -88,7 +88,13 @@ for _, team in ipairs(ctf_teams.teamlist) do fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, }, on_place = function(itemstack, placer, pointed_thing) - return minetest.item_place(itemstack, placer, pointed_thing, 34) + local itemstack, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) + local meta = minetest.get_meta(pos) + local pname = placer:get_player_name() + if pname ~= "" then + meta:set_string("placer", pname) + end + return itemstack, pos end }) end @@ -100,6 +106,23 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) if team and reason.node == string.format("ctf_map:spike_%s", team) then return 0, true end + local damaged = false + minetest.chat_send_all(minetest.serialize(reason)) + if reason.node_pos then + local meta = minetest.get_meta(reason.node_pos) + local pname = meta:get_string("placer") + minetest.chat_send_all(pname) + if pname ~= "" then + local placer = minetest.get_player_by_name(pname) + if placer then + player:punch(placer, 10, { fleshy = 5, spike = 1}) + damaged = true + end + end + end + if not damaged then + hp_change = hp_change - 5 + end end return hp_change diff --git a/mods/ctf/ctf_modebase/features.lua b/mods/ctf/ctf_modebase/features.lua index e3bdd4924..1f8e34d7a 100644 --- a/mods/ctf/ctf_modebase/features.lua +++ b/mods/ctf/ctf_modebase/features.lua @@ -18,6 +18,7 @@ local damage_group_textures = { knockback_grenade = "ctf_mode_nade_fight_knockback_grenade.png", black_hole_grenade = "ctf_mode_nade_fight_black_hole_grenade.png", damage_cobble = "ctf_map_damage_cobble.png", + spike = "ctf_map_spike.png", } local function get_weapon_image(hitter, tool_capabilities) From 16f31ac439df5477c8278a5fd804c4868bf20303 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 19:59:22 +0330 Subject: [PATCH 02/13] fix shadowing fix --- mods/ctf/ctf_map/ctf_traps.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 84aa269e8..5ecc3b538 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -88,13 +88,13 @@ for _, team in ipairs(ctf_teams.teamlist) do fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, }, on_place = function(itemstack, placer, pointed_thing) - local itemstack, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) + local item, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) local meta = minetest.get_meta(pos) local pname = placer:get_player_name() if pname ~= "" then meta:set_string("placer", pname) end - return itemstack, pos + return item, pos end }) end From 87d168a24b8aef1cd92bc02e462b66127c01d930 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 20:25:25 +0330 Subject: [PATCH 03/13] Update mods/ctf/ctf_map/ctf_traps.lua Co-authored-by: LoneWolfHT --- mods/ctf/ctf_map/ctf_traps.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 5ecc3b538..c908f4e6e 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -111,7 +111,6 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) if reason.node_pos then local meta = minetest.get_meta(reason.node_pos) local pname = meta:get_string("placer") - minetest.chat_send_all(pname) if pname ~= "" then local placer = minetest.get_player_by_name(pname) if placer then From dc9328cac3a58611061222334d7e8ee9d515985a Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 20:25:31 +0330 Subject: [PATCH 04/13] Update mods/ctf/ctf_map/ctf_traps.lua Co-authored-by: LoneWolfHT --- mods/ctf/ctf_map/ctf_traps.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index c908f4e6e..2d75e93d6 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -107,7 +107,6 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) return 0, true end local damaged = false - minetest.chat_send_all(minetest.serialize(reason)) if reason.node_pos then local meta = minetest.get_meta(reason.node_pos) local pname = meta:get_string("placer") From f20efbe4411c88f8320818fedecc7d23047b28f6 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 20:25:45 +0330 Subject: [PATCH 05/13] Update mods/ctf/ctf_map/ctf_traps.lua Co-authored-by: LoneWolfHT --- mods/ctf/ctf_map/ctf_traps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 2d75e93d6..5a9836fed 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -114,7 +114,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) local placer = minetest.get_player_by_name(pname) if placer then player:punch(placer, 10, { fleshy = 5, spike = 1}) - damaged = true + return hp_change end end end From d8307ecfb22e8d70cc174ff6eb8ce3e2f2dadee7 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 20:25:52 +0330 Subject: [PATCH 06/13] Update mods/ctf/ctf_map/ctf_traps.lua Co-authored-by: LoneWolfHT --- mods/ctf/ctf_map/ctf_traps.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 5a9836fed..15a22a72b 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -106,7 +106,6 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) if team and reason.node == string.format("ctf_map:spike_%s", team) then return 0, true end - local damaged = false if reason.node_pos then local meta = minetest.get_meta(reason.node_pos) local pname = meta:get_string("placer") From 09608699d5371769fbf8c8ad5d5ba45e08cd67ad Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Wed, 12 Apr 2023 10:02:15 -0700 Subject: [PATCH 07/13] Update ctf_traps.lua --- mods/ctf/ctf_map/ctf_traps.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 15a22a72b..5eb561e4d 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -36,7 +36,7 @@ minetest.register_node("ctf_map:spike", { paramtype2 = "meshoptions", sunlight_propagates = true, walkable = false, - damage_per_second = 5, + damage_per_second = 7, groups = {cracky=1, level=2}, selection_box = { type = "fixed", @@ -80,7 +80,7 @@ for _, team in ipairs(ctf_teams.teamlist) do paramtype2 = "meshoptions", sunlight_propagates = true, walkable = false, - damage_per_second = 5, + damage_per_second = 7, groups = {cracky=1, level=2}, drop = "ctf_map:spike", selection_box = { @@ -112,14 +112,11 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) if pname ~= "" then local placer = minetest.get_player_by_name(pname) if placer then - player:punch(placer, 10, { fleshy = 5, spike = 1}) - return hp_change + player:punch(placer, 1, { fleshy = 7, spike = 1}) + return 0 end end end - if not damaged then - hp_change = hp_change - 5 - end end return hp_change From 22d38ba7f079362324137eedc1726cdb18482ffe Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Fri, 28 Jul 2023 22:20:08 -0700 Subject: [PATCH 08/13] Update ctf_traps.lua --- mods/ctf/ctf_map/ctf_traps.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 5eb561e4d..c947ea9fa 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -46,17 +46,21 @@ minetest.register_node("ctf_map:spike", { local pteam = ctf_teams.get(placer) if pteam then + local pname = placer:get_player_name() + 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 spikes in your own territory!") + minetest.chat_send_player(pname, "You can only place spikes in your own territory!") return itemstack end local newitemstack = ItemStack("ctf_map:spike_"..pteam) newitemstack:set_count(itemstack:get_count()) - local result = minetest.item_place(newitemstack, placer, pointed_thing, 34) + local result, pos = minetest.item_place(newitemstack, placer, pointed_thing, 34) if result then + minetest.get_meta(pos):set_string("placer", pname) + itemstack:set_count(result:get_count()) end @@ -89,11 +93,11 @@ for _, team in ipairs(ctf_teams.teamlist) do }, on_place = function(itemstack, placer, pointed_thing) local item, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) - local meta = minetest.get_meta(pos) - local pname = placer:get_player_name() - if pname ~= "" then - meta:set_string("placer", pname) + + if item then + minetest.get_meta(pos):set_string("placer", placer:get_player_name()) end + return item, pos end }) From c449e3a7f48b31c69b72df38987fd76c1a162ce7 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Sat, 29 Jul 2023 08:05:30 -0700 Subject: [PATCH 09/13] Update ctf_traps.lua --- mods/ctf/ctf_map/ctf_traps.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index c947ea9fa..e068fe7b7 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -56,10 +56,10 @@ minetest.register_node("ctf_map:spike", { local newitemstack = ItemStack("ctf_map:spike_"..pteam) newitemstack:set_count(itemstack:get_count()) - local result, pos = minetest.item_place(newitemstack, placer, pointed_thing, 34) + local result = minetest.item_place(newitemstack, placer, pointed_thing, 34) if result then - minetest.get_meta(pos):set_string("placer", pname) + minetest.get_meta(pointed_thing.above):set_string("placer", pname) itemstack:set_count(result:get_count()) end @@ -95,7 +95,7 @@ for _, team in ipairs(ctf_teams.teamlist) do local item, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) if item then - minetest.get_meta(pos):set_string("placer", placer:get_player_name()) + minetest.get_meta(pointed_thing.above):set_string("placer", placer:get_player_name()) end return item, pos @@ -116,7 +116,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) if pname ~= "" then local placer = minetest.get_player_by_name(pname) if placer then - player:punch(placer, 1, { fleshy = 7, spike = 1}) + player:punch(placer, 1, {damage_groups = {fleshy = 7, spike = 1}}) return 0 end end From dd2794feaf46836d4c227aaa4aa9671cf1ea78ee Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 10:11:28 +0330 Subject: [PATCH 10/13] make spikes have perk for the placer --- mods/ctf/ctf_map/ctf_traps.lua | 29 ++++++++++++++++++++++++++--- mods/ctf/ctf_modebase/features.lua | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index acb580a8c..84aa269e8 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -36,7 +36,7 @@ minetest.register_node("ctf_map:spike", { paramtype2 = "meshoptions", sunlight_propagates = true, walkable = false, - damage_per_second = 7, + damage_per_second = 5, groups = {cracky=1, level=2}, selection_box = { type = "fixed", @@ -80,7 +80,7 @@ for _, team in ipairs(ctf_teams.teamlist) do paramtype2 = "meshoptions", sunlight_propagates = true, walkable = false, - damage_per_second = 7, + damage_per_second = 5, groups = {cracky=1, level=2}, drop = "ctf_map:spike", selection_box = { @@ -88,7 +88,13 @@ for _, team in ipairs(ctf_teams.teamlist) do fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, }, on_place = function(itemstack, placer, pointed_thing) - return minetest.item_place(itemstack, placer, pointed_thing, 34) + local itemstack, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) + local meta = minetest.get_meta(pos) + local pname = placer:get_player_name() + if pname ~= "" then + meta:set_string("placer", pname) + end + return itemstack, pos end }) end @@ -100,6 +106,23 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) if team and reason.node == string.format("ctf_map:spike_%s", team) then return 0, true end + local damaged = false + minetest.chat_send_all(minetest.serialize(reason)) + if reason.node_pos then + local meta = minetest.get_meta(reason.node_pos) + local pname = meta:get_string("placer") + minetest.chat_send_all(pname) + if pname ~= "" then + local placer = minetest.get_player_by_name(pname) + if placer then + player:punch(placer, 10, { fleshy = 5, spike = 1}) + damaged = true + end + end + end + if not damaged then + hp_change = hp_change - 5 + end end return hp_change diff --git a/mods/ctf/ctf_modebase/features.lua b/mods/ctf/ctf_modebase/features.lua index f5dd62093..b2761d666 100644 --- a/mods/ctf/ctf_modebase/features.lua +++ b/mods/ctf/ctf_modebase/features.lua @@ -18,6 +18,7 @@ local damage_group_textures = { knockback_grenade = "ctf_mode_nade_fight_knockback_grenade.png", black_hole_grenade = "ctf_mode_nade_fight_black_hole_grenade.png", damage_cobble = "ctf_map_damage_cobble.png", + spike = "ctf_map_spike.png", } local function get_weapon_image(hitter, tool_capabilities) From dc9ff485bd73c0e809f8d163cddcf6ce2196958f Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Wed, 12 Apr 2023 19:59:22 +0330 Subject: [PATCH 11/13] fix shadowing fix --- mods/ctf/ctf_map/ctf_traps.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 84aa269e8..5ecc3b538 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -88,13 +88,13 @@ for _, team in ipairs(ctf_teams.teamlist) do fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, }, on_place = function(itemstack, placer, pointed_thing) - local itemstack, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) + local item, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) local meta = minetest.get_meta(pos) local pname = placer:get_player_name() if pname ~= "" then meta:set_string("placer", pname) end - return itemstack, pos + return item, pos end }) end From f81e6303a3cef945925e9ffadcb81eaebb949280 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Fri, 11 Aug 2023 15:07:41 +0330 Subject: [PATCH 12/13] remove debug logs --- mods/ctf/ctf_map/ctf_traps.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 5ecc3b538..6ad2ecb66 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -107,15 +107,15 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) return 0, true end local damaged = false - minetest.chat_send_all(minetest.serialize(reason)) if reason.node_pos then local meta = minetest.get_meta(reason.node_pos) local pname = meta:get_string("placer") - minetest.chat_send_all(pname) if pname ~= "" then local placer = minetest.get_player_by_name(pname) if placer then player:punch(placer, 10, { fleshy = 5, spike = 1}) + player:set_hp(player:get_hp() - 10) + end damaged = true end end From c4a9605ec779b3c37e7bd2e6c95a894fd39b7991 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Tue, 13 Feb 2024 21:57:01 +0330 Subject: [PATCH 13/13] better damage mechanism --- mods/ctf/ctf_map/ctf_traps.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 3f98a73c4..d68498c40 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -94,7 +94,9 @@ for _, team in ipairs(ctf_teams.teamlist) do on_place = function(itemstack, placer, pointed_thing) local item, pos = minetest.item_place(itemstack, placer, pointed_thing, 34) if item then - minetest.get_meta(pointed_thing.above):set_string("placer", placer:get_player_name()) + local pname = placer:get_player_name() + minetest.get_meta(pointed_thing.above):set_string("placer_team", ctf_teams.get(pname)) + minetest.get_meta(pointed_thing.above):set_string("placer", pname) end return item, pos end @@ -110,12 +112,16 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) end if reason.node_pos then local meta = minetest.get_meta(reason.node_pos) + local pteam = meta:get_string("placer_team") local pname = meta:get_string("placer") - if pname ~= "" then + if pteam ~= team then local placer = minetest.get_player_by_name(pname) - if placer then + if ctf_teams.get(pname) == team then + player:set_hp(player:get_hp() - 7) + return -7, false + elseif placer then player:punch(placer, 1, { fleshy = 7, spike = 1}) - return 0 + return -7, false end end end