2020-11-28 18:13:52 +00:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
|
|
|
if reason.type ~= "punch" or not reason.object or not reason.object:is_player() then
|
|
|
|
return hp_change
|
|
|
|
end
|
2020-11-08 17:08:14 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
local class = ctf_classes.get(reason.object)
|
2020-10-14 03:00:21 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
if class.properties.melee_bonus and reason.object:get_wielded_item():get_name():find("sword") then
|
|
|
|
local change = hp_change - class.properties.melee_bonus
|
2020-11-08 18:09:15 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
if player:get_hp() + change <= 0 and player:get_hp() + hp_change > 0 then
|
|
|
|
local wielded_item = reason.object:get_wielded_item()
|
2020-10-14 03:00:21 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
for i = 1, #ctf.registered_on_killedplayer do
|
|
|
|
ctf.registered_on_killedplayer[i](
|
|
|
|
player:get_player_name(),
|
|
|
|
reason.object:get_player_name(),
|
|
|
|
wielded_item,
|
|
|
|
wielded_item:get_tool_capabilities()
|
|
|
|
)
|
|
|
|
end
|
2020-11-08 01:17:21 +00:00
|
|
|
end
|
2020-11-28 18:13:52 +00:00
|
|
|
|
|
|
|
return change
|
2020-10-13 15:42:41 +00:00
|
|
|
end
|
2020-11-28 18:13:52 +00:00
|
|
|
|
|
|
|
return hp_change
|
|
|
|
end, true)
|
2020-12-07 19:26:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
local sword_special_timer = {}
|
2021-03-12 17:02:30 +00:00
|
|
|
local SWORD_SPECIAL_COOLDOWN = 20
|
2020-12-07 19:26:12 +00:00
|
|
|
local function sword_special_timer_func(pname, timeleft)
|
|
|
|
sword_special_timer[pname] = timeleft
|
|
|
|
|
2021-03-12 17:02:30 +00:00
|
|
|
if timeleft - 2 >= 0 then
|
|
|
|
minetest.after(2, sword_special_timer_func, pname, timeleft - 2)
|
2020-12-07 19:26:12 +00:00
|
|
|
else
|
|
|
|
sword_special_timer[pname] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-06 20:55:35 +00:00
|
|
|
minetest.register_tool("ctf_classes:sword_bronze", {
|
2020-12-12 23:32:52 +00:00
|
|
|
description = "Knight's Sword\nSneak+Rightclick items/air to place marker\nRightclick enemies to place marker listing all enemies in area",
|
2021-01-06 20:55:35 +00:00
|
|
|
inventory_image = "default_tool_bronzesword.png",
|
2020-12-07 19:26:12 +00:00
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 0.8,
|
|
|
|
max_drop_level=1,
|
|
|
|
groupcaps={
|
|
|
|
snappy={times={[1]=2.5, [2]=1.20, [3]=0.35}, uses=0, maxlevel=2},
|
|
|
|
},
|
2021-05-08 15:49:53 +00:00
|
|
|
damage_groups = {fleshy=6, sword=1},
|
2020-12-07 19:26:12 +00:00
|
|
|
punch_attack_uses = 0,
|
|
|
|
},
|
|
|
|
sound = {breaks = "default_tool_breaks"},
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
local pname = placer:get_player_name()
|
|
|
|
if not pointed_thing then return end
|
|
|
|
|
2021-03-12 17:02:30 +00:00
|
|
|
if sword_special_timer[pname] and placer:get_player_control().sneak then
|
|
|
|
minetest.chat_send_player(pname, "You have to wait "..sword_special_timer[pname].."s to place marker again")
|
2020-12-07 19:26:12 +00:00
|
|
|
|
|
|
|
if pointed_thing.type == "node" then
|
|
|
|
return minetest.item_place(itemstack, placer, pointed_thing)
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local pteam = ctf.player(pname).team
|
|
|
|
|
2021-05-04 20:59:33 +00:00
|
|
|
if not pteam then -- can be nil during map change
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-12-07 19:26:12 +00:00
|
|
|
if pointed_thing.type == "object" and pointed_thing.ref:is_player() then
|
|
|
|
if ctf_match.is_in_build_time() then return end
|
|
|
|
|
|
|
|
local enemies = {}
|
|
|
|
local pos = pointed_thing.ref:get_pos()
|
|
|
|
|
|
|
|
sword_special_timer[pname] = SWORD_SPECIAL_COOLDOWN
|
|
|
|
sword_special_timer_func(pname, SWORD_SPECIAL_COOLDOWN)
|
|
|
|
|
|
|
|
for _, p in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = p:get_player_name()
|
|
|
|
|
|
|
|
if pteam ~= ctf.player(name).team and
|
|
|
|
vector.distance(p:get_pos(), pos) <= 10 then
|
|
|
|
table.insert(enemies, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if #enemies > 0 then
|
|
|
|
ctf_marker.remove_marker(pteam)
|
2021-03-10 04:53:11 +00:00
|
|
|
ctf_marker.add_marker(pname, pteam, pos, (" found enemies: <%s>]"):format(table.concat(enemies, ", ")))
|
2020-12-07 19:26:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if pointed_thing.type == "node" then
|
|
|
|
return minetest.item_place(itemstack, placer, pointed_thing)
|
|
|
|
end
|
|
|
|
|
2020-12-13 19:05:26 +00:00
|
|
|
-- Check if player is sneaking before placing marker
|
|
|
|
if not placer:get_player_control().sneak then return end
|
|
|
|
|
2021-03-12 17:02:30 +00:00
|
|
|
sword_special_timer[pname] = 4
|
|
|
|
sword_special_timer_func(pname, 4)
|
2020-12-07 19:26:12 +00:00
|
|
|
|
2021-03-10 04:53:11 +00:00
|
|
|
minetest.registered_chatcommands["m"].func(pname, "placed with sword")
|
2020-12-07 19:26:12 +00:00
|
|
|
end,
|
|
|
|
on_secondary_use = function(itemstack, user, pointed_thing)
|
|
|
|
if pointed_thing then
|
2021-01-06 20:55:35 +00:00
|
|
|
minetest.registered_tools["ctf_classes:sword_bronze"].on_place(itemstack, user, pointed_thing)
|
2020-12-07 19:26:12 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
sword_special_timer[player:get_player_name()] = nil
|
|
|
|
end)
|
|
|
|
|
|
|
|
ctf_match.register_on_new_match(function()
|
|
|
|
sword_special_timer = {}
|
|
|
|
end)
|
|
|
|
|
|
|
|
ctf.register_on_new_game(function()
|
|
|
|
sword_special_timer = {}
|
|
|
|
end)
|
2022-09-19 12:27:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
minetest.register_tool("ctf_classes:battleaxe", {
|
|
|
|
inventory_image = "ctf_classes_axefighter.png",
|
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 3,
|
|
|
|
max_drop_level=1,
|
|
|
|
groupcaps={
|
|
|
|
choppy={times={[1]=2.75, [2]=1.70, [3]=1.15}, uses=0, maxlevel=2},
|
|
|
|
},
|
|
|
|
damage_groups = {fleshy=10},
|
|
|
|
punch_attack_uses = 0,
|
|
|
|
},
|
|
|
|
})
|