Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making spikes have perks for the placer #1135

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
33 changes: 29 additions & 4 deletions mods/ctf/ctf_map/ctf_traps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
LoneWolfHT marked this conversation as resolved.
Show resolved Hide resolved
groups = {cracky=1, level=2},
selection_box = {
type = "fixed",
Expand All @@ -46,8 +46,10 @@ 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

Expand All @@ -57,6 +59,8 @@ minetest.register_node("ctf_map:spike", {
local result = minetest.item_place(newitemstack, placer, pointed_thing, 34)

if result then
minetest.get_meta(pointed_thing.above):set_string("placer", pname)

itemstack:set_count(result:get_count())
end

Expand All @@ -80,15 +84,21 @@ 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 = {
type = "fixed",
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 item, pos = minetest.item_place(itemstack, placer, pointed_thing, 34)
if item then
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
})
end
Expand All @@ -100,6 +110,21 @@ 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
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 pteam ~= team then
local placer = minetest.get_player_by_name(pname)
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 -7, false
Comment on lines +121 to +124
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the return value heal any damage dealt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I don't think this code is reachable unless they aren't damaged by a spike

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I don't think this code is reachable unless they aren't damaged by a spike

how so? Are you talking about L121 or L123-124?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

110: if team and reason.node == string.format("ctf_map:spike_%s", team) then

end
end
end
end

return hp_change
Expand Down
1 change: 1 addition & 0 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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)
Expand Down
Loading