From 1398c750b502bf23b0dcaa9864de4467276b040a Mon Sep 17 00:00:00 2001 From: Billy S Date: Tue, 24 Jul 2018 21:18:11 -0400 Subject: [PATCH] Made dead players un-knockoutable; improved knockout time equation --- api.lua | 4 ++-- handlers.lua | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api.lua b/api.lua index df9bdf2..c2ae38c 100644 --- a/api.lua +++ b/api.lua @@ -3,10 +3,10 @@ -- (A value betwen 1 and 0; 1 = will happen every time; 0 = will never happed. Note that a chance of 1 may fail to knock players out if the tool is not used wiht a full punch) -- max_health is the maximum health the player will have to be knocked out with the tool -- (If the player's health is greater then max_health, they won't be knocked out, regardless of chance) --- max_time is the maximum time (in seconds) that the player will be knocked out for +-- max_time is the maximum time (in seconds) that the player will be knocked out for (note that this would happen if the player was hit when they had 0 hp, aka never) -- the minimum time the player will be knocked out for is half of max_time -- The actual time the player is knocked out for is calculated by the following equation: --- time knocked out = ((current health / max_health) + 1) * max_time / 2 +-- time knocked out = max_time * (1 - current hp / (max_health * 2)) knockout.register_tool = function(toolname, chance, max_health, max_time) knockout.tools[toolname] = {chance = chance, max_health = max_health, max_time = max_time} end diff --git a/handlers.lua b/handlers.lua index fead570..9996ee5 100644 --- a/handlers.lua +++ b/handlers.lua @@ -79,7 +79,9 @@ end) -- Catch whacks with various tools and calculate if the victim should be knocked out minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) local victim = player:get_player_name() + local currHp = player:get_hp() if knockout.knocked_out[victim] ~= nil then return end + if currHp <= 0 then return end local tool = hitter:get_wielded_item():get_name() -- Get tool used local def = nil -- Get tool knockout def @@ -91,13 +93,12 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, end if def == nil then return end -- Calculate - local currHp = player:get_hp() if currHp <= def.max_health then local chanceMult = time_from_last_punch / tool_capabilities.full_punch_interval -- You can't knock people out with lots of love taps if chanceMult > 1 then chanceMult = 1 end if math.random() < def.chance * chanceMult then -- Knocked out - local koTime = ((currHp / def.max_health) + 1) * def.max_time / 2 + local koTime = math.floor(def.max_time * (1 - currHp / (def.max_health * 2))) knockout.knockout(victim, koTime) end end