Fixed more MP stuff

This commit is contained in:
Pao
2023-01-13 10:17:41 +01:00
parent 3938c540b4
commit 06bc050ebc
4 changed files with 85 additions and 53 deletions

View File

@@ -52,16 +52,6 @@ function AskCanOperateLimb(player, part_name)
end
function AskCanResetEverything(other_player)
GetConfirmUIMP().responseReceive = false;
local arg = {}
arg["From"] = getPlayer():getOnlineID()
arg["To"] = other_player:getOnlineID()
arg["command"] = "CanResetEverything"
arg["toSend"] = {}
sendClientCommand("TOC", "SendServer", arg)
end
-- Patient (receive)
Commands["CutLimb"] = function(arg)
local arg = arg["toSend"]
@@ -109,32 +99,41 @@ Commands["ResetEverything"] = function(arg)
ResetEverything()
end
-- Cheating stuff
Commands["AcceptResetEverything"] = function(arg)
local clicked_player = getPlayerByOnlineID(arg[1]) -- TODO delete this
ResetEverything()
end
-- Base stuff
Commands["GivePlayerData"] = function(arg)
local surgeon_id = arg[1]
local patient = getPlayerByOnlineID(arg[2])
local toc_data = patient:getModData().TOC
sendClientCommand(patient, "TOC", "SendPlayerData", {surgeon_id, toc_data})
end
Commands["SendTocData"] = function(arg)
print("Sending TOC data")
local patient = getPlayerByOnlineID(arg[1])
MP_other_player_toc_data = arg[2]
end
local function OnTocServerCommand(module, command, args)
if module == 'TOC' then
if command == 'GivePlayerData' then
--local surgeon = getPlayerByOnlineID(args[1])
local surgeon_id = args[1]
local patient = getPlayerByOnlineID(args[2])
local toc_data = patient:getModData().TOC
-- todo maybe we cant send a table like this. Let's try something easier
--local moneyAmount = playerTwo:getInventory():getCountTypeRecurse("Money")
print("Giving info")
-- not fast enough, wont get toc_data in time. FInd a better way to send and get data
sendClientCommand(patient, "TOC", "SendPlayerData", {surgeon_id, toc_data})
elseif command == 'SendTocData' then
print("Sending TOC data")
local patient = getPlayerByOnlineID(args[1]) --todo cant we delete this>?
-- ew a global var.... but dunno if there's a better way to do this
MP_other_player_toc_data = args[2]
elseif Commands[command] then
print("OnTocServerCommand " .. command)
if Commands[command] then
args = args or {}
Commands[command](args)

View File

@@ -22,6 +22,14 @@ local function OperateLocal(_, patient, surgeon, part_name, use_oven)
end
function TryToToResetEverythingOtherPlayer(_, patient, surgeon)
sendClientCommand(surgeon, "TOC", "AskToResetEverything", {patient:getOnlineID()})
end
--TODO Make the name more unique
function TryActionOnOtherPlayerLocal(_, part_name, action, surgeon, patient)
@@ -35,8 +43,6 @@ function TryActionOnOtherPlayerLocal(_, part_name, action, surgeon, patient)
AskCanCutLimb(patient, part_name)
elseif action == "Operate" then
AskCanOperateLimb(patient, part_name)
elseif action == "ResetEverything" then
AskCanResetEverything(patient)
end
ui.actionAct = action
ui.partNameAct = part_name
@@ -100,10 +106,10 @@ function ISWorldObjectContextMenu.OnFillTOCMenu(player, context, worldObjects, t
if clickedPlayer == player_obj then
cheat_menu:addOption("Reset TOC for me", worldObjects, ResetEverything, clickedPlayer)
cheat_menu:addOption("Reset TOC for me", worldObjects, ResetEverything)
else
cheat_menu:addOption("Reset TOC for " .. clickedPlayer:getUsername(), worldObjects, TryActionOnOtherPlayerLocal, _, "ResetEverything", player_obj, clickedPlayer)
cheat_menu:addOption("Reset TOC for " .. clickedPlayer:getUsername(), worldObjects, TryToToResetEverythingOtherPlayer, clickedPlayer, player_obj)
end
end

View File

@@ -616,7 +616,15 @@ function ISNewHealthPanel.onClick_TOC(button)
if button.otherPlayer then
if button.character ~= button.otherPlayer then
sendClientCommand(button.otherPlayer, "TOC", "GetPlayerData", {button.otherPlayer:getOnlineID(), button.character:getOnlineID()})
if MP_other_player_toc_data == nil then
print("MP_other_player_toc_data is still nil")
else
SetCorrectArgsMainUI(MP_other_player_toc_data) --other player is the surgeon
end
else
SetCorrectArgsMainUI(getPlayer():getModData().TOC) --myself?

View File

@@ -3,28 +3,47 @@
---Server side
local Commands = {}
--TODO how does this work
Commands["SendServer"] = function(player, arg)
local otherPlayer = getPlayerByOnlineID(arg["To"])
print("The Only Cure Command: ", arg['command'])
sendServerCommand(otherPlayer, "TOC", arg["command"], arg)
end
-- To make the UI Work
Commands["GetPlayerData"] = function(_, arg)
local surgeon_id = arg[1]
local patient_id = arg[2]
local patient = getPlayerByOnlineID(arg[2])
sendServerCommand(patient, "TOC", "GivePlayerData", {surgeon_id, patient_id})
end
Commands["SendPlayerData"] = function(_, arg)
local surgeon = getPlayerByOnlineID(arg[1])
local surgeon_id = arg[1]
local toc_data = arg[2]
sendServerCommand(surgeon, "TOC", "SendTocData", {surgeon_id, toc_data})
end
-- CHEATING STUFF
Commands["AskToResetEverything"] = function (_, arg)
local clicked_player = getPlayerByOnlineID(arg[1])
local clicked_player_id = arg[1]
sendServerCommand(clicked_player, "TOC", "AcceptResetEverything", {clicked_player_id})
end
local function OnTocClientCommand(module, command, player, args)
if module == 'TOC' then
print(command)
if command == 'GetPlayerData' then
local surgeon_id = args[1]
local patient_id = args[2]
--local playerOne = getPlayerByOnlineID(args[1])
local patient = getPlayerByOnlineID(args[2])
--local playerOneID = args[1]
sendServerCommand(patient, "TOC", "GivePlayerData", {surgeon_id, patient_id})
elseif command == 'SendPlayerData' then
local surgeon = getPlayerByOnlineID(args[1])
local surgeon_id = args[1]
local toc_data = args[2]
sendServerCommand(surgeon, "TOC", "SendTocData", {surgeon_id, toc_data})
elseif Commands[command] then
print("OnTocClientCommand " .. command)
if Commands[command] then
args = args or {}
Commands[command](_, args)
end