fix: working amputations in mp

This commit is contained in:
ZioPao
2026-01-27 01:33:54 +01:00
parent 1fb3899a5a
commit df9f559078
7 changed files with 82 additions and 20 deletions

20
.vscode/tasks.json vendored
View File

@@ -28,7 +28,7 @@
"presentation": { "presentation": {
"group": "groupZomboid" "group": "groupZomboid"
}, },
"command": "\"${config:zomboid_folder_b42}\\ProjectZomboid64 - nosteam-debug 42.bat\"", "command": "\"${config:zomboid_folder_b42}\\ProjectZomboid64_Debug_NoSteam.bat\"",
"options": {"statusbar": {"label": "$(run) Zomboid client (42)"}}, "options": {"statusbar": {"label": "$(run) Zomboid client (42)"}},
"problemMatcher": [ "problemMatcher": [
"$eslint-stylish" "$eslint-stylish"
@@ -67,15 +67,15 @@
// "Run Zomboid Debug No Steam", "Run Zomboid Debug No Steam 2"], // "Run Zomboid Debug No Steam", "Run Zomboid Debug No Steam 2"],
// "problemMatcher": [] // "problemMatcher": []
// }, // },
// { {
// "label": "Run Zomboid Test Server", "label": "Run Zomboid Test Server",
// "options": {"statusbar": {"label": "$(run) Zomboid Server (TOC)"}}, "options": {"statusbar": {"label": "$(run) Zomboid Server (TOC)"}},
// "type": "shell", "type": "shell",
// "command":"\"${config:zomboid_server_folder}\\StartServer64_nosteam_custom.bat\" TOC", "command":"\"${config:zomboid_server_folder}\\StartServer64_nosteam_custom.bat\" TOC",
// "problemMatcher": [ "problemMatcher": [
// "$eslint-stylish" "$eslint-stylish"
// ] ]
// }, },
// { // {
// "label": "Run Zomboid Test Server 2", // "label": "Run Zomboid Test Server 2",
// "options": {"statusbar": {"label": "$(run) Zomboid Server (TOC+FH+BH)"}}, // "options": {"statusbar": {"label": "$(run) Zomboid Server (TOC+FH+BH)"}},

View File

@@ -1,6 +1,8 @@
local DataController = require("TOC/Controllers/DataController") local DataController = require("TOC/Controllers/DataController")
local CommonMethods = require("TOC/CommonMethods") local CommonMethods = require("TOC/CommonMethods")
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local CommandsData = require("TOC/CommandsData")
local StaticData = require("TOC/StaticData") local StaticData = require("TOC/StaticData")
require("TOC/Events") require("TOC/Events")
local TOC = require("TOC/Registries") local TOC = require("TOC/Registries")
@@ -38,8 +40,7 @@ function LocalPlayerController.InitializePlayer(isForced)
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too -- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
if isForced then if isForced then
local ItemsController = require("TOC/Controllers/ItemsController") sendClientCommand(CommandsData.modules.TOC_ITEMS, "DeleteAllOldAmputationItems", {playerNum = playerObj:getOnlineID()})
ItemsController.Player.DeleteAllOldAmputationItems(playerObj)
CachedDataHandler.Setup(username) CachedDataHandler.Setup(username)
end end
@@ -319,9 +320,10 @@ function LocalPlayerController.HandleSetCicatrization(dcInst, playerObj, limbNam
dcInst:setIsCicatrized(limbName, true) dcInst:setIsCicatrized(limbName, true)
dcInst:setCicatrizationTime(limbName, 0) dcInst:setCicatrizationTime(limbName, 0)
-- Set visuals for the amputation -- -- Set visuals for the amputation
local ItemsController = require("TOC/Controllers/ItemsController") sendClientCommand(CommandsData.modules.TOC_ITEMS, "OverrideAmputationItemVisuals",
ItemsController.Player.OverrideAmputationItemVisuals(playerObj, limbName, true) {playerNum = playerObj:getOnlineID(), limbName = limbName, isCicatrized = true})
end end
--* Object drop handling when amputation occurs --* Object drop handling when amputation occurs

View File

@@ -2,7 +2,7 @@
local DataController = require("TOC/Controllers/DataController") local DataController = require("TOC/Controllers/DataController")
local ItemsController = require("TOC/Controllers/ItemsController") local CommandsData = require("TOC/CommandsData")
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local LocalPlayerController = require("TOC/Controllers/LocalPlayerController") local LocalPlayerController = require("TOC/Controllers/LocalPlayerController")
local StaticData = require("TOC/StaticData") local StaticData = require("TOC/StaticData")
@@ -177,8 +177,15 @@ function AmputationHandler:execute(damagePlayer)
LocalPlayerController.HealArea(bodyPart) LocalPlayerController.HealArea(bodyPart)
-- Give the player the correct amputation item -- Give the player the correct amputation item
ItemsController.Player.DeleteOldAmputationItem(self.patientPl, self.limbName)
ItemsController.Player.SpawnAmputationItem(self.patientPl, self.limbName) -- FIX This can be done in a single step instead of this crap
sendClientCommand(CommandsData.modules.TOC_ITEMS, "DeleteOldAmputationItem",
{playerNum = self.patientPl:getOnlineID(), limbName = self.limbName})
sendClientCommand(CommandsData.modules.TOC_ITEMS, "SpawnAmputationItem",
{playerNum = self.patientPl:getOnlineID(), limbName = self.limbName})
--ItemsController.Player.DeleteOldAmputationItem(self.patientPl, self.limbName)
--ItemsController.Player.SpawnAmputationItem(self.patientPl, self.limbName)
-- Add it to the list of cut limbs on this local client -- Add it to the list of cut limbs on this local client
local username = self.patientPl:getUsername() local username = self.patientPl:getUsername()

View File

@@ -49,6 +49,8 @@ function ItemsController.Player.RemoveClothingItem(playerObj, clothingItem)
---@diagnostic disable-next-line: param-type-mismatch ---@diagnostic disable-next-line: param-type-mismatch
playerObj:getInventory():Remove(clothingItem) -- Umbrella is wrong, can be an InventoryItem too playerObj:getInventory():Remove(clothingItem) -- Umbrella is wrong, can be an InventoryItem too
sendRemoveItemFromContainer(playerObj:getInventory(), clothingItem)
TOC_DEBUG.print("found and deleted" .. tostring(clothingItem)) TOC_DEBUG.print("found and deleted" .. tostring(clothingItem))
-- Reset model -- Reset model
@@ -108,11 +110,13 @@ end
function ItemsController.Player.SpawnAmputationItem(playerObj, limbName) function ItemsController.Player.SpawnAmputationItem(playerObj, limbName)
TOC_DEBUG.print("clothing name " .. StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName) TOC_DEBUG.print("clothing name " .. StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName)
local clothingItem = playerObj:getInventory():AddItem(StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName) local clothingItem = playerObj:getInventory():AddItem(StaticData.AMPUTATION_CLOTHING_ITEM_BASE .. limbName)
local texId = ItemsController.Player.GetAmputationTexturesIndex(playerObj, false) local texId = ItemsController.Player.GetAmputationTexturesIndex(playerObj, false)
---@cast clothingItem InventoryItem ---@cast clothingItem InventoryItem
clothingItem:getVisual():setTextureChoice(texId) -- it counts from 0, so we have to subtract 1 clothingItem:getVisual():setTextureChoice(texId) -- it counts from 0, so we have to subtract 1
playerObj:setWornItem(clothingItem:getBodyLocation(), clothingItem) playerObj:setWornItem(clothingItem:getBodyLocation(), clothingItem)
sendAddItemToContainer(playerObj:getInventory(), clothingItem)
end end
---Search through worn items and modifies a specific amputation item ---Search through worn items and modifies a specific amputation item

View File

@@ -0,0 +1,44 @@
require ("TOC/Debug")
local CommandsData = require("TOC/CommandsData")
local ItemsController = require("TOC/Controllers/ItemsController")
--------------------------------------------
local ServerItemsCommands = {}
function ServerItemsCommands.SpawnAmputationItem(_, args)
local playerObj = getPlayerByOnlineID(args.playerNum)
local limbName = args.limbName
ItemsController.Player.SpawnAmputationItem(playerObj, limbName)
end
function ServerItemsCommands.DeleteOldAmputationItem(_, args)
local patientPl = getPlayerByOnlineID(args.playerNum)
local limbName = args.limbName
ItemsController.Player.DeleteOldAmputationItem(patientPl, limbName)
end
function ServerItemsCommands.DeleteAllOldAmputationItems(_, args)
local playerObj = getPlayerByOnlineID(args.playerNum)
ItemsController.Player.DeleteAllOldAmputationItems(playerObj)
end
function ServerItemsCommands.OverrideAmputationItemVisuals(_, args)
local playerObj = getPlayerByOnlineID(args.playerNum)
local limbName = args.limbName
local isCicatrized = args.isCicatrized
ItemsController.Player.OverrideAmputationItemVisuals(playerObj, limbName, isCicatrized)
end
--------------------------------------------------------------------
local function OnClientItemsCommands(module, command, playerObj, args)
if module == CommandsData.modules.TOC_ITEMS and ServerItemsCommands[command] then
TOC_DEBUG.print("Received ItemsController command - " .. tostring(command))
ServerItemsCommands[command](playerObj, args)
end
end
Events.OnClientCommand.Add(OnClientItemsCommands)

View File

@@ -53,7 +53,11 @@ function ServerRelayCommands.RelayForcedAmputation(adminObj, args)
sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveForcedCicatrization, {limbName = args.limbName}) sendServerCommand(patientPl, CommandsData.modules.TOC_RELAY, CommandsData.client.Relay.ReceiveForcedCicatrization, {limbName = args.limbName})
end end
function ServerRelayCommands.DeleteAllOldAmputationItems(_, args)
local playerObj = getPlayerByOnlineID(args.playerNum)
local ItemsController = require("TOC/Controllers/ItemsController")
ItemsController.Player.DeleteAllOldAmputationItems(playerObj)
end
------------------------- -------------------------

View File

@@ -5,7 +5,8 @@ local CommandsData = {}
CommandsData.modules = { CommandsData.modules = {
TOC_DEBUG = "TOC_DEBUG", TOC_DEBUG = "TOC_DEBUG",
TOC_RELAY = "TOC_RELAY" TOC_RELAY = "TOC_RELAY",
TOC_ITEMS = "TOC_ITEMS"
} }
CommandsData.client = { CommandsData.client = {