From 0f45a101b7a31d290ffa5ccc3be88eeca83604c5 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Wed, 6 Jan 2021 12:26:54 -0800 Subject: [PATCH] Make damage cobble hurt ranged weapon users --- mods/ctf/ctf_traps/init.lua | 30 +++++++++++++++++++++++------- mods/pvp/shooter | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/mods/ctf/ctf_traps/init.lua b/mods/ctf/ctf_traps/init.lua index af09333..db2f2a2 100644 --- a/mods/ctf/ctf_traps/init.lua +++ b/mods/ctf/ctf_traps/init.lua @@ -44,7 +44,9 @@ minetest.register_node("ctf_traps:damage_cobble", { is_ground_content = false, walkable = true, groups = {cracky=3, stone=2}, - on_dig = function(pos, node, digger) + on_dig = function(pos, node, digger, extra) + if not digger:is_player() then return end + local name = digger:get_player_name() if not digger then return @@ -52,20 +54,34 @@ minetest.register_node("ctf_traps:damage_cobble", { local digger_team = ctf.player(name).team local meta = minetest.get_meta(pos) - local placer_team = meta:get_string("placer") or "missing" + local placer = minetest.deserialize(meta:get_string("placer")) + + local placer_team = placer and placer.team or "missing" if digger_team ~= placer_team then - local hp = digger:get_hp() - digger:set_hp(hp - 7) + local placerobj = placer and minetest.get_player_by_name(placer.name) + + if placerobj then + digger:punch(placerobj, 10, {damage_groups = {fleshy = 7}}, vector.new(0, 1, 0)) + else + digger:set_hp(digger:get_hp() - 7) + end + minetest.remove_node(pos) return end - meta:set_string("placer", "") - return minetest.node_dig(pos, node, digger) + if not extra or extra.do_dig then + meta:set_string("placer", "") + return minetest.node_dig(pos, node, digger) + end end, after_place_node = function(pos, placer, itemstack, pointed_thing) local meta = minetest.get_meta(pos) local name = placer:get_player_name() - meta:set_string("placer", ctf.player(name).team) + + meta:set_string("placer", minetest.serialize({ + team = ctf.player(name).team, + name = name, + })) end }) diff --git a/mods/pvp/shooter b/mods/pvp/shooter index 6fd876d..e856150 160000 --- a/mods/pvp/shooter +++ b/mods/pvp/shooter @@ -1 +1 @@ -Subproject commit 6fd876d87c6c13e128a28c00b28e297d76d23a6e +Subproject commit e856150c13972825626bdadd2f80165a853408c1