From abb463fbd38ee009a7b8af18039132c4caad262a Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Fri, 16 Oct 2020 14:51:07 -0700 Subject: [PATCH] Improve knight's damage boost code --- mods/ctf/ctf_classes/melee.lua | 32 ++++++++--------------------- mods/other/latest_updates/init.lua | 7 ++++--- mods/other/random_messages/init.lua | 4 ++-- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/mods/ctf/ctf_classes/melee.lua b/mods/ctf/ctf_classes/melee.lua index 9b6d3e0..2fd523c 100644 --- a/mods/ctf/ctf_classes/melee.lua +++ b/mods/ctf/ctf_classes/melee.lua @@ -1,28 +1,12 @@ -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 +minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) + if tool_capabilities.damage_groups.nopunch then return end + local class = ctf_classes.get(hitter) - local class = ctf_classes.get(reason.object) - - if class.properties.melee_bonus and reason.object:get_wielded_item():get_name():find("sword") then - local change = hp_change - class.properties.melee_bonus - - if player:get_hp() + change <= 0 and player:get_hp() + hp_change > 0 then - local wielded_item = reason.object:get_wielded_item() - - 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 + if class.properties.melee_bonus and hitter:get_wielded_item():get_name():find("sword") then + if time_from_last_punch > 0.75 then + time_from_last_punch = 0.75 end - return change + player:punch(hitter, 1, {damage_groups = {fleshy = time_from_last_punch*2, nopunch = 1}}, dir) end - - return hp_change -end, true) +end) diff --git a/mods/other/latest_updates/init.lua b/mods/other/latest_updates/init.lua index f621522..58e50a2 100644 --- a/mods/other/latest_updates/init.lua +++ b/mods/other/latest_updates/init.lua @@ -2,7 +2,7 @@ local latest_updates = minetest.formspec_escape([[ - Prevented knights from using the SMG - Gave medic class building tools and prevented them from using SMG/Shotgun - Changed fall damage to use the combat system -- Increased damage dealt by knights (+1 hp) when wielding swords +- Increased damage dealt by knights (up to +1.5 hp depending on time since last punch) when wielding swords - Merged the sniper class with the shooter class - Changed bandages to give two points per heal - Made rifle automatic and doubled damage @@ -17,8 +17,9 @@ if minetest.global_exists("sfinv") then get = function(self, player, context) return sfinv.make_formspec(player, context, "real_coordinates[true]" .. - "box[0.1,0.5;10.4,10.25;#222222]" .. - "textarea[0.1,0.5;10.4,10.25;;The latest updates to CTF are listed here;" .. latest_updates .. "]", false) + "label[3,0.4;"..minetest.colorize("#00aa00", "The latest updates to CTF are listed here").."]" .. + "box[0.1,0.65;10.4,10.1;#222222]" .. + "textarea[0.1,0.65;10.4,10.1;;;" .. latest_updates .. "]", false) end }) end diff --git a/mods/other/random_messages/init.lua b/mods/other/random_messages/init.lua index f254527..ccb43fb 100644 --- a/mods/other/random_messages/init.lua +++ b/mods/other/random_messages/init.lua @@ -51,7 +51,7 @@ function random_messages.read_messages() "To talk to only your team, start your messages with /t. For example, /t Hello team!", "Use medkits to gradually restore your health.", "Moving or fighting while using medkits will interrupt the healing process.", - "Knights have a slight damage bonus when attacking with swords.", + "Knights have a slight damage bonus (up to 1.5 hp) when attacking with swords.", "Gain more score by killing more than you die, by healing teammates as a medic, or by capturing the flag.", "You gain more score the better the opponent you defeat.", "Find weapons in chests or mine and use furnaces to make stronger swords.", @@ -78,7 +78,7 @@ function random_messages.read_messages() "Medics cause troops within 10 metres to regenerate health faster.", "Hitting your enemy does more damage than not hitting them.", "Press right mouse button or double-tap the screen to activate scope while wielding a sniper rifle.", - "The 'Updates' tab in your inventory will show some of the latest updates to CTF" + "The 'Updates' tab in your inventory will show some of the latest updates to CTF", } end