I broke everything since I'm an idiot, now it works

This commit is contained in:
Pao
2023-01-12 19:49:04 +01:00
parent 7c5e98d828
commit d66ed790a6
3 changed files with 117 additions and 166 deletions

View File

@@ -10,6 +10,12 @@
"Perks", "Perks",
"getPlayerByOnlineID", "getPlayerByOnlineID",
"getTexture", "getTexture",
"ISTimedActionQueue" "ISTimedActionQueue",
"sendClientCommand",
"ISBaseTimedAction",
"instanceof",
"getPlayerInventory",
"sendServerCommand",
"TraitFactory"
] ]
} }

View File

@@ -1,8 +1,38 @@
-- Makes the player drop an item if they don't have a limb or haven't equipped a prosthesis
function TheOnlyCure.TryDropItem(player, toc_data)
if TheOnlyCure.CheckIfCanPickUpItem(toc_data, Right, Hand, Forearm) and player:getPrimaryHandItem() ~= nil then
if player:getPrimaryHandItem():getName() ~= "Bare Hands" then
player:dropHandItems()
end
end
if TheOnlyCure.CheckIfCanPickUpItem(toc_data, Left, Hand, Forearm) and player:getSecondaryHandItem() ~= nil then
if player:getSecondaryHandItem():getName() ~= "Bare Hands" then
player:dropHandItems()
end
end
end
-- Helper for DropItem
function TheOnlyCure.CheckIfCanPickUpItem(toc_data, side, limb, secondary_limb)
local full_primary_limb = side .. limb
local full_secondary_limb = side .. secondary_limb
return toc_data[full_primary_limb].is_cut and not (toc_data[full_primary_limb].has_prosthesis_equipped or toc_data[full_secondary_limb]) or
(toc_data[full_secondary_limb].is_cut and not toc_data[full_secondary_limb].has_prosthesis_equipped)
end
function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data) function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
local body_damage = player:getBodyDamage() local body_damage = player:getBodyDamage()
for _, v in GetLimbsBodyPartTypes() do for _, v in ipairs(GetLimbsBodyPartTypes()) do
local toc_bodypart = TheOnlyCure.FindBodyPartFromBodyPartType(toc_data, v) local toc_bodypart = TheOnlyCure.FindBodyPartFromBodyPartType(toc_data, v)
if body_damage:getBodyPart(v):bitten() and not toc_data[toc_bodypart].is_cut then if body_damage:getBodyPart(v):bitten() and not toc_data[toc_bodypart].is_cut then
@@ -11,7 +41,7 @@ function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
end end
end end
for _, v in GetOtherBodyPartTypes() do for _, v in ipairs(GetOtherBodyPartTypes()) do
if body_damage:getBodyPart(v):bitten() then if body_damage:getBodyPart(v):bitten() then
toc_data.is_other_bodypart_infected = true -- Even one is enough, stop cycling if we find it toc_data.is_other_bodypart_infected = true -- Even one is enough, stop cycling if we find it
player:transmitModData() player:transmitModData()
@@ -152,10 +182,15 @@ end
function TheOnlyCure.UpdateEveryOneMinute() function TheOnlyCure.UpdateEveryOneMinute()
local player = getPlayer() local player = getPlayer()
-- To prevent errors during loading
if player == nil then
return
end
local toc_data = player:getModData().TOC local toc_data = player:getModData().TOC
if toc_data ~= nil then if toc_data ~= nil then
TheOnlyCure.TryDropItem(player, toc_data) --TheOnlyCure.TryDropItem(player, toc_data) -- TODO this is kinda useless I think
TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data) TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
TheOnlyCure.UpdatePlayerHealth(player, toc_data) TheOnlyCure.UpdatePlayerHealth(player, toc_data)
end end
@@ -165,6 +200,10 @@ end
function TheOnlyCure.UpdateEveryTenMinutes() function TheOnlyCure.UpdateEveryTenMinutes()
local player = getPlayer() local player = getPlayer()
if player == nil then
return
end
local toc_data = player:getModData().TOC local toc_data = player:getModData().TOC
@@ -172,7 +211,7 @@ function TheOnlyCure.UpdateEveryTenMinutes()
if toc_data.RightHand.has_prosthesis_equipped or toc_data.RightForearm.has_prosthesis_equipped then player:getXp():AddXP(Perks.RightHand, 4) end if toc_data.RightHand.has_prosthesis_equipped or toc_data.RightForearm.has_prosthesis_equipped then player:getXp():AddXP(Perks.RightHand, 4) end
if toc_data.LeftHand.has_prosthesis_equipped or toc_data.LeftForearm.has_prosthesis_equipped then player:getXp():AddXP(Perks.LeftHand, 4) end if toc_data.LeftHand.has_prosthesis_equipped or toc_data.LeftForearm.has_prosthesis_equipped then player:getXp():AddXP(Perks.LeftHand, 4) end
-- Updates the cicatrization time -- Updates the cicatrization timesssss
for _, part_name in pairs(GetBodyParts()) do for _, part_name in pairs(GetBodyParts()) do
if toc_data[part_name].is_cut and toc_data[part_name].is_cicatrized then if toc_data[part_name].is_cut and toc_data[part_name].is_cicatrized then
toc_data[part_name].cicatrization_time = toc_data[part_name].cicatrization_time - 1 -- TODO Make it more "dynamic" toc_data[part_name].cicatrization_time = toc_data[part_name].cicatrization_time - 1 -- TODO Make it more "dynamic"
@@ -185,5 +224,5 @@ function TheOnlyCure.UpdateEveryTenMinutes()
end end
Events.EveryTenMinutes(TheOnlyCure.UpdateEveryTenMinutes) Events.EveryTenMinutes.Add(TheOnlyCure.UpdateEveryTenMinutes)
Events.EveryOneMinute.Add(TheOnlyCure.UpdateEveryOneMinute) Events.EveryOneMinute.Add(TheOnlyCure.UpdateEveryOneMinute)

