Make damage cobble hurt ranged weapon users

This commit is contained in:
LoneWolfHT 2021-01-06 12:26:54 -08:00
parent 355a171949
commit 0f45a101b7
2 changed files with 24 additions and 8 deletions

View file

@ -44,7 +44,9 @@ minetest.register_node("ctf_traps:damage_cobble", {
is_ground_content = false, is_ground_content = false,
walkable = true, walkable = true,
groups = {cracky=3, stone=2}, 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() local name = digger:get_player_name()
if not digger then if not digger then
return return
@ -52,20 +54,34 @@ minetest.register_node("ctf_traps:damage_cobble", {
local digger_team = ctf.player(name).team local digger_team = ctf.player(name).team
local meta = minetest.get_meta(pos) 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 if digger_team ~= placer_team then
local hp = digger:get_hp() local placerobj = placer and minetest.get_player_by_name(placer.name)
digger:set_hp(hp - 7)
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) minetest.remove_node(pos)
return return
end end
meta:set_string("placer", "") if not extra or extra.do_dig then
return minetest.node_dig(pos, node, digger) meta:set_string("placer", "")
return minetest.node_dig(pos, node, digger)
end
end, end,
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local name = placer:get_player_name() 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 end
}) })

@ -1 +1 @@
Subproject commit 6fd876d87c6c13e128a28c00b28e297d76d23a6e Subproject commit e856150c13972825626bdadd2f80165a853408c1