Fixed ResetEverything for SP and some other fixes

This commit is contained in:
Pao
2023-01-23 01:44:35 +01:00
parent 5770b8a488
commit 5faa4ddb92
4 changed files with 70 additions and 16 deletions

View File

@@ -147,7 +147,7 @@ end
TocContextMenus.CreateCheatMenu = function(context, root_menu, local_player, clicked_player) TocContextMenus.CreateCheatMenu = function(context, root_menu, local_player, clicked_player)
if local_player:getAccessLevel() == "Admin" then if local_player:getAccessLevel() == "Admin" or isDebugEnabled() then
local cheat_menu = TocContextMenus.CreateNewMenu("Cheat", context, root_menu) local cheat_menu = TocContextMenus.CreateNewMenu("Cheat", context, root_menu)

View File

@@ -1,20 +1,37 @@
function TocResetEverything() function TocResetEverything()
-- This has to be run on the local player to be sure that we're correctly reassigning everything
local player = getPlayer() local player = getPlayer()
local player_inventory = player:getInventory()
local mod_data = player:getModData() local mod_data = player:getModData()
mod_data.TOC = nil mod_data.TOC = nil
TheOnlyCure.InitTheOnlyCure(_, player) TheOnlyCure.InitTheOnlyCure(_, player)
-- Destroy the amputation model -- Destroy the amputation or prosthesis item
for _, v in ipairs(GetBodyParts()) do for _, v in ipairs(GetBodyParts()) do
local cloth = player:getInventory():FindAndReturn(TocFindAmputatedClothingFromPartName(v)) --local amputated_clothing = player:getInventory():FindAndReturn(TocFindAmputatedClothingFromPartName(v))
-- TODO make it better
local amputation_item_name = TocFindAmputationOrProsthesisName(v, player, "Amputation")
local prosthesis_item_name = TocFindAmputationOrProsthesisName(v, player, "Prosthesis")
if cloth ~= nil then if amputation_item_name ~= nil then
print("Resetting " .. cloth:getName()) local amputation_item = player_inventory:FindAndReturn(amputation_item_name)
player:removeWornItem(cloth) if amputation_item ~= nil then
player:getInventory():Remove(cloth) print("Resetting " .. amputation_item:getName())
player:removeWornItem(amputation_item)
player:getInventory():Remove(amputation_item)
end end
cloth = nil -- reset it amputation_item = nil -- reset it
end
if prosthesis_item_name ~= nil then
local prosthesis_item = player_inventory:FindAndReturn(prosthesis_item_name)
if prosthesis_item ~= nil then
print("Resetting " .. prosthesis_item:getName())
player:removeWornItem(prosthesis_item)
player:getInventory():Remove(prosthesis_item)
end
prosthesis_item = nil -- reset it
end
end end
end end

View File

@@ -124,7 +124,7 @@ end
-- Unequip Prosthesis -- Unequip Prosthesis
local function PartNameToBodyLocation(name) local function PartNameToBodyLocationProsthesis(name)
-- This is still correct but naming sucks -- This is still correct but naming sucks
if name == "Right_Hand" then return "ArmRight_Prot" end if name == "Right_Hand" then return "ArmRight_Prot" end
if name == "Right_LowerArm" then return "ArmRight_Prot" end if name == "Right_LowerArm" then return "ArmRight_Prot" end
@@ -134,15 +134,25 @@ local function PartNameToBodyLocation(name)
if name == "Left_UpperArm" then return "ArmLeft_Prot" end if name == "Left_UpperArm" then return "ArmLeft_Prot" end
end end
function TocFindItemInProstBodyLocation(part_name, patient)
-- FIXME this can return even amputated limbs, and we're using it only for prosthetics. This is gonna break sooner or later
local function PartNameToBodyLocationAmputation(name)
-- This is still correct but naming sucks
if name == "Right_Hand" then return "ArmRight" end
if name == "Right_LowerArm" then return "ArmRight" end
if name == "Right_UpperArm" then return "ArmRight" end
if name == "Left_Hand" then return "ArmLeft" end
if name == "Left_LowerArm" then return "ArmLeft" end
if name == "Left_UpperArm" then return "ArmLeft" end
end
function TocFindItemInProstBodyLocation(part_name, patient)
-- Can't be used for online purposes, since we can't get the online inventory of another player -- Can't be used for online purposes, since we can't get the online inventory of another player
local worn_items = patient:getWornItems() local worn_items = patient:getWornItems()
for i = 1, worn_items:size() - 1 do -- Maybe wornItems:size()-1 for i = 1, worn_items:size() - 1 do -- Maybe wornItems:size()-1
local item = worn_items:get(i):getItem() local item = worn_items:get(i):getItem()
if item:getBodyLocation() == PartNameToBodyLocation(part_name) then if item:getBodyLocation() == PartNameToBodyLocationProsthesis(part_name) then
return item return item
end end
end end
@@ -150,6 +160,34 @@ function TocFindItemInProstBodyLocation(part_name, patient)
end end
-- Debug cheat
function TocFindAmputationOrProsthesisName(part_name, player, choice)
local worn_items = player:getWornItems()
for i = 1, worn_items:size() - 1 do
local item = worn_items:get(i):getItem()
if choice == "Amputation" then
if item:getBodyLocation() == PartNameToBodyLocationAmputation(part_name) then
return item:getFullType()
end
elseif choice == "Prosthesis" then
if item:getBodyLocation() == PartNameToBodyLocationProsthesis(part_name) then
return item:getFullType()
end
end
end
end
------------------------------------- -------------------------------------
-- Override helper -- Override helper

View File

@@ -158,14 +158,13 @@ function TheOnlyCure.UpdateEveryOneMinute()
-- Updates toc data in a global way, basically player:transmitModData but it works
-- Sends only Limbs since the other stuff is mostly static
if toc_data ~= nil then if toc_data ~= nil then
sendClientCommand(player, 'TOC', 'ChangePlayerState', { toc_data.Limbs } ) sendClientCommand(player, 'TOC', 'ChangePlayerState', { toc_data.Limbs } )
end end
end end
function TheOnlyCure.UpdateEveryTenMinutes() function TheOnlyCure.UpdateEveryTenMinutes()