View File

@@ -2,8 +2,6 @@ if not TheOnlyCure then
TheOnlyCure = {} TheOnlyCure = {}
end end
-- GLOBAL STRINGS -- GLOBAL STRINGS
Left = "Left" Left = "Left"
Right = "Right" Right = "Right"
@@ -12,104 +10,16 @@ Hand = "Hand"
Forearm = "Forearm" Forearm = "Forearm"
Arm = "Arm" Arm = "Arm"
function TheOnlyCure.InitTheOnlyCure(_, player)
local mod_data = player:getModData()
--local toc_data = player:getModData().TOC
if mod_data.TOC == nil then
-- Makes the player drop an item if they don't have a limb or haven't equipped a prosthesis mod_data.TOC = {}
function TheOnlyCure.TryDropItem(player, toc_data) print("CREATING NEW TOC STUFF SINCE YOU JUST DIED")
if TheOnlyCure.CheckIfCanPickUpItem(toc_data, Right, Hand, Forearm) and player:getPrimaryHandItem() ~= nil then
if player:getPrimaryHandItem():getName() ~= "Bare Hands" then
player:dropHandItems()
end
end
if TheOnlyCure.CheckIfCanPickUpItem(toc_data, Left, Hand, Forearm) and player:getSecondaryHandItem() ~= nil then
if player:getSecondaryHandItem():getName() ~= "Bare Hands" then
player:dropHandItems()
end
end
end
-- Helper for DropItem
function TheOnlyCure.CheckIfCanPickUpItem(toc_data, side, limb, secondary_limb)
local full_primary_limb = side .. limb
local full_secondary_limb = side .. secondary_limb
return toc_data[full_primary_limb].is_cut and not (toc_data[full_primary_limb].has_prosthesis_equipped or toc_data[full_secondary_limb]) or
(toc_data[full_secondary_limb].is_cut and not toc_data[full_secondary_limb].has_prosthesis_equipped)
end
----------
-- Updates
local function everyOneMinute()
local player = getPlayer()
local modData = player:getModData()
--player:transmitModData()
if modData.TOC ~= nil then
dropItem(player, modData);
CheckIfInfect(player, modData);
UpdatePlayerHealth(player, modData);
end
end
local function everyTenMinutes()
local player = getPlayer()
local modData = player:getModData()
if modData.TOC ~= nil then
local names = {"RightHand", "RightForearm", "RightArm", "LeftHand", "LeftForearm", "LeftArm"}
--Augmente l'xp si equip
if modData.TOC.RightHand.has_prosthesis_equipped or modData.TOC.RightForearm.has_prosthesis_equipped then player:getXp():AddXP(Perks.RightHand, 4) end
if modData.TOC.LeftHand.has_prosthesis_equipped or modData.TOC.LeftForearm.has_prosthesis_equipped then player:getXp():AddXP(Perks.LeftHand, 4) end
--Reduit le temps de cicatri restant
for i,name in pairs(names) do
if modData.TOC[name].is_cut and not modData.TOC[name].is_cicatrized then
modData.TOC[name].cicatrization_time = modData.TOC[name].cicatrization_time - 1;
player:transmitModData()
end
end
end
end
local function initVariable(_, player)
local modData = player:getModData()
if modData.TOC == nil then
-- https://stackoverflow.com/questions/20915164/lua-loop-for-creating-variables-in-table
local rightHand = "RightHand" local rightHand = "RightHand"
local rightForearm = "RightForearm" local rightForearm = "RightForearm"
local rightArm = "RightArm" local rightArm = "RightArm"
@@ -118,100 +28,96 @@ local function initVariable(_, player)
local leftForearm = "LeftForearm" local leftForearm = "LeftForearm"
local leftArm = "LeftArm" local leftArm = "LeftArm"
mod_data.TOC = {
modData.TOC = {
RightHand = {}, RightHand = {},
RightForearm = {}, RightForearm = {},
RightArm = {}, RightArm = {},
LeftHand = {}, LeftHand = {},
LeftForearm = {}, LeftForearm = {},
LeftArm = {} LeftArm = {},
is_other_bodypart_infected = false
} }
for k,v in pairs(GetBodyParts()) do for _ ,v in pairs(GetBodyParts()) do
modData.TOC[v].is_cut = false mod_data.TOC[v].is_cut = false
modData.TOC[v].is_infected = false mod_data.TOC[v].is_infected = false
modData.TOC[v].is_operated = false mod_data.TOC[v].is_operated = false
modData.TOC[v].is_cicatrized = false mod_data.TOC[v].is_cicatrized = false
modData.TOC[v].is_cauterized = false mod_data.TOC[v].is_cauterized = false
modData.TOC[v].is_amputation_shown = false mod_data.TOC[v].is_amputation_shown = false
modData.TOC[v].cicatrization_time = 0 mod_data.TOC[v].cicatrization_time = 0
modData.TOC[v].has_prosthesis_equipped = false mod_data.TOC[v].has_prosthesis_equipped = false
modData.TOC[v].prothesis_factor = 1.0 -- Every prothesis has the same... does this even make sense here? mod_data.TOC[v].prothesis_factor = 1.0 -- TODO Every prosthesis has the same... does this even make sense here?
modData.TOC[v].prothesis_material_id = nil mod_data.TOC[v].prothesis_material_id = nil
end end
-- Manual stuff, just a temporary fix since this is kinda awful -- Manual stuff, just a temporary fix since this is kinda awful
modData.TOC[rightHand].depends_on = {} mod_data.TOC[rightHand].depends_on = {}
modData.TOC[rightForearm].depends_on = {rightHand} mod_data.TOC[rightForearm].depends_on = {rightHand}
modData.TOC[rightArm].depends_on = { rightHand, rightForearm } mod_data.TOC[rightArm].depends_on = { rightHand, rightForearm }
modData.TOC[leftHand].depends_on = {} mod_data.TOC[leftHand].depends_on = {}
modData.TOC[leftForearm].depends_on = { leftHand } mod_data.TOC[leftForearm].depends_on = { leftHand }
modData.TOC[leftArm].depends_on = { leftHand, leftForearm } mod_data.TOC[leftArm].depends_on = { leftHand, leftForearm }
-- Setup cicatrization times -- Setup cicatrization times
modData.TOC[rightHand].cicatrization_base_time = 1700 mod_data.TOC[rightHand].cicatrization_base_time = 1700
modData.TOC[leftHand].cicatrization_base_time = 1700 mod_data.TOC[leftHand].cicatrization_base_time = 1700
modData.TOC[rightForearm].cicatrization_base_time = 1800 mod_data.TOC[rightForearm].cicatrization_base_time = 1800
modData.TOC[leftForearm].cicatrization_base_time = 1800 mod_data.TOC[leftForearm].cicatrization_base_time = 1800
modData.TOC[rightArm].cicatrization_base_time = 2000 mod_data.TOC[rightArm].cicatrization_base_time = 2000
modData.TOC[leftArm].cicatrization_base_time = 2000 mod_data.TOC[leftArm].cicatrization_base_time = 2000
modData.TOC.is_other_bodypart_infected = false
-- Traits setup
if player:HasTrait("amputee1") then if player:HasTrait("amputee1") then
local cloth = player:getInventory():AddItem("TOC.ArmLeft_noHand"); local cloth = player:getInventory():AddItem("TOC.ArmLeft_noHand")
player:setWornItem(cloth:getBodyLocation(), cloth); player:setWornItem(cloth:getBodyLocation(), cloth)
modData.TOC.LeftHand.is_cut=true; modData.TOC.LeftHand.is_operated=true; modData.TOC.LeftHand.is_amputation_shown=true; modData.TOC.LeftHand.is_cicatrized=true; mod_data.TOC.LeftHand.is_cut=true; mod_data.TOC.LeftHand.is_operated=true; mod_data.TOC.LeftHand.is_amputation_shown=true; mod_data.TOC.LeftHand.is_cicatrized=true
player:getInventory():AddItem("TOC.MetalHook"); player:getInventory():AddItem("TOC.MetalHook")
end end
if player:HasTrait("amputee2") then if player:HasTrait("amputee2") then
local cloth = player:getInventory():AddItem("TOC.ArmLeft_noForearm"); local cloth = player:getInventory():AddItem("TOC.ArmLeft_noForearm")
player:setWornItem(cloth:getBodyLocation(), cloth); player:setWornItem(cloth:getBodyLocation(), cloth)
modData.TOC.LeftHand.is_cut=true; modData.TOC.LeftHand.is_operated=true; mod_data.TOC.LeftHand.is_cut=true; mod_data.TOC.LeftHand.is_operated=true
modData.TOC.LeftForearm.is_cut=true; modData.TOC.LeftForearm.is_operated=true; modData.TOC.LeftForearm.is_amputation_shown=true; modData.TOC.LeftForearm.is_cicatrized=true; mod_data.TOC.LeftForearm.is_cut=true; mod_data.TOC.LeftForearm.is_operated=true; mod_data.TOC.LeftForearm.is_amputation_shown=true; mod_data.TOC.LeftForearm.is_cicatrized=true
player:getInventory():AddItem("TOC.MetalHook"); player:getInventory():AddItem("TOC.MetalHook")
end end
if player:HasTrait("amputee3") then if player:HasTrait("amputee3") then
local cloth = player:getInventory():AddItem("TOC.ArmLeft_noArm"); local cloth = player:getInventory():AddItem("TOC.ArmLeft_noArm")
player:setWornItem(cloth:getBodyLocation(), cloth); player:setWornItem(cloth:getBodyLocation(), cloth)
modData.TOC.LeftHand.is_cut=true; modData.TOC.LeftHand.is_operated=true; mod_data.TOC.LeftHand.is_cut=true; mod_data.TOC.LeftHand.is_operated=true
modData.TOC.LeftForearm.is_cut=true; modData.TOC.LeftForearm.is_operated=true; mod_data.TOC.LeftForearm.is_cut=true; mod_data.TOC.LeftForearm.is_operated=true
modData.TOC.LeftArm.is_cut=true; modData.TOC.LeftArm.is_operated=true; modData.TOC.LeftArm.is_amputation_shown=true; modData.TOC.LeftArm.is_cicatrized=true; mod_data.TOC.LeftArm.is_cut=true; mod_data.TOC.LeftArm.is_operated=true; mod_data.TOC.LeftArm.is_amputation_shown=true; mod_data.TOC.LeftArm.is_cicatrized=true
player:getInventory():AddItem("TOC.MetalHook"); player:getInventory():AddItem("TOC.MetalHook")
end end
player:transmitModData() player:transmitModData()
end end
end end
local function initTOCTraits() function TheOnlyCure.DeclareTraits()
local amp1 = TraitFactory.addTrait("amputee1", getText("UI_trait_Amputee1"), -8, getText("UI_trait_Amputee1desc"), false, false); local amp1 = TraitFactory.addTrait("amputee1", getText("UI_trait_Amputee1"), -8, getText("UI_trait_Amputee1desc"), false, false)
amp1:addXPBoost(Perks.LeftHand, 4); amp1:addXPBoost(Perks.LeftHand, 4)
local amp2 = TraitFactory.addTrait("amputee2", getText("UI_trait_Amputee2"), -10, getText("UI_trait_Amputee2desc"), false, false); local amp2 = TraitFactory.addTrait("amputee2", getText("UI_trait_Amputee2"), -10, getText("UI_trait_Amputee2desc"), false, false)
amp2:addXPBoost(Perks.LeftHand, 4); amp2:addXPBoost(Perks.LeftHand, 4)
local amp3 = TraitFactory.addTrait("amputee3", getText("UI_trait_Amputee3"), -20, getText("UI_trait_Amputee3desc"), false, false); local amp3 = TraitFactory.addTrait("amputee3", getText("UI_trait_Amputee3"), -20, getText("UI_trait_Amputee3desc"), false, false)
amp3:addXPBoost(Perks.LeftHand, 4); amp3:addXPBoost(Perks.LeftHand, 4)
TraitFactory.addTrait("Insensitive", getText("UI_trait_Insensitive"), 6, getText("UI_trait_Insensitivedesc"), false, false); TraitFactory.addTrait("Insensitive", getText("UI_trait_Insensitive"), 6, getText("UI_trait_Insensitivedesc"), false, false)
TraitFactory.setMutualExclusive("amputee1", "amputee2"); TraitFactory.setMutualExclusive("amputee1", "amputee2")
TraitFactory.setMutualExclusive("amputee1", "amputee3"); TraitFactory.setMutualExclusive("amputee1", "amputee3")
TraitFactory.setMutualExclusive("amputee2", "amputee3"); TraitFactory.setMutualExclusive("amputee2", "amputee3")
end end
Events.OnCreatePlayer.Add(initVariable);
Events.OnGameBoot.Add(initTOCTraits);
Events.OnCreatePlayer.Add(TheOnlyCure.InitTheOnlyCure)
Events.OnGameBoot.Add(TheOnlyCure.DeclareTraits)