diff --git a/media/lua/client/TOC_Client.lua b/media/lua/client/TOC_Client.lua index 04aaab9..2d79376 100644 --- a/media/lua/client/TOC_Client.lua +++ b/media/lua/client/TOC_Client.lua @@ -12,6 +12,56 @@ Commands["ResponseCanAct"] = function(arg) ui.responseActionIsBitten = getPlayerByOnlineID(arg["From"]):getBodyDamage():getBodyPart(TOC_getBodyPart(ui.responsePartName)):bitten() end + +function SendCutLimb(player, part_name, surgeon_factor, bandage_table, painkiller_table) + local arg = {} + arg["From"] = getPlayer():getOnlineID() + arg["To"] = player:getOnlineID() + arg["command"] = "CutLimb" + arg["toSend"] = {part_name, surgeon_factor, bandage_table, painkiller_table} + sendClientCommand("TOC", "SendServer", arg) +end + +function SendOperateLimb(player, part_name, surgeon_factor, use_oven) + local arg = {} + arg["From"] = getPlayer():getOnlineID() + arg["To"] = player:getOnlineID() + arg["command"] = "OperateLimb" + arg["toSend"] = {part_name, surgeon_factor, use_oven} + sendClientCommand("TOC", "SendServer", arg) +end + +function AskCanCutLimb(player, part_name) + GetConfirmUIMP().responseReceive = false; + local arg = {}; + arg["From"] = getPlayer():getOnlineID(); + arg["To"] = player:getOnlineID(); + arg["command"] = "CanCutLimb"; + arg["toSend"] = part_name; + sendClientCommand("TOC", "SendServer", arg); +end + +function AskCanOperateLimb(player, part_name) + GetConfirmUIMP().responseReceive = false; + local arg = {}; + arg["From"] = getPlayer():getOnlineID(); + arg["To"] = player:getOnlineID(); + arg["command"] = "CanOperateLimb"; + arg["toSend"] = part_name; + sendClientCommand("TOC", "SendServer", arg); +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"] @@ -20,7 +70,7 @@ end Commands["OperateLimb"] = function(arg) local arg = arg["toSend"] - OperateLimb(arg[1], arg[2], arg[3]) + TheOnlyCure.OperateLimb(arg[1], arg[2], arg[3]) end Commands["CanCutLimb"] = function(arg) @@ -43,6 +93,21 @@ Commands["CanOperateLimb"] = function(arg) sendClientCommand("TOC", "SendServer", arg) end +Commands["CanResetEverything"] = function(arg) + local arg = arg["toSend"] --useless + + arg["To"] = arg["From"] + arg["From"] = getPlayer():getOnlineID() + arg["command"] = "ResponseCanAct" + arg["toSend"] = {} + sendClientCommand("TOC", "SendServer", arg) + --ResetEverything() +end + +Commands["ResetEverything"] = function(arg) + local arg = arg["toSend"] + ResetEverything() +end local function OnTocServerCommand(module, command, args) if module == 'TOC' then diff --git a/media/lua/client/TOC_ContextMenus.lua b/media/lua/client/TOC_ContextMenus.lua index 42d2a6e..55c6a15 100644 --- a/media/lua/client/TOC_ContextMenus.lua +++ b/media/lua/client/TOC_ContextMenus.lua @@ -21,8 +21,8 @@ local function OperateLocal(_, patient, surgeon, part_name, use_oven) end end - -function TheOnlyCure.TryActionOnOtherPlayerLocal(_, part_name, action, surgeon, patient) +--TODO Make the name more unique +function TryActionOnOtherPlayerLocal(_, part_name, action, surgeon, patient) local ui = GetConfirmUIMP() if not ui then @@ -32,14 +32,12 @@ function TheOnlyCure.TryActionOnOtherPlayerLocal(_, part_name, action, surgeon, if action == "Cut" then AskCanCutLimb(patient, part_name) - --AskCanCutArm(patient, part_name); elseif action == "Operate" then AskCanOperateLimb(patient, part_name) - --AskCanOperateArm(patient, part_name); end - ui.actionAct = action; - ui.partNameAct = part_name; - ui.patient = patient; + ui.actionAct = action + ui.partNameAct = part_name + ui.patient = patient SetConfirmUIMP("Wait server") end @@ -90,6 +88,23 @@ function ISWorldObjectContextMenu.OnFillTOCMenu(player, context, worldObjects, t local cutMenu = context:getNew(context); local operateMenu = context:getNew(context); + + -- admin stuff + if clickedPlayer:getAccessLevel() == "Admin" then + local cheat_option = rootMenu:addOption("Cheat") + local cheat_menu = context:getNew(context) + context:addSubMenu(cheat_option, cheat_menu) + + + if clickedPlayer == player_obj then + cheat_menu:addOption("Reset TOC for me", worldObjects, ResetEverything, clickedPlayer) + + else + cheat_menu:addOption("Reset TOC for " .. clickedPlayer:getUsername(), worldObjects, AskCanResetEverything, clickedPlayer) + + end + end + context:addSubMenu(rootOption, rootMenu); context:addSubMenu(cutOption, cutMenu); context:addSubMenu(operateOption, operateMenu); @@ -105,8 +120,8 @@ function ISWorldObjectContextMenu.OnFillTOCMenu(player, context, worldObjects, t cutMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, CutLocal, player_obj, player_obj, v_part) operateMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, OperateLocal, player_obj, player_obj, v_part) else - cutMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, TheOnlyCure.TryActionOnOtherPlayerLocal, v_part, "Cut", player_obj, clickedPlayer) - operateMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, TheOnlyCure.TryActionOnOtherPlayerLocal, v_part, "Operate", player_obj, clickedPlayer); + cutMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, TryActionOnOtherPlayerLocal, v_part, "Cut", player_obj, clickedPlayer) + operateMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, TryActionOnOtherPlayerLocal, v_part, "Operate", player_obj, clickedPlayer); end diff --git a/media/lua/client/TOC_Debug.lua b/media/lua/client/TOC_Debug.lua new file mode 100644 index 0000000..f351168 --- /dev/null +++ b/media/lua/client/TOC_Debug.lua @@ -0,0 +1,22 @@ +function ResetEverything() + + local player = getPlayer() + local mod_data = player:getModData() -- TODO we need to send data... + mod_data.TOC = nil + TheOnlyCure.InitTheOnlyCure(_, player) + + -- Destroy the amputation model + + for _,v in ipairs(GetBodyParts()) do + local cloth = player:getInventory():FindAndReturn(find_clothName2_TOC(v)) + + if cloth ~= nil then + player:removeWornItem(cloth) + player:getInventory():Remove(cloth:getName()) + end + + end + + player:transmitModData() + +end diff --git a/media/lua/client/TOC_HelperFunctions.lua b/media/lua/client/TOC_HelperFunctions.lua index fc1e2b7..fc2ae9e 100644 --- a/media/lua/client/TOC_HelperFunctions.lua +++ b/media/lua/client/TOC_HelperFunctions.lua @@ -1,5 +1,6 @@ -- CutLimb -function TheOnlyCure.CheckIfStillInfected(toc_data) +-- TODO if TheONlyCure. triggers an errors +function CheckIfStillInfected(toc_data) if toc_data == nil then return end @@ -21,7 +22,8 @@ function TheOnlyCure.CheckIfStillInfected(toc_data) end -function TheOnlyCure.CureInfection(body_damage) +-- TODO this triggers an error +function CureInfection(body_damage) body_damage:setInfected(false) body_damage:setInfectionMortalityDuration(-1) body_damage:setInfectionTime(-1) @@ -38,7 +40,7 @@ end -- OperateLimb -function TheOnlyCure.SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven) +function SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven) --for _, v in ipairs(GetBodyParts()) do diff --git a/media/lua/client/TOC_main.lua b/media/lua/client/TOC_main.lua index 76c38b6..287bdcb 100644 --- a/media/lua/client/TOC_main.lua +++ b/media/lua/client/TOC_main.lua @@ -160,8 +160,8 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille body_part_type:SetBitten(false) -- Second check, let's see if there is any other infected limb. - if TheOnlyCure.CheckIfStillInfected(toc_data) == false then - TheOnlyCure.CureInfection(body_damage) + if CheckIfStillInfected(toc_data) == false then + CureInfection(body_damage) getPlayer():Say("I'm gonna be fine") else getPlayer():Say("I'm still gonna die...") @@ -211,7 +211,7 @@ function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven) end - TheOnlyCure.SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven) + SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven) player:transmitModData() end diff --git a/media/lua/client/TimedActions/NewOnCut_old.lua b/media/lua/client/TimedActions/NewOnCut_old.lua deleted file mode 100644 index 9945575..0000000 --- a/media/lua/client/TimedActions/NewOnCut_old.lua +++ /dev/null @@ -1,96 +0,0 @@ --- require "TimedActions/ISBaseTimedAction" - --- IsCutArm = ISBaseTimedAction:derive("IsCutArm"); - --- function IsCutArm:isValid() --- return self.patientX == self.patient:getX() and self.patientY == self.patient:getY(); --- end - --- function IsCutArm:waitToStart() --- if self.patient == self.surgeon then --- return false --- end --- self.surgeon:faceThisObject(self.patient) --- return self.surgeon:shouldBeTurning() --- end - --- function IsCutArm:update() --- if self.patient ~= self.surgeon then --- self.surgeon:faceThisObject(self.patient) --- end --- end - --- function IsCutArm:start() --- if self.patient == self.surgeon then --- self:setActionAnim("WearClothing"); --- self:setAnimVariable("WearClothingLocation", "Jacket") --- else --- self:setActionAnim("Loot") --- self.patient:SetVariable("LootPosition", "Mid") --- end --- end - --- function IsCutArm:findArgs() --- local useBandage, bandageAlcool, usePainkiller, painkillerCount --- local surgeonFact = self.surgeon:getPerkLevel(Perks.Doctor); --- if self.surgeon:getDescriptor():getProfession() == "surgeon" then surgeonFact = surgeonFact + 15 end --- if self.surgeon:getDescriptor():getProfession() == "doctor" then surgeonFact = surgeonFact + 9 end --- if self.surgeon:getDescriptor():getProfession() == "nurse" then surgeonFact = surgeonFact + 4 end - --- local bandage = self.surgeon:getInventory():FindAndReturn('Bandage'); --- local albandage = self.surgeon:getInventory():FindAndReturn('AlcoholBandage'); --- if albandage then --- useBandage = true; --- bandageAlcool = true; --- self.patient:getInventory():Remove(albandage); --- surgeonFact = surgeonFact + 4 --- elseif bandage then --- useBandage = true; --- self.patient:getInventory():Remove(bandage); --- surgeonFact = surgeonFact + 2 --- end - --- local painkiller = self.surgeon:getInventory():FindAndReturn('Pills'); --- if painkiller then --- usePainkiller = true; --- painkillerCount = painkiller:getRemainingUses(); --- end - --- return surgeonFact, useBandage, bandageAlcool, usePainkiller, painkillerCount; --- end - --- function IsCutArm:perform() --- local surgeonFact, useBandage, bandageAlcool, usePainkiller, painkillerCount = self:findArgs(); - --- if self.patient ~= self.surgeon and isClient() then --- SendCutArm(self.patient, self.partName, surgeonFact, useBandage, bandageAlcool, usePainkiller, painkillerCount); --- else --- CutArm(self.partName, surgeonFact, useBandage, bandageAlcool, usePainkiller, painkillerCount); --- end --- self.surgeon:getXp():AddXP(Perks.Doctor, 400); - --- ISBaseTimedAction.perform(self); --- end - --- function IsCutArm:new(patient, surgeon, partName) --- local o = {} --- setmetatable(o, self) --- self.__index = self --- o.partName = partName; --- o.bodyPart = TOC_getBodyPart(partName); --- o.character = surgeon; -- For anim - --- o.surgeon = surgeon; -- Surgeon or player that make the operation --- o.patient = patient; -- Player to cut - --- o.patientX = patient:getX(); --- o.patientY = patient:getY(); - --- o.maxTime = 1000 - (surgeon:getPerkLevel(Perks.Doctor) * 50); --- o.stopOnWalk = true; --- o.stopOnRun = true; --- o.ignoreHandsWounds = false; --- o.fromHotbar = true; --- if o.patient:isTimedActionInstant() then o.maxTime = 1; end --- return o; --- end \ No newline at end of file diff --git a/media/lua/server/TOC_MP_server.lua b/media/lua/server/TOC_MP_server.lua index b139546..0aa5ea8 100644 --- a/media/lua/server/TOC_MP_server.lua +++ b/media/lua/server/TOC_MP_server.lua @@ -1,5 +1,5 @@ --- A rly big thx to Fenris_Wolf and Chuck to help me with that. Love you guy -if isClient() then return end +--if isClient() then return end ---Server side local Commands = {} @@ -9,44 +9,6 @@ Commands["SendServer"] = function(player, arg) sendServerCommand(otherPlayer, "TOC", arg["command"], arg) end -function SendCutLimb(player, part_name, surgeon_factor, bandage_table, painkiller_table) - local arg = {} - arg["From"] = getPlayer():getOnlineID() - arg["To"] = player:getOnlineID() - arg["command"] = "CutLimb" - arg["toSend"] = {part_name, surgeon_factor, bandage_table, painkiller_table} - sendClientCommand("TOC", "SendServer", arg) -end - -function SendOperateLimb(player, part_name, surgeon_factor, use_oven) - local arg = {} - arg["From"] = getPlayer():getOnlineID() - arg["To"] = player:getOnlineID() - arg["command"] = "OperateLimb" - arg["toSend"] = {part_name, surgeon_factor, use_oven} - sendClientCommand("TOC", "SendServer", arg) -end - -function AskCanCutLimb(player, part_name) - GetConfirmUIMP().responseReceive = false; - local arg = {}; - arg["From"] = getPlayer():getOnlineID(); - arg["To"] = player:getOnlineID(); - arg["command"] = "CanCutLimb"; - arg["toSend"] = part_name; - sendClientCommand("TOC", "SendServer", arg); -end - -function AskCanOperateLimb(player, part_name) - GetConfirmUIMP().responseReceive = false; - local arg = {}; - arg["From"] = getPlayer():getOnlineID(); - arg["To"] = player:getOnlineID(); - arg["command"] = "CanOperateArm"; - arg["toSend"] = part_name; - sendClientCommand("TOC", "SendServer", arg); -end - local function OnTocClientCommand(module, command, player, args) if module == 'TOC' then print(command) @@ -62,7 +24,7 @@ local function OnTocClientCommand(module, command, player, args) local surgeon_id = args[1] local toc_data = args[2] sendServerCommand(surgeon, "TOC", "SendTocData", {surgeon_id, toc_data}) - elseif command == Commands[command] then + elseif Commands[command] then args = args or {} Commands[command](_, args) end