From 5b5a68015e25a3e98a48f953500a68f49d1b5ee2 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Sun, 13 Sep 2020 00:28:12 -0500 Subject: [PATCH] Add: takedown feature --- README.md | 31 +++++++++++++++++-- chatcommands.lua | 42 +++++++++++++++++--------- config.lua | 5 ++++ globalstep.lua | 77 ++++++++++++++++++++++++++++++++---------------- punch.lua | 5 ++-- settingtypes.txt | 2 ++ 6 files changed, 117 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 8f07ec8..d4b6a81 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,28 @@ All tools have different throw speeds, charge times, and damages. **/tap_speed_reset** [none] Resets the tap sensitivity to 0.15 seconds. **(Requires sscsm)** -**/use_shield** [boolean] If set to true, the shield plate inside your armor inventory will be used to block all incoming damage when RMB is pressed. +**/use_shield** [boolean] If set to true, the shield plate inside your armor inventory will be used to block all incoming damage when RMB is pressed. **(Requires shields)** -**/throw_style** Change how you throw an item. Accepted values are [none|spin|dip] +**/move_item** Gives you a movement item. Accepted values are: +- dodge +- dash_left +- dash_up +- dash_right +- dash_down +- dash_all +- roll_left +- roll_up +- roll_right +- roll_down +- roll_all +- all + +These items offer a way to still dodge, dash, and roll without the sscsm mod. + +**/throw_style** Change how you throw an item. Accepted values are: +- none +- spin +- dip Thrown items give better damage and distance when charged the longest. @@ -115,6 +134,9 @@ Any damage from a punch in pvp is put in a queue for a duration. This makes it p 4. *Counter* reverses all damage plus bonus damage to the aggressor. (Must be within counter duration and full punch only) 5. *Hasty guard* when you block immediately after being hit you can block the any damage from any angle, but this has a small-time window to activate. (depends on config or tool settings) +#### takedown +If enabled full punches can only kill a player. Spam punches will only bring the hp to one (half a heart). + ### effects #### disarming @@ -301,6 +323,10 @@ This is used to divide the range value into two parts. The parts being optimal a ``` lua pvp_revamped.optimal_distance_mul = 0.625 ``` +If true you would need a full punch in order to kill a player. Spam punches will only bring the hp to one. +``` lua +pvp_revamped.takedown = true +``` #### maneuvers Set how fast eachh player should dash. @@ -528,6 +554,5 @@ armor:register_armor("test:shield_test", { shield_entity_rotate = {x = -90, y = 180, z = 180}, -- See shield_entity_scale in config. shield_entity_scale = {x = 0.35, y = 0.35}} - }) ``` diff --git a/chatcommands.lua b/chatcommands.lua index 75bcc83..4179cdc 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -37,8 +37,8 @@ minetest.register_chatcommand("throw_style", { -- Cmd to give you movement items. minetest.register_chatcommand("move_item", { params = "[]: Gives you a movement item.", - description = "Gives you a movement item. Accepted values are [dodge|dash_left|dash_up|dash_right|dash_down|roll_left" - .. "|roll_up|roll_right|roll_down|all]", + description = "Gives you a movement item. Accepted values are [dodge|dash_left|dash_up|dash_right|dash_down|dash_all|roll_left" + .. "|roll_up|roll_right|roll_down|roll_all|all]", privs = { interact = true, }, @@ -49,39 +49,53 @@ minetest.register_chatcommand("move_item", { if param == "dodge" then inv:add_item("main", "pvp_revamped:dodge") - return true, "" + return true elseif param == "dash_left" then inv:add_item("main", "pvp_revamped:dash_left") - return true, "" + return true elseif param == "dash_up" then inv:add_item("main", "pvp_revamped:dash_up") - return true, "" + return true elseif param == "dash_right" then inv:add_item("main", "pvp_revamped:dash_right") - return true, "" + return true elseif param == "dash_down" then inv:add_item("main", "pvp_revamped:dash_down") - return true, "" + return true + elseif param == "dash_all" then + inv:add_item("main", "pvp_revamped:dash_left") + inv:add_item("main", "pvp_revamped:dash_up") + inv:add_item("main", "pvp_revamped:dash_right") + inv:add_item("main", "pvp_revamped:dash_down") + + return true elseif param == "roll_left" then inv:add_item("main", "pvp_revamped:roll_left") - return true, "" + return true elseif param == "roll_up" then inv:add_item("main", "pvp_revamped:roll_up") - return true, "" + return true elseif param == "roll_right" then inv:add_item("main", "pvp_revamped:roll_right") - return true, "" + return true elseif param == "roll_down" then inv:add_item("main", "pvp_revamped:roll_down") - return true, "" + return true + elseif param == "roll_all" then + inv:add_item("main", "pvp_revamped:roll_left") + inv:add_item("main", "pvp_revamped:roll_up") + inv:add_item("main", "pvp_revamped:roll_right") + inv:add_item("main", "pvp_revamped:roll_down") + + return true elseif param == "all" then inv:add_item("main", "pvp_revamped:dodge") inv:add_item("main", "pvp_revamped:dash_left") @@ -93,11 +107,11 @@ minetest.register_chatcommand("move_item", { inv:add_item("main", "pvp_revamped:roll_right") inv:add_item("main", "pvp_revamped:roll_down") - return true, "" + return true end - return false, "Only parameters: 'dodge', 'dash_left', 'dash_up', 'dash_right', 'dash_down',\n" - .. "roll_left, roll_up, roll_right, roll_down, and 'all' are accepted." + return false, "Only parameters: 'dodge', 'dash_left', 'dash_up', 'dash_right', 'dash_down', 'dash_all',\n" + .. "'roll_left', 'roll_up', 'roll_right', 'roll_down', 'roll_all', and 'all' are accepted." end }) diff --git a/config.lua b/config.lua index ed318c2..ae29923 100644 --- a/config.lua +++ b/config.lua @@ -39,6 +39,7 @@ pvp_revamped.config.lower_elevation_dmg_mul = tonumber(minetest.settings:get("pv pvp_revamped.config.velocity_dmg_mul = tonumber(minetest.settings:get("pvp_revamped.velocity_dmg_mul")) or 0.15 pvp_revamped.config.optimal_distance_dmg_mul = tonumber(minetest.settings:get("pvp_revamped.optimal_distance_dmg_mul")) or 0.2 pvp_revamped.config.maximum_distance_dmg_mul = tonumber(minetest.settings:get("pvp_revamped.maximum_distance_dmg_mul")) or 0.1 +pvp_revamped.config.takedown = minetest.settings:get_bool("pvp_revamped.takedown") pvp_revamped.config.optimal_distance_mul = tonumber(minetest.settings:get("pvp_revamped.optimal_distance_mul")) or 0.625 pvp_revamped.config.projectile_full_throw_mul = tonumber(minetest.settings:get("pvp_revamped.projectile_full_throw_mul")) or 2 pvp_revamped.config.projectile_half_throw_mul = tonumber(minetest.settings:get("pvp_revamped.projectile_half_throw_mul")) or 0.000005 @@ -80,3 +81,7 @@ pvp_revamped.config.shield_entity_rotate = {x = tonumber(xyz[1]), y = tonumber(x xyz = split("pvp_revamped.shield_entity_scale", {0.35, 0.35}) pvp_revamped.config.shield_entity_scale = {x = tonumber(xyz[1]), y = tonumber(xyz[2]), z = tonumber(xyz[3])} + +if pvp_revamped.config.takedown == nil then + pvp_revamped.config.takedown = true +end diff --git a/globalstep.lua b/globalstep.lua index 1b8be55..bead1f0 100644 --- a/globalstep.lua +++ b/globalstep.lua @@ -15,6 +15,7 @@ local clash_duration = pvp_revamped.config.clash_duration local dash_cooldown = pvp_revamped.config.dash_cooldown local dash_cooldown = pvp_revamped.config.dash_cooldown local hasty_guard_duration = pvp_revamped.config.hasty_guard_duration +local takedown = pvp_revamped.config.takedown local projectile_throw_style_dip = pvp_revamped.projectile_throw_style_dip local projectile_throw_style_spinning = pvp_revamped.projectile_throw_style_spinning local player_data = pvp_revamped.player_data @@ -289,38 +290,62 @@ minetest.register_globalstep(function(dtime) local hp = player:get_hp() local hp_change - for i = #hit_data, 1, -1 do - local data = hit_data[i] - - if data.resolved or data.time + clash_duration + server_lag < time then - local block = v.block - local shield = v.shield - local damage = data.damage - local timeframe = time - server_lag - - -- If the player was able to pull off a hasty guard cancel the attack. - if damage > 0 and not (block and block.initial_time + block.hasty_guard_duration > timeframe) and not (shield and shield.initial_time + shield.hasty_guard_duration > timeframe) then - hp = hp - damage - hp_change = true - elseif damage < 0 then - local hitter = get_player_by_name(data.name) - - hitter:set_hp(hitter:get_hp() + damage) + if hp >= 1 then + for i = #hit_data, 1, -1 do + -- End the loop if hp is below one. + if hp < 1 then + v.hit = nil + break end + + local data = hit_data[i] - local count = #hit_data + if data.resolved or data.time + clash_duration + server_lag < time then + local block = v.block + local shield = v.shield + local damage = data.damage + local timeframe = time - server_lag + + -- If the player was able to pull off a hasty guard cancel the attack. + if damage > 0 and not (block and block.initial_time + block.hasty_guard_duration > timeframe) and not (shield and shield.initial_time + shield.hasty_guard_duration > timeframe) then + hp = hp - damage - hit_data[i] = hit_data[count] - hit_data[count] = nil + if takedown and not data.full_punch and (hp - damage) < 1 then + hp = 1 + end + + hp_change = true + elseif damage < 0 then + local hitter = get_player_by_name(data.name) + local hitter_hp = hitter:get_hp() + + if (takedown and data.full_punch and (hitter_hp + damage) >= 1) or (not takedown and hitter_hp >= 1) then + hitter:set_hp(hitter_hp + damage) + elseif takedown and hitter_hp > 1 then + hitter:set_hp(max(hitter_hp + damage, 1)) + end + end + + local count = #hit_data + + hit_data[i] = hit_data[count] + hit_data[count] = nil + end end - end - if hp_change then - player:set_hp(hp) - end + local real_hp = player:get_hp() - -- If this table contains no more hits remove it. - if maxn(hit_data) < 1 then + if hp_change and real_hp >= 1 then + player:set_hp(hp) + elseif real_hp < 1 then + v.hit = nil + end + + -- If this table contains no more hits remove it. + if maxn(hit_data) < 1 then + v.hit = nil + end + else v.hit = nil end diff --git a/punch.lua b/punch.lua index 2be104a..4d5850e 100644 --- a/punch.lua +++ b/punch.lua @@ -575,14 +575,15 @@ local function punch(player, hitter, time_from_last_punch, tool_capabilities, di end hd.resolved = true + hd.full_punch = true break end end elseif victim_data.hit then - insert(victim_data.hit, 1, {name = hitter_name, damage = damage, time = get_us_time()}) + insert(victim_data.hit, 1, {name = hitter_name, damage = damage, full_punch = full_punch, time = get_us_time()}) else - victim_data.hit = {{name = hitter_name, damage = damage, time = get_us_time()}} + victim_data.hit = {{name = hitter_name, damage = damage, full_punch = full_punch, time = get_us_time()}} end victim_data.block = nil diff --git a/settingtypes.txt b/settingtypes.txt index c8e8bce..01e7f1b 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -83,6 +83,8 @@ pvp_revamped.parry_dmg_mul (Parry damage multiplier) float 1.2 pvp_revamped.counter_dmg_mul (Counter damage multiplier) float 1.5 # This is used to divide the range value into two parts. The parts being optimal and maximum range. pvp_revamped.optimal_distance_mul (Optimal distance multiplier) float 0.625 +# If true you would need a full punch in order to kill a player. Spam punches will only bring the hp to 1. +pvp_revamped.takedown (Take down) bool true [Maneuvers] # Set how fast eachh player should dash.