diff --git a/media/lua/client/TOC_ContextMenus.lua b/media/lua/client/TOC_ContextMenus.lua index 9a9e462..c1ffefd 100644 --- a/media/lua/client/TOC_ContextMenus.lua +++ b/media/lua/client/TOC_ContextMenus.lua @@ -147,7 +147,7 @@ end 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) diff --git a/media/lua/client/TOC_Debug.lua b/media/lua/client/TOC_Debug.lua index a57990e..26f7d67 100644 --- a/media/lua/client/TOC_Debug.lua +++ b/media/lua/client/TOC_Debug.lua @@ -1,20 +1,37 @@ 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_inventory = player:getInventory() local mod_data = player:getModData() mod_data.TOC = nil TheOnlyCure.InitTheOnlyCure(_, player) - -- Destroy the amputation model + -- Destroy the amputation or prosthesis item 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 - print("Resetting " .. cloth:getName()) - player:removeWornItem(cloth) - player:getInventory():Remove(cloth) + if amputation_item_name ~= nil then + local amputation_item = player_inventory:FindAndReturn(amputation_item_name) + if amputation_item ~= nil then + print("Resetting " .. amputation_item:getName()) + player:removeWornItem(amputation_item) + player:getInventory():Remove(amputation_item) + end + amputation_item = nil -- reset it end - cloth = nil -- reset it + 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 diff --git a/media/lua/client/TOC_HelperFunctions.lua b/media/lua/client/TOC_HelperFunctions.lua index 9d793b5..6de0a4c 100644 --- a/media/lua/client/TOC_HelperFunctions.lua +++ b/media/lua/client/TOC_HelperFunctions.lua @@ -124,7 +124,7 @@ end -- Unequip Prosthesis -local function PartNameToBodyLocation(name) +local function PartNameToBodyLocationProsthesis(name) -- This is still correct but naming sucks if name == "Right_Hand" 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 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 local worn_items = patient:getWornItems() for i = 1, worn_items:size() - 1 do -- Maybe wornItems:size()-1 local item = worn_items:get(i):getItem() - if item:getBodyLocation() == PartNameToBodyLocation(part_name) then + if item:getBodyLocation() == PartNameToBodyLocationProsthesis(part_name) then return item end end @@ -150,6 +160,34 @@ function TocFindItemInProstBodyLocation(part_name, patient) 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 diff --git a/media/lua/client/TOC_Update.lua b/media/lua/client/TOC_Update.lua index fe33099..fc153c2 100644 --- a/media/lua/client/TOC_Update.lua +++ b/media/lua/client/TOC_Update.lua @@ -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 sendClientCommand(player, 'TOC', 'ChangePlayerState', { toc_data.Limbs } ) end - - - end function TheOnlyCure.UpdateEveryTenMinutes()