From 50ed336144724a7ae103dc648377f100f8fb4f12 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 21 May 2017 06:20:00 +0200 Subject: [PATCH] Add PvP combat exhaustion --- mods/PLAYER/mcl_hunger/init.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 088d85e7d..f0123893a 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -40,16 +40,15 @@ mcl_hunger.HUD_TICK = 0.1 mcl_hunger.EXHAUST_DIG = 5 -- after digging node mcl_hunger.EXHAUST_JUMP = 50 -- jump mcl_hunger.EXHAUST_SPRINT_JUMP = 200 -- TODO: jump while sprinting -mcl_hunger.EXHAUST_ATTACK = 100 -- TODO: hit an enemy +mcl_hunger.EXHAUST_ATTACK = 100 -- hit an enemy mcl_hunger.EXHAUST_SWIM = 10 -- TODO: player movement in water mcl_hunger.EXHAUST_SPRINT = 100 -- sprint (per node) -mcl_hunger.EXHAUST_DAMAGE = 100 -- TODO: taking damage (protected by armor) +mcl_hunger.EXHAUST_DAMAGE = 100 -- TODO (mostly done): taking damage (protected by armor) mcl_hunger.EXHAUST_REGEN = 6000 -- Regenerate 1 HP mcl_hunger.EXHAUST_LVL = 4000 -- at what exhaustion player saturation gets lowered mcl_hunger.SATURATION_INIT = 50 -- Initial saturation for new/respawning players - --load custom settings local set = io.open(minetest.get_modpath("mcl_hunger").."/mcl_hunger.conf", "r") if set then @@ -186,6 +185,14 @@ minetest.register_on_respawnplayer(function(player) mcl_hunger.update_exhaustion_hud(player, e) end) +-- PvP combat exhaustion +minetest.register_on_punchplayer(function(victim, puncher, time_from_last_punch, tool_capabilities, dir, damage) + if victim:is_player() and puncher:is_player() then + mcl_hunger.exhaust(victim:get_player_name(), mcl_hunger.EXHAUST_DAMAGE) + mcl_hunger.exhaust(puncher:get_player_name(), mcl_hunger.EXHAUST_ATTACK) + end +end) + function mcl_hunger.exhaust(playername, increase) local player = minetest.get_player_by_name(playername) if not player then return false end