From b7effc0d62326faa33590265896b05991e5499b9 Mon Sep 17 00:00:00 2001 From: Pao Date: Mon, 23 Jan 2023 01:00:11 +0100 Subject: [PATCH] Fixes --- media/lua/client/TOC_HelperFunctions.lua | 47 ++++------------------- media/lua/client/TOC_Update.lua | 4 +- media/lua/client/TOC_main.lua | 49 +++++++++++------------- 3 files changed, 33 insertions(+), 67 deletions(-) diff --git a/media/lua/client/TOC_HelperFunctions.lua b/media/lua/client/TOC_HelperFunctions.lua index edfc276..630ee3f 100644 --- a/media/lua/client/TOC_HelperFunctions.lua +++ b/media/lua/client/TOC_HelperFunctions.lua @@ -1,7 +1,7 @@ -- CutLimb -- TODO if TheONlyCure. triggers an errors -function TocCheckIfStillInfected(part_data) - if part_data == nil then +function TocCheckIfStillInfected(limbs_data) + if limbs_data == nil then return end -- Check ALL body part types to check if the player is still gonna die @@ -9,26 +9,26 @@ function TocCheckIfStillInfected(part_data) for _, v in ipairs(GetBodyParts()) do - if part_data[v].is_infected then + if limbs_data[v].is_infected then check = true end end - if part_data.is_other_bodypart_infected then + if limbs_data.is_other_bodypart_infected then check = true end return check end -function TocCureInfection(body_damage, part_data, part_name) +function TocCureInfection(body_damage, limbs_data, part_name) local body_part_type = body_damage:getBodyPart(TocGetBodyPartTypeFromPartName(part_name)) -- Check if we can heal the infection local is_other_bodypart_infected = getPlayer():getModData().TOC.Limbs.is_other_bodypart_infected - if not is_other_bodypart_infected and not TheOnlyCure.CheckIfOtherLimbsAreInfected(part_data, part_name) then + if not is_other_bodypart_infected and not TheOnlyCure.CheckIfOtherLimbsAreInfected(limbs_data, part_name) then body_damage:setInfected(false) body_part_type:SetInfected(false) body_damage:setInfectionMortalityDuration(-1) @@ -91,14 +91,14 @@ function TocGetSawInInventory(surgeon) end -- OperateLimb -function SetBodyPartsStatusAfterOperation(player, part_data, part_name, use_oven) +function SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven) --for _, v in ipairs(GetBodyParts()) do local body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name)) FixSingleBodyPartType(body_part_type, use_oven) - for _, v in ipairs(part_data[part_name].depends_on) do + for _, v in ipairs(limbs_data[part_name].depends_on) do local depended_body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(v)) FixSingleBodyPartType(depended_body_part_type, use_oven) @@ -169,37 +169,6 @@ function CheckIfItemIsAmputatedLimb(item) end --- function CheckIfItemIsAmputatedLimb(item) - - --- local item_full_type = item:getFullType() - --- local sides = {"Left", "Right"} --- local limbs_to_check = {"Hand", "LowerArm", "UpperArm"} - --- local is_amputated_limb = false - --- for _, part in ipairs(limbs_to_check) do --- for _, side in ipairs(sides) do - --- local part_name = side .. "_" .. part - --- local check_name = "TOC.Amputation_" .. part_name --- print(check_name) --- if item_full_type == check_name then --- is_amputated_limb = true --- break --- end - --- end - --- end - - --- return is_amputated_limb - --- end - function CheckIfItemIsProsthesis(item) -- TODO find a cleaner way diff --git a/media/lua/client/TOC_Update.lua b/media/lua/client/TOC_Update.lua index 3381c59..fe33099 100644 --- a/media/lua/client/TOC_Update.lua +++ b/media/lua/client/TOC_Update.lua @@ -125,14 +125,14 @@ function TheOnlyCure.SetHealthStatusForBodyPart(part_data, part_name, player) end --Helper function for UpdatePlayerHealth -function TheOnlyCure.CheckIfOtherLimbsAreInfected(part_data, part_name) +function TheOnlyCure.CheckIfOtherLimbsAreInfected(limbs_data, part_name) local body_parts = GetBodyParts() body_parts[part_name] = nil for _, v in pairs(body_parts) do - if part_data[v].is_infected then + if limbs_data[v].is_infected then return true end end diff --git a/media/lua/client/TOC_main.lua b/media/lua/client/TOC_main.lua index 03561c5..753e409 100644 --- a/media/lua/client/TOC_main.lua +++ b/media/lua/client/TOC_main.lua @@ -228,7 +228,7 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille local player = getPlayer() local toc_data = player:getModData().TOC - local part_data = toc_data.Limbs + local limbs_data = toc_data.Limbs local body_part = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromPartName(part_name)) local stats = player:getStats() @@ -261,21 +261,21 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille -- Use a tourniquet if available -- TODO add tourniquet - if part_data[part_name].is_cut == false then - part_data[part_name].is_cut = true - part_data[part_name].is_amputation_shown = true - part_data[part_name].cicatrization_time = part_data[part_name].cicatrization_base_time - surgeon_factor * 50 + if limbs_data[part_name].is_cut == false then + limbs_data[part_name].is_cut = true + limbs_data[part_name].is_amputation_shown = true + limbs_data[part_name].cicatrization_time = limbs_data[part_name].cicatrization_base_time - surgeon_factor * 50 -- Heal the infection here local body_damage = player:getBodyDamage() - if part_data[part_name].is_infected and body_damage:getInfectionLevel() < 20 then - part_data[part_name].is_infected = false + if limbs_data[part_name].is_infected and body_damage:getInfectionLevel() < 20 then + limbs_data[part_name].is_infected = false body_part:SetBitten(false) body_part:setBiteTime(0) -- Second check, let's see if there is any other infected limb. - if TocCheckIfStillInfected(part_data) == false then - TocCureInfection(body_damage, part_data, part_name) + if TocCheckIfStillInfected(limbs_data) == false then + TocCureInfection(body_damage, limbs_data, part_name) getPlayer():Say("I'm gonna be fine...") else getPlayer():Say("I'm still gonna die...") @@ -283,10 +283,10 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille end -- Cut the depended part - for _, depended_v in pairs(part_data[part_name].depends_on) do - part_data[depended_v].is_cut = true - part_data[depended_v].is_amputation_shown = false - part_data[depended_v].cicatrization_time = part_data[part_name].cicatrization_base_time - surgeon_factor * 50 + for _, depended_v in pairs(limbs_data[part_name].depends_on) do + limbs_data[depended_v].is_cut = true + limbs_data[depended_v].is_amputation_shown = false + limbs_data[depended_v].cicatrization_time = limbs_data[part_name].cicatrization_base_time - surgeon_factor * 50 end @@ -303,9 +303,6 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille -- Set blood on the amputated limb TocSetBloodOnAmputation(getPlayer(), body_part) - - player:transmitModData() - end @@ -316,7 +313,7 @@ end function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven) local player = getPlayer() - local part_data = player:getModData().TOC.Limbs + local limbs_data = player:getModData().TOC.Limbs if use_oven then local stats = player:getStats() @@ -324,20 +321,20 @@ function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven) stats:setStress(100) end - if part_data[part_name].is_operated == false and part_data[part_name].is_cut == true then - part_data[part_name].is_operated = true - part_data[part_name].cicatrization_time = part_data[part_name].cicatrization_time - (surgeon_factor * 200) - if use_oven then part_data[part_name].is_cauterized = true end - for _, depended_v in pairs(part_data[part_name].depends_on) do - part_data[depended_v].is_operated = true - part_data[depended_v].cicatrization_time = part_data[depended_v].cicatrization_time - (surgeon_factor * 200) - if use_oven then part_data[depended_v].is_cauterized = true end -- TODO does this make sense? + if limbs_data[part_name].is_operated == false and limbs_data[part_name].is_cut == true then + limbs_data[part_name].is_operated = true + limbs_data[part_name].cicatrization_time = limbs_data[part_name].cicatrization_time - (surgeon_factor * 200) + if use_oven then limbs_data[part_name].is_cauterized = true end + for _, depended_v in pairs(limbs_data[part_name].depends_on) do + limbs_data[depended_v].is_operated = true + limbs_data[depended_v].cicatrization_time = limbs_data[depended_v].cicatrization_time - (surgeon_factor * 200) + if use_oven then limbs_data[depended_v].is_cauterized = true end -- TODO does this make sense? end end - SetBodyPartsStatusAfterOperation(player, part_data, part_name, use_oven) + SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven) player:transmitModData() end