Made dead players un-knockoutable; improved knockout time equation

This commit is contained in:
Billy S 2018-07-24 21:18:11 -04:00
parent 35c3de0184
commit 1398c750b5
2 changed files with 5 additions and 4 deletions

View File

@ -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

View File

@ -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