From 014165df1280fe6ce9090eeb97775fe3a203e5af Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Thu, 14 Nov 2019 21:17:30 +0100 Subject: [PATCH 01/15] Update MethHelper.lua - Fixed some Bugs - Works now on Border Crystals --- lua/MethHelper.lua | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index bcaaed4..d28d5c7 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -3,6 +3,9 @@ local RatsFinishedID = "pln_rat_stage1_28" local RatsAddedID = "pln_rat_stage1_12" local CookoffFinishedID = "pln_rt1_28" local CookoffAddedID = "pln_rt1_12" +local BorderCrystalFinsishedID = "Play_loc_mex_cook_17" +local BorderCrystalFinsishedID2 = "Play_loc_mex_cook_13" +local BorderCrystalAddedID = "Play_loc_mex_cook_22" -- Dictionary mapping dialogue codes to plain text ingredients local ingredient_dialog = {} @@ -12,11 +15,17 @@ ingredient_dialog["pln_rt1_24"] = "Hydrogen Chloride" ingredient_dialog["pln_rat_stage1_20"] = "Muriatic Acid" ingredient_dialog["pln_rat_stage1_22"] = "Caustic Soda" ingredient_dialog["pln_rat_stage1_24"] = "Hydrogen Chloride" +ingredient_dialog["Play_loc_mex_cook_03"] = "Muriatic Acid" +ingredient_dialog["Play_loc_mex_cook_04"] = "Caustic Soda" +ingredient_dialog["Play_loc_mex_cook_05"] = "Hydrogen Chloride" -- Round about hacky way to trigger by both ingredients and recipe state dialogue ingredient_dialog [RatsFinishedID] = true ingredient_dialog [RatsAddedID] = true ingredient_dialog [CookoffFinishedID] = true ingredient_dialog [CookoffAddedID] = true +ingredient_dialog [BorderCrystalFinsishedID] = true +ingredient_dialog [BorderCrystalFinsishedID2] = true +ingredient_dialog [BorderCrystalAddedID] = true -- Track number of ingredients in current meth recipe local currentRecipe = 1 @@ -35,7 +44,7 @@ function clampCeiling (val, vMax) end return val - +end -- Trigger this every time there is dialogue local _queue_dialog_orig = DialogManager.queue_dialog function DialogManager:queue_dialog(id, ...) @@ -43,7 +52,7 @@ function DialogManager:queue_dialog(id, ...) -- If dialogue code is found in dict if ingredient_dialog[id] then -- If "batch finished" dialogue is played - if id == CookoffFinishedID or id == RatsFinishedID then + if id == CookoffFinishedID or id == RatsFinishedID or id == BorderCrystalFinsishedID or id == BorderCrystalFinsishedID2 then currentRecipe = 1 totalBags = totalBags + 1 -- Reset recipe state @@ -51,12 +60,16 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList ["Caustic Soda"] = false currentRecipeList ["Hydrogen Chloride"] = false - managers.chat:_receive_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) + managers.chat:send_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) -- If "ingredient added" dialogue is played - elseif (id == CookoffAddedID or id == RatsAddedID) and (currentRecipe ["Muriatic Acid"] == true and currentRecipeList ["Caustic Soda"] == true and currentRecipeList ["Hydrogen Chloride"] == true) then + elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and ((currentRecipeList ["Muriatic Acid"] == true and currentRecipeList ["Caustic Soda"] == true and currentRecipeList ["Hydrogen Chloride"] == true) == false) and ((currentRecipeList ["Muriatic Acid"] == false and currentRecipeList ["Caustic Soda"] == false and currentRecipeList ["Hydrogen Chloride"] == false) == false) then currentRecipe = clampCeiling (currentRecipe + 1, 3) + managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) + elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and currentRecipe == 3 then + currentRecipe = clampCeiling (currentRecipe + 1, 3) + managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) -- Else ID is for ingredient else -- Check to make sure that the ingredient is not already being echoed @@ -65,11 +78,13 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList [ingredient_dialog [id]] = true -- Print text - managers.chat:_receive_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) + managers.chat:send_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) end end end - + -- for event mapping + --log("DialogManager: said " .. tostring(id)) + --managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) return _queue_dialog_orig(self, id, ...) end -- feed_system_message () shows it to you and nobody else From 9a752ca439574577ca1823f45151c16a33761e7d Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Thu, 14 Nov 2019 21:19:16 +0100 Subject: [PATCH 02/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7056e5f..9600e43 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A mod for PAYDAY 2 which notifies the player as to which meth ingredient is to b Mod will print the current required ingredient to the host of the mod (that's you) and nobody else. All messages from MethHelper will be preceeded by the tag "[MethHelper]". -Works with Cook Off, Rats day 1, Hotline Miami day 1, and Bomb Dockyard. +Works with Cook Off, Rats day 1, Hotline Miami day 1, Border Crystal and Bomb Dockyard. # How to install In order to install this mod, follow the outlined steps below: From 1215033115398fce4c19e22d61ed3ecba4d48708 Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Fri, 15 Nov 2019 11:00:45 +0100 Subject: [PATCH 03/15] Add files via upload From abc557328511c1dfc85f855444b1f3ff285d9558 Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Fri, 15 Nov 2019 11:01:35 +0100 Subject: [PATCH 04/15] Add files via upload --- lua/MethHelper.lua | 94 ++++++++++++++++++++++++++++++++++++++++++---- menu/lang.json | 8 ++++ menu/menu.json | 27 +++++++++++++ 3 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 menu/lang.json create mode 100644 menu/menu.json diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index d28d5c7..103745b 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -1,3 +1,63 @@ +_G.MethHelper = _G.MethHelper or {} +MethHelper._path = ModPath +MethHelper._data_path = ModPath .. "saved_options_meth_helper.txt" +MethHelper._data = {} + +function MethHelper:Save() + local file = io.open( self._data_path, "w+" ) + if file then + file:write( json.encode( self._data ) ) + file:close() + end +end + +function MethHelper:Load() + local file = io.open( self._data_path, "r" ) + if file then + self._data = json.decode( file:read("*all") ) + file:close() + end +end + +Hooks:Add("LocalizationManagerPostInit", "LocalizationManagerPostInit_MethHelper", function( loc ) + loc:load_localization_file( MethHelper._path .. "menu/" .. "lang.json") +end) + +Hooks:Add( "MenuManagerInitialize", "MenuManagerInitialize_MethHelper", function( menu_manager ) + + --[[ + Setup our callbacks as defined in our item callback keys, and perform our logic on the data retrieved. + ]] + MenuCallbackHandler.callback_meth_helper_active = function(self, item) + MethHelper._data.meth_helper_active_value = (item:value() == "on" and true or false) + MethHelper:Save() + MethHelper.active_toggle = item:value() + log("Active Toggle is: " .. item:value()) + end + + MenuCallbackHandler.callback_meth_helper_silent = function(self, item) + MethHelper._data.meth_helper_silent_value = (item:value() == "on" and true or false) + MethHelper:Save() + MethHelper.silent_toggle = item:value() + log("Silent Toggle is: " .. item:value()) + end + + + --[[ + Load our previously saved data from our save file. + ]] + MethHelper:Load() + + --[[ + Load our menu json file and pass it to our MenuHelper so that it can build our in-game menu for us. + We pass our parent mod table as the second argument so that any keybind functions can be found and called + as necessary. + We also pass our data table as the third argument so that our saved values can be loaded from it. + ]] + MenuHelper:LoadFromJsonFile( MethHelper._path .. "menu/menu.json", MethHelper, MethHelper._data ) + +end ) + -- Dialogue event codes local RatsFinishedID = "pln_rat_stage1_28" local RatsAddedID = "pln_rat_stage1_12" @@ -45,12 +105,13 @@ function clampCeiling (val, vMax) return val end + -- Trigger this every time there is dialogue local _queue_dialog_orig = DialogManager.queue_dialog function DialogManager:queue_dialog(id, ...) -- If dialogue code is found in dict - if ingredient_dialog[id] then + if ingredient_dialog[id] and MethHelper.active_toggle then -- If "batch finished" dialogue is played if id == CookoffFinishedID or id == RatsFinishedID or id == BorderCrystalFinsishedID or id == BorderCrystalFinsishedID2 then currentRecipe = 1 @@ -59,17 +120,30 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList ["Muriatic Acid"] = false currentRecipeList ["Caustic Soda"] = false currentRecipeList ["Hydrogen Chloride"] = false - - managers.chat:send_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) - + --check menu options + if MethHelper.silent_toggle then + managers.chat:_receive_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) + else + managers.chat:send_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) + end -- If "ingredient added" dialogue is played elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and ((currentRecipeList ["Muriatic Acid"] == true and currentRecipeList ["Caustic Soda"] == true and currentRecipeList ["Hydrogen Chloride"] == true) == false) and ((currentRecipeList ["Muriatic Acid"] == false and currentRecipeList ["Caustic Soda"] == false and currentRecipeList ["Hydrogen Chloride"] == false) == false) then currentRecipe = clampCeiling (currentRecipe + 1, 3) - managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) - + if MethHelper.silent_toggle then + managers.chat:_receive_message (1, "[MethMagic]", "Ingredient added!", Color.green) + + else + managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) + end + elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and currentRecipe == 3 then currentRecipe = clampCeiling (currentRecipe + 1, 3) - managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) + + if MethHelper.silent_toggle then + managers.chat:_receive_message (1, "[MethMagic]", "Ingredient added!", Color.green) + else + managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) + end -- Else ID is for ingredient else -- Check to make sure that the ingredient is not already being echoed @@ -78,7 +152,11 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList [ingredient_dialog [id]] = true -- Print text - managers.chat:send_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) + if MethHelper.silent_toggle then + managers.chat:_receive_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) + else + managers.chat:send_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) + end end end end diff --git a/menu/lang.json b/menu/lang.json new file mode 100644 index 0000000..4405ff5 --- /dev/null +++ b/menu/lang.json @@ -0,0 +1,8 @@ +{ + "methHelper_title" : "Methhelper Menu", + "methHelper_menu_desc" : "A few options for the Methhelper Mod!", + "meth_helper_active_toggle" : "Methhelper Active?", + "meth_helper_active_desc" : "Enable or disable Methhelper", + "meth_helper_silent_toggle" : "Silentmode?", + "meth_helper_silent_desc" : "When in Silent mode only you get the chat messages, while when not in silent mode every one gets the message!" +} \ No newline at end of file diff --git a/menu/menu.json b/menu/menu.json new file mode 100644 index 0000000..af7d7da --- /dev/null +++ b/menu/menu.json @@ -0,0 +1,27 @@ +{ + "menu_id" : "methHelper_menu", + "parent_menu_id" : "lua_mod_options_menu", + "title" : "methHelper_title", + "description" : "methHelper_menu_desc", + "items" : [ + + { + "type" : "toggle", + "id" : "meth_helper_active", + "title" : "meth_helper_active_toggle", + "description" : "meth_helper_active_desc", + "callback" : "callback_meth_helper_active", + "value" : "meth_helper_active_value", + "default_value" : false + }, + { + "type" : "toggle", + "id" : "meth_helper_silent", + "title" : "meth_helper_silent_toggle", + "description" : "meth_helper_silent_desc", + "callback" : "callback_meth_helper_silent", + "value" : "meth_helper_silent_value", + "default_value" : false + } + ] +} From fba50e1113421e4cdaf9adbd9aa68a2a5f309a8d Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Fri, 15 Nov 2019 11:49:25 +0100 Subject: [PATCH 05/15] Add files via upload --- mod.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod.txt b/mod.txt index 097b18f..32cd9bb 100644 --- a/mod.txt +++ b/mod.txt @@ -14,6 +14,7 @@ ], "hooks" : [ - {"hook_id" : "lib/managers/dialogmanager", "script_path" : "lua/MethHelper.lua"} + {"hook_id" : "lib/managers/dialogmanager", "script_path" : "lua/MethHelper.lua"}, + {"hook_id" : "lib/managers/menumanager","script_path" : "lua/MethHelper.lua"} ] } From 3ce32a56fa4b3d19a8fd333e27a5aae0cd274559 Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Fri, 15 Nov 2019 14:56:54 +0100 Subject: [PATCH 06/15] Add files via upload --- lua/MethHelper.lua | 25 ++++++++++++++++--------- menu/menu.json | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 103745b..2f99164 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -1,7 +1,11 @@ _G.MethHelper = _G.MethHelper or {} MethHelper._path = ModPath -MethHelper._data_path = ModPath .. "saved_options_meth_helper.txt" -MethHelper._data = {} +MethHelper._data_path = SavePath .. "Meth_helper.txt" +MethHelper._data = { + active_toggle = true; + silent_toggle = false; +} + function MethHelper:Save() local file = io.open( self._data_path, "w+" ) @@ -31,14 +35,14 @@ Hooks:Add( "MenuManagerInitialize", "MenuManagerInitialize_MethHelper", function MenuCallbackHandler.callback_meth_helper_active = function(self, item) MethHelper._data.meth_helper_active_value = (item:value() == "on" and true or false) MethHelper:Save() - MethHelper.active_toggle = item:value() + MethHelper._data.active_toggle = item:value() log("Active Toggle is: " .. item:value()) end MenuCallbackHandler.callback_meth_helper_silent = function(self, item) MethHelper._data.meth_helper_silent_value = (item:value() == "on" and true or false) MethHelper:Save() - MethHelper.silent_toggle = item:value() + MethHelper._data.silent_toggle = item:value() log("Silent Toggle is: " .. item:value()) end @@ -109,9 +113,12 @@ end -- Trigger this every time there is dialogue local _queue_dialog_orig = DialogManager.queue_dialog function DialogManager:queue_dialog(id, ...) + log("Dialouge is played, some debug stuff ...") + log("Silent Toggle is ..:" .. MethHelper._data.silent_toggle) + log("Active Toggle is ..:" .. MethHelper._data.active_toggle) -- If dialogue code is found in dict - if ingredient_dialog[id] and MethHelper.active_toggle then + if ingredient_dialog[id] and MethHelper._data.active_toggle then -- If "batch finished" dialogue is played if id == CookoffFinishedID or id == RatsFinishedID or id == BorderCrystalFinsishedID or id == BorderCrystalFinsishedID2 then currentRecipe = 1 @@ -121,7 +128,7 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList ["Caustic Soda"] = false currentRecipeList ["Hydrogen Chloride"] = false --check menu options - if MethHelper.silent_toggle then + if MethHelper._data.silent_toggle then managers.chat:_receive_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) else managers.chat:send_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) @@ -129,7 +136,7 @@ function DialogManager:queue_dialog(id, ...) -- If "ingredient added" dialogue is played elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and ((currentRecipeList ["Muriatic Acid"] == true and currentRecipeList ["Caustic Soda"] == true and currentRecipeList ["Hydrogen Chloride"] == true) == false) and ((currentRecipeList ["Muriatic Acid"] == false and currentRecipeList ["Caustic Soda"] == false and currentRecipeList ["Hydrogen Chloride"] == false) == false) then currentRecipe = clampCeiling (currentRecipe + 1, 3) - if MethHelper.silent_toggle then + if MethHelper._data.silent_toggle then managers.chat:_receive_message (1, "[MethMagic]", "Ingredient added!", Color.green) else @@ -139,7 +146,7 @@ function DialogManager:queue_dialog(id, ...) elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and currentRecipe == 3 then currentRecipe = clampCeiling (currentRecipe + 1, 3) - if MethHelper.silent_toggle then + if MethHelper._data.silent_toggle then managers.chat:_receive_message (1, "[MethMagic]", "Ingredient added!", Color.green) else managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) @@ -152,7 +159,7 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList [ingredient_dialog [id]] = true -- Print text - if MethHelper.silent_toggle then + if MethHelper._data.silent_toggle then managers.chat:_receive_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) else managers.chat:send_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) diff --git a/menu/menu.json b/menu/menu.json index af7d7da..53eb1d8 100644 --- a/menu/menu.json +++ b/menu/menu.json @@ -1,6 +1,6 @@ { "menu_id" : "methHelper_menu", - "parent_menu_id" : "lua_mod_options_menu", + "parent_menu_id" : "blt_options", "title" : "methHelper_title", "description" : "methHelper_menu_desc", "items" : [ @@ -12,7 +12,7 @@ "description" : "meth_helper_active_desc", "callback" : "callback_meth_helper_active", "value" : "meth_helper_active_value", - "default_value" : false + "default_value" : true }, { "type" : "toggle", From 452fb8ca8076b7f85798181fdd47be74a7833683 Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Sat, 16 Nov 2019 17:54:38 +0100 Subject: [PATCH 07/15] Fixed a Few bugs and added a Menu --- lua/MethHelper.lua | 288 +++++++++++++++++++++++---------------------- 1 file changed, 149 insertions(+), 139 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 2f99164..1edde35 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -1,177 +1,187 @@ _G.MethHelper = _G.MethHelper or {} MethHelper._path = ModPath -MethHelper._data_path = SavePath .. "Meth_helper.txt" -MethHelper._data = { - active_toggle = true; - silent_toggle = false; -} - +MethHelper._data_path = SavePath .. 'Meth_helper.txt' +MethHelper._data = {} function MethHelper:Save() - local file = io.open( self._data_path, "w+" ) - if file then - file:write( json.encode( self._data ) ) - file:close() - end + local file = io.open(self._data_path, 'w+') + if file then + file:write(json.encode(self._data)) + file:close() + end end function MethHelper:Load() - local file = io.open( self._data_path, "r" ) - if file then - self._data = json.decode( file:read("*all") ) - file:close() - end + local file = io.open(self._data_path, 'r') + if file then + for k, v in pairs(json.decode(file:read('*all')) or {}) do + self._data[k] = v + end + file:close() + else + MethHelper._data.silent_toggle = false + MethHelper._data.active_toggle = true + end end -Hooks:Add("LocalizationManagerPostInit", "LocalizationManagerPostInit_MethHelper", function( loc ) - loc:load_localization_file( MethHelper._path .. "menu/" .. "lang.json") -end) - -Hooks:Add( "MenuManagerInitialize", "MenuManagerInitialize_MethHelper", function( menu_manager ) - - --[[ +Hooks:Add( + 'LocalizationManagerPostInit', + 'LocalizationManagerPostInit_MethHelper', + function(loc) + loc:load_localization_file(MethHelper._path .. 'menu/' .. 'lang.json') + end +) + +Hooks:Add( + 'MenuManagerInitialize', + 'MenuManagerInitialize_MethHelper', + function(menu_manager) + --[[ Setup our callbacks as defined in our item callback keys, and perform our logic on the data retrieved. ]] - MenuCallbackHandler.callback_meth_helper_active = function(self, item) - MethHelper._data.meth_helper_active_value = (item:value() == "on" and true or false) - MethHelper:Save() - MethHelper._data.active_toggle = item:value() - log("Active Toggle is: " .. item:value()) - end - - MenuCallbackHandler.callback_meth_helper_silent = function(self, item) - MethHelper._data.meth_helper_silent_value = (item:value() == "on" and true or false) - MethHelper:Save() - MethHelper._data.silent_toggle = item:value() - log("Silent Toggle is: " .. item:value()) - end - - - --[[ + MenuCallbackHandler.callback_meth_helper_active = function(self, item) + MethHelper._data.meth_helper_active_value = (item:value() == 'on' and true or false) + MethHelper._data.active_toggle = item:value() + MethHelper:Save() + end + + MenuCallbackHandler.callback_meth_helper_silent = function(self, item) + MethHelper._data.meth_helper_silent_value = (item:value() == 'on' and true or false) + MethHelper._data.silent_toggle = item:value() + MethHelper:Save() + end + + --[[ Load our previously saved data from our save file. ]] - MethHelper:Load() + MethHelper:Load() - --[[ + --[[ Load our menu json file and pass it to our MenuHelper so that it can build our in-game menu for us. We pass our parent mod table as the second argument so that any keybind functions can be found and called as necessary. We also pass our data table as the third argument so that our saved values can be loaded from it. ]] - MenuHelper:LoadFromJsonFile( MethHelper._path .. "menu/menu.json", MethHelper, MethHelper._data ) - -end ) + MenuHelper:LoadFromJsonFile(MethHelper._path .. 'menu/menu.json', MethHelper, MethHelper._data) + end +) -- Dialogue event codes -local RatsFinishedID = "pln_rat_stage1_28" -local RatsAddedID = "pln_rat_stage1_12" -local CookoffFinishedID = "pln_rt1_28" -local CookoffAddedID = "pln_rt1_12" -local BorderCrystalFinsishedID = "Play_loc_mex_cook_17" -local BorderCrystalFinsishedID2 = "Play_loc_mex_cook_13" -local BorderCrystalAddedID = "Play_loc_mex_cook_22" +local RatsFinishedID = 'pln_rat_stage1_28' +local RatsAddedID = 'pln_rat_stage1_12' +local CookoffFinishedID = 'pln_rt1_28' +local CookoffAddedID = 'pln_rt1_12' +local BorderCrystalFinsishedID = 'Play_loc_mex_cook_17' +local BorderCrystalFinsishedID2 = 'Play_loc_mex_cook_13' +local BorderCrystalAddedID = 'Play_loc_mex_cook_22' -- Dictionary mapping dialogue codes to plain text ingredients local ingredient_dialog = {} -ingredient_dialog["pln_rt1_20"] = "Muriatic Acid" -ingredient_dialog["pln_rt1_22"] = "Caustic Soda" -ingredient_dialog["pln_rt1_24"] = "Hydrogen Chloride" -ingredient_dialog["pln_rat_stage1_20"] = "Muriatic Acid" -ingredient_dialog["pln_rat_stage1_22"] = "Caustic Soda" -ingredient_dialog["pln_rat_stage1_24"] = "Hydrogen Chloride" -ingredient_dialog["Play_loc_mex_cook_03"] = "Muriatic Acid" -ingredient_dialog["Play_loc_mex_cook_04"] = "Caustic Soda" -ingredient_dialog["Play_loc_mex_cook_05"] = "Hydrogen Chloride" +ingredient_dialog['pln_rt1_20'] = 'Muriatic Acid' +ingredient_dialog['pln_rt1_22'] = 'Caustic Soda' +ingredient_dialog['pln_rt1_24'] = 'Hydrogen Chloride' +ingredient_dialog['pln_rat_stage1_20'] = 'Muriatic Acid' +ingredient_dialog['pln_rat_stage1_22'] = 'Caustic Soda' +ingredient_dialog['pln_rat_stage1_24'] = 'Hydrogen Chloride' +ingredient_dialog['Play_loc_mex_cook_03'] = 'Muriatic Acid' +ingredient_dialog['Play_loc_mex_cook_04'] = 'Caustic Soda' +ingredient_dialog['Play_loc_mex_cook_05'] = 'Hydrogen Chloride' -- Round about hacky way to trigger by both ingredients and recipe state dialogue -ingredient_dialog [RatsFinishedID] = true -ingredient_dialog [RatsAddedID] = true -ingredient_dialog [CookoffFinishedID] = true -ingredient_dialog [CookoffAddedID] = true -ingredient_dialog [BorderCrystalFinsishedID] = true -ingredient_dialog [BorderCrystalFinsishedID2] = true -ingredient_dialog [BorderCrystalAddedID] = true - --- Track number of ingredients in current meth recipe -local currentRecipe = 1 +ingredient_dialog[RatsFinishedID] = true +ingredient_dialog[RatsAddedID] = true +ingredient_dialog[CookoffFinishedID] = true +ingredient_dialog[CookoffAddedID] = true +ingredient_dialog[BorderCrystalFinsishedID] = true +ingredient_dialog[BorderCrystalFinsishedID2] = true +ingredient_dialog[BorderCrystalAddedID] = true + -- Track total number of bags made local totalBags = 0 -- Track current recipe state local currentRecipeList = {} -currentRecipeList ["Muriatic Acid"] = false -currentRecipeList ["Caustic Soda"] = false -currentRecipeList ["Hydrogen Chloride"] = false - --- Math.Clamp -function clampCeiling (val, vMax) - if val > vMax then - val = vMax - end - - return val +currentRecipeList['Muriatic Acid'] = false +currentRecipeList['Caustic Soda'] = false +currentRecipeList['Hydrogen Chloride'] = false + +IngredientCount = 0 +OldIngredientCount = 0 + +function countAddedIngredients(Table) + local count = 0 + for i, v in pairs(Table) do + if v == true then + count = count + 1 + end + end + return count end -- Trigger this every time there is dialogue local _queue_dialog_orig = DialogManager.queue_dialog function DialogManager:queue_dialog(id, ...) - log("Dialouge is played, some debug stuff ...") - log("Silent Toggle is ..:" .. MethHelper._data.silent_toggle) - log("Active Toggle is ..:" .. MethHelper._data.active_toggle) - + -- If dialogue code is found in dict - if ingredient_dialog[id] and MethHelper._data.active_toggle then - -- If "batch finished" dialogue is played - if id == CookoffFinishedID or id == RatsFinishedID or id == BorderCrystalFinsishedID or id == BorderCrystalFinsishedID2 then - currentRecipe = 1 - totalBags = totalBags + 1 - -- Reset recipe state - currentRecipeList ["Muriatic Acid"] = false - currentRecipeList ["Caustic Soda"] = false - currentRecipeList ["Hydrogen Chloride"] = false - --check menu options - if MethHelper._data.silent_toggle then - managers.chat:_receive_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) - else - managers.chat:send_message (1, "[MethMagic]", "Total bags: [" .. totalBags .. "]", Color.green) - end - -- If "ingredient added" dialogue is played - elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and ((currentRecipeList ["Muriatic Acid"] == true and currentRecipeList ["Caustic Soda"] == true and currentRecipeList ["Hydrogen Chloride"] == true) == false) and ((currentRecipeList ["Muriatic Acid"] == false and currentRecipeList ["Caustic Soda"] == false and currentRecipeList ["Hydrogen Chloride"] == false) == false) then - currentRecipe = clampCeiling (currentRecipe + 1, 3) - if MethHelper._data.silent_toggle then - managers.chat:_receive_message (1, "[MethMagic]", "Ingredient added!", Color.green) - - else - managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) - end - - elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and currentRecipe == 3 then - currentRecipe = clampCeiling (currentRecipe + 1, 3) - - if MethHelper._data.silent_toggle then - managers.chat:_receive_message (1, "[MethMagic]", "Ingredient added!", Color.green) - else - managers.chat:send_message (1, "[MethMagic]", "Ingredient added!", Color.green) - end - -- Else ID is for ingredient - else - -- Check to make sure that the ingredient is not already being echoed - if currentRecipeList [ingredient_dialog [id]] == false then - -- Flip the flag - currentRecipeList [ingredient_dialog [id]] = true - - -- Print text - if MethHelper._data.silent_toggle then - managers.chat:_receive_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) - else - managers.chat:send_message (1, "[MethMagic]", "[" .. currentRecipe .. "/3] [" .. ingredient_dialog[id] .. "]", Color.green) - end - end - end - end - -- for event mapping - --log("DialogManager: said " .. tostring(id)) - --managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) + if ingredient_dialog[id] and MethHelper._data.active_toggle == true or MethHelper._data.active_toggle == 'on' then + -- If "batch finished" dialogue is played + if id == CookoffFinishedID or id == RatsFinishedID or id == BorderCrystalFinsishedID or id == BorderCrystalFinsishedID2 then + -- If "ingredient added" dialogue is played + OldIngredientCount = 0 + totalBags = totalBags + 1 + -- Reset recipe state + currentRecipeList['Muriatic Acid'] = false + currentRecipeList['Caustic Soda'] = false + currentRecipeList['Hydrogen Chloride'] = false + -- check menu options + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) + end + elseif + (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and ((currentRecipeList['Muriatic Acid'] == true and currentRecipeList['Caustic Soda'] == true and currentRecipeList['Hydrogen Chloride'] == true) == false) and + ((currentRecipeList['Muriatic Acid'] == false and currentRecipeList['Caustic Soda'] == false and currentRecipeList['Hydrogen Chloride'] == false) == false) + then + IngredientCount = countAddedIngredients(currentRecipeList) + if IngredientCount > OldIngredientCount then + OldIngredientCount = IngredientCount + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) + end + end + elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) == 3 then + -- Else ID is for ingredient + IngredientCount = countAddedIngredients(currentRecipeList) + if IngredientCount > OldIngredientCount then + OldIngredientCount = IngredientCount + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) + end + end + else + -- Check to make sure that the ingredient is not already being echoed + if currentRecipeList[ingredient_dialog[id]] == false then + -- Flip the flag + currentRecipeList[ingredient_dialog[id]] = true + + -- Print text + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', '[' .. countAddedIngredients(currentRecipeList) .. '/3] [' .. ingredient_dialog[id] .. ']', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', '[' .. countAddedIngredients(currentRecipeList) .. '/3] [' .. ingredient_dialog[id] .. ']', Color.green) + end + end + end + end + -- for event mapping + -- log("DialogManager: said " .. tostring(id)) + -- managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) + return _queue_dialog_orig(self, id, ...) end -- feed_system_message () shows it to you and nobody else - -- send_message () shows it to everyone - -- _receive_message () shows it to everyone +-- send_message () shows it to everyone +-- _receive_message () shows it to everyone From b714ae163ab1352e38432a47ca74e03d5ad3ab37 Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:46:23 +0100 Subject: [PATCH 08/15] simplyfied code simplyfied code and increased maintainability --- lua/MethHelper.lua | 49 +++++++++++++++++++++++----------------------- mod.txt | 6 +++--- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 1edde35..5d0cd4f 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -106,6 +106,21 @@ currentRecipeList['Hydrogen Chloride'] = false IngredientCount = 0 OldIngredientCount = 0 +function sendMethMessage() + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) + end +end + +function getTotalIngredients(Table) + local ingredients = 0 + for k, v in pairs(Table) + ingredients = ingredients + 1 + end +end + function countAddedIngredients(Table) local count = 0 for i, v in pairs(Table) do @@ -132,34 +147,22 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false -- check menu options - if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then - managers.chat:_receive_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) - else - managers.chat:send_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) - end - elseif - (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and ((currentRecipeList['Muriatic Acid'] == true and currentRecipeList['Caustic Soda'] == true and currentRecipeList['Hydrogen Chloride'] == true) == false) and - ((currentRecipeList['Muriatic Acid'] == false and currentRecipeList['Caustic Soda'] == false and currentRecipeList['Hydrogen Chloride'] == false) == false) - then + sendMethMessage() + elseif + -- Dialouge is a Meth-related dialouge and it's neither the first ingredient nor a higher than 3 one + (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) > 0 and countAddedIngredients(currentRecipeList) < getTotalIngredients() + then IngredientCount = countAddedIngredients(currentRecipeList) if IngredientCount > OldIngredientCount then OldIngredientCount = IngredientCount - if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then - managers.chat:_receive_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) - else - managers.chat:send_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) - end + sendMethMessage() end - elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) == 3 then + elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) == getTotalIngredients() then -- Else ID is for ingredient IngredientCount = countAddedIngredients(currentRecipeList) if IngredientCount > OldIngredientCount then OldIngredientCount = IngredientCount - if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then - managers.chat:_receive_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) - else - managers.chat:send_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) - end + sendMethMessage() end else -- Check to make sure that the ingredient is not already being echoed @@ -168,11 +171,7 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList[ingredient_dialog[id]] = true -- Print text - if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then - managers.chat:_receive_message(1, '[SilentMethMagic]', '[' .. countAddedIngredients(currentRecipeList) .. '/3] [' .. ingredient_dialog[id] .. ']', Color.green) - else - managers.chat:send_message(1, '[SilentMethMagic]', '[' .. countAddedIngredients(currentRecipeList) .. '/3] [' .. ingredient_dialog[id] .. ']', Color.green) - end + sendMethMessage() end end end diff --git a/mod.txt b/mod.txt index 32cd9bb..81c82dc 100644 --- a/mod.txt +++ b/mod.txt @@ -1,9 +1,9 @@ { "name" : "MethHelper", "description": "Prints out information regarding recipe requirements during Hotline Miami day 1, Bomb Dockyard, Rats day 1 and Cook Off.", - "author" : "Keys", - "contact" : "http://steamcommunity.com/id/ilikekeys/", - "version" : "1.00", + "author" : "Keys, Gurkoel", + "contact" : "http://steamcommunity.com/id/ilikekeys/, http://steamcommunity.com/id/Gurkoel/", + "version" : "1.2", "blt_version" : "2", "updates" : [ From 91bc1238bbb89711093aa0c266f4b459e1cc9f72 Mon Sep 17 00:00:00 2001 From: Gurkoel Date: Fri, 17 Jan 2020 13:43:46 +0100 Subject: [PATCH 09/15] Fixen and simplified --- lua/MethHelper.lua | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 5d0cd4f..16ff93d 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -106,19 +106,34 @@ currentRecipeList['Hydrogen Chloride'] = false IngredientCount = 0 OldIngredientCount = 0 -function sendMethMessage() - if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then - managers.chat:_receive_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) - else - managers.chat:send_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) +function sendMethMessage(number, id) + if number == 1 then + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', 'Ingredient added!', Color.green) + end + elseif number == 2 then + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', '[' .. countAddedIngredients(currentRecipeList) .. '/3] [' .. ingredient_dialog[id] .. ']', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', '[' .. countAddedIngredients(currentRecipeList) .. '/3] [' .. ingredient_dialog[id] .. ']', Color.green) + end + elseif number == 3 then + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) + else + managers.chat:send_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) + end end end function getTotalIngredients(Table) local ingredients = 0 - for k, v in pairs(Table) + for k, v in pairs(Table) do ingredients = ingredients + 1 end + return ingredients end function countAddedIngredients(Table) @@ -147,22 +162,14 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false -- check menu options - sendMethMessage() + sendMethMessage(3, id) -- Total bags ... elseif - -- Dialouge is a Meth-related dialouge and it's neither the first ingredient nor a higher than 3 one - (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) > 0 and countAddedIngredients(currentRecipeList) < getTotalIngredients() - then - IngredientCount = countAddedIngredients(currentRecipeList) - if IngredientCount > OldIngredientCount then - OldIngredientCount = IngredientCount - sendMethMessage() - end - elseif (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) == getTotalIngredients() then - -- Else ID is for ingredient + -- Dialouge is a Meth-related dialouge and it's neither 0 nor a higher than 3 + (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) > 0 and countAddedIngredients(currentRecipeList) <= getTotalIngredients(currentRecipeList) then IngredientCount = countAddedIngredients(currentRecipeList) if IngredientCount > OldIngredientCount then OldIngredientCount = IngredientCount - sendMethMessage() + sendMethMessage(1, id) -- Ingredient Added end else -- Check to make sure that the ingredient is not already being echoed @@ -171,7 +178,7 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList[ingredient_dialog[id]] = true -- Print text - sendMethMessage() + sendMethMessage(2, id) --Ingredient is .... end end end From e81c42b967c546515fbe1714916200a214de9f27 Mon Sep 17 00:00:00 2001 From: Gurkoel Date: Fri, 17 Jan 2020 17:50:03 +0100 Subject: [PATCH 10/15] further simplyfied code, investigating into 8bag bug --- lua/MethHelper.lua | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 16ff93d..c85d653 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -87,6 +87,9 @@ ingredient_dialog['Play_loc_mex_cook_03'] = 'Muriatic Acid' ingredient_dialog['Play_loc_mex_cook_04'] = 'Caustic Soda' ingredient_dialog['Play_loc_mex_cook_05'] = 'Hydrogen Chloride' -- Round about hacky way to trigger by both ingredients and recipe state dialogue + +local batchFinishedDialog = {"pln_rat_stage1_28","pln_rt1_28","Play_loc_mex_cook_17","Play_loc_mex_cook_13","Play_loc_mex_cook_22"} + ingredient_dialog[RatsFinishedID] = true ingredient_dialog[RatsAddedID] = true ingredient_dialog[CookoffFinishedID] = true @@ -102,6 +105,7 @@ local currentRecipeList = {} currentRecipeList['Muriatic Acid'] = false currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false +local ingredientAddedCount = 0 IngredientCount = 0 OldIngredientCount = 0 @@ -128,6 +132,20 @@ function sendMethMessage(number, id) end end +function isMethFinished(id) + for i, v in pairs(batchFinishedDialog) do + if v == id then + return true + end + end +end + +function isAddedMaxCountReached() + if self.ingredientAddedCount == 3 then + return true + end +end + function getTotalIngredients(Table) local ingredients = 0 for k, v in pairs(Table) do @@ -153,22 +171,24 @@ function DialogManager:queue_dialog(id, ...) -- If dialogue code is found in dict if ingredient_dialog[id] and MethHelper._data.active_toggle == true or MethHelper._data.active_toggle == 'on' then -- If "batch finished" dialogue is played - if id == CookoffFinishedID or id == RatsFinishedID or id == BorderCrystalFinsishedID or id == BorderCrystalFinsishedID2 then - -- If "ingredient added" dialogue is played + if isMethFinished(id) == true then + -- If "BAg finished" dialogue is played OldIngredientCount = 0 totalBags = totalBags + 1 -- Reset recipe state currentRecipeList['Muriatic Acid'] = false currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false + self.ingredientAddedCount = 0 -- check menu options sendMethMessage(3, id) -- Total bags ... - elseif + elseif -- Dialouge is a Meth-related dialouge and it's neither 0 nor a higher than 3 (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) > 0 and countAddedIngredients(currentRecipeList) <= getTotalIngredients(currentRecipeList) then IngredientCount = countAddedIngredients(currentRecipeList) if IngredientCount > OldIngredientCount then OldIngredientCount = IngredientCount + self.ingredientAddedCount = self.ingredientAddedCount + 1 sendMethMessage(1, id) -- Ingredient Added end else @@ -181,10 +201,13 @@ function DialogManager:queue_dialog(id, ...) sendMethMessage(2, id) --Ingredient is .... end end +--[[ elseif isAddedMaxCountReached() == true then + self.ingredientAddedCount = 0 + end ]] end -- for event mapping - -- log("DialogManager: said " .. tostring(id)) - -- managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) + log("DialogManager: said " .. tostring(id)) + managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) return _queue_dialog_orig(self, id, ...) end From 867227d757f30d4eda409468a7224efe085e7b5c Mon Sep 17 00:00:00 2001 From: Gurkoel Date: Sat, 18 Jan 2020 14:47:51 +0100 Subject: [PATCH 11/15] Found a solution for 8 bag error, its being tested if a dialog is missing. Total bagcount gets guessed by then Further testing necessary. --- lua/MethHelper.lua | 64 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index c85d653..6437aef 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -105,10 +105,12 @@ local currentRecipeList = {} currentRecipeList['Muriatic Acid'] = false currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false -local ingredientAddedCount = 0 -IngredientCount = 0 -OldIngredientCount = 0 + + +local lastAdded = false +local IngredientCount = 0 +local OldIngredientCount = 0 function sendMethMessage(number, id) if number == 1 then @@ -129,6 +131,12 @@ function sendMethMessage(number, id) else managers.chat:send_message(1, '[SilentMethMagic]', 'Total bags: [' .. totalBags .. ']', Color.green) end + elseif number == 4 then + if MethHelper._data.silent_toggle == true or MethHelper._data.silent_toggle == 'on' then + managers.chat:_receive_message(1, '[SilentMethMagic]', 'No finished dialouge caught, Bag-count is being guessed by now', Color.red) + else + managers.chat:send_message(1, '[SilentMethMagic]', 'No finished dialouge caught, Bag-count is being guessed by now', Color.red) + end end end @@ -139,12 +147,15 @@ function isMethFinished(id) end end end - -function isAddedMaxCountReached() - if self.ingredientAddedCount == 3 then - return true + +function isIngredient(id) + for i,v in pairs(ingredient_dialog) do + if v == 'Muriatic Acid' or v == 'Caustic Soda' or v == 'Hydrogen Chloride' then + return true + end end end + function getTotalIngredients(Table) local ingredients = 0 @@ -170,6 +181,8 @@ function DialogManager:queue_dialog(id, ...) -- If dialogue code is found in dict if ingredient_dialog[id] and MethHelper._data.active_toggle == true or MethHelper._data.active_toggle == 'on' then + --check if Bag finished dialog wasn't played this happens i.E in cook off after bag 8 + -- If "batch finished" dialogue is played if isMethFinished(id) == true then -- If "BAg finished" dialogue is played @@ -179,32 +192,55 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList['Muriatic Acid'] = false currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false - self.ingredientAddedCount = 0 + lastAdded = false -- check menu options sendMethMessage(3, id) -- Total bags ... - elseif + elseif -- Dialouge is a Meth-related dialouge and it's neither 0 nor a higher than 3 (id == CookoffAddedID or id == RatsAddedID or id == BorderCrystalAddedID) and countAddedIngredients(currentRecipeList) > 0 and countAddedIngredients(currentRecipeList) <= getTotalIngredients(currentRecipeList) then IngredientCount = countAddedIngredients(currentRecipeList) if IngredientCount > OldIngredientCount then OldIngredientCount = IngredientCount - self.ingredientAddedCount = self.ingredientAddedCount + 1 sendMethMessage(1, id) -- Ingredient Added + if IngredientCount == getTotalIngredients(currentRecipeList) then + lastAdded = true + else + lastAdded = false + end end + elseif isIngredient(id) and lastAdded == true and countAddedIngredients(currentRecipeList) != getTotalIngredients(currentRecipeList) then + sendMethMessage(4, id) --something went wrong + OldIngredientCount = 0 + totalBags = totalBags + 1 + -- Reset recipe state + currentRecipeList['Muriatic Acid'] = false + currentRecipeList['Caustic Soda'] = false + currentRecipeList['Hydrogen Chloride'] = false + sendMethMessage(3, id) --guessed total bags else -- Check to make sure that the ingredient is not already being echoed if currentRecipeList[ingredient_dialog[id]] == false then -- Flip the flag currentRecipeList[ingredient_dialog[id]] = true - -- Print text sendMethMessage(2, id) --Ingredient is .... end end ---[[ elseif isAddedMaxCountReached() == true then - self.ingredientAddedCount = 0 - end ]] end + + -- ideas to fix: + -- create a variable which saves the last ingredient + -- check if dialog ID is a new ingredient --> if so reset counter + -- give warning after bag 8 and remind that calculations might be wrong + -- You might have to pour in twice the same in a row + -- need a solution for that + -- if it is an ingredient and last ingrediend was already added you can assure it is faulty and warn the player + + -- Possibility to trigger when 3 ingredients are added and next dialog is not an ID-Dialog? + -- Is there always a dialog inbetween? + -- Might happen between finish and last ingredient + --> Faulty value + -- -- for event mapping log("DialogManager: said " .. tostring(id)) managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) From 8310f01ee919798820b804df2adac00e9780a2dc Mon Sep 17 00:00:00 2001 From: Gurkoel Date: Mon, 20 Jan 2020 16:11:30 +0100 Subject: [PATCH 12/15] Testing in progression ... --- lua/MethHelper.lua | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 6437aef..e7107ac 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -181,8 +181,6 @@ function DialogManager:queue_dialog(id, ...) -- If dialogue code is found in dict if ingredient_dialog[id] and MethHelper._data.active_toggle == true or MethHelper._data.active_toggle == 'on' then - --check if Bag finished dialog wasn't played this happens i.E in cook off after bag 8 - -- If "batch finished" dialogue is played if isMethFinished(id) == true then -- If "BAg finished" dialogue is played @@ -208,11 +206,12 @@ function DialogManager:queue_dialog(id, ...) lastAdded = false end end - elseif isIngredient(id) and lastAdded == true and countAddedIngredients(currentRecipeList) != getTotalIngredients(currentRecipeList) then - sendMethMessage(4, id) --something went wrong + --check if Bag finished dialog wasn't played this happens i.E in cook off after bag 8 + elseif isIngredient(id) and lastAdded == true and countAddedIngredients(currentRecipeList) ~= getTotalIngredients(currentRecipeList) then + sendMethMessage(4, id) --something went wrong warn player about bag count OldIngredientCount = 0 totalBags = totalBags + 1 - -- Reset recipe state + -- Reset recipe state because finished dialouge will not be played anymore currentRecipeList['Muriatic Acid'] = false currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false @@ -227,20 +226,6 @@ function DialogManager:queue_dialog(id, ...) end end end - - -- ideas to fix: - -- create a variable which saves the last ingredient - -- check if dialog ID is a new ingredient --> if so reset counter - -- give warning after bag 8 and remind that calculations might be wrong - -- You might have to pour in twice the same in a row - -- need a solution for that - -- if it is an ingredient and last ingrediend was already added you can assure it is faulty and warn the player - - -- Possibility to trigger when 3 ingredients are added and next dialog is not an ID-Dialog? - -- Is there always a dialog inbetween? - -- Might happen between finish and last ingredient - --> Faulty value - -- -- for event mapping log("DialogManager: said " .. tostring(id)) managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) From 58e30830f6e56543dafd71d47098ce7df0872837 Mon Sep 17 00:00:00 2001 From: Gurkoel Date: Mon, 20 Jan 2020 16:14:39 +0100 Subject: [PATCH 13/15] test --- lua/MethHelper.lua | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 6437aef..2cde25f 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -181,8 +181,6 @@ function DialogManager:queue_dialog(id, ...) -- If dialogue code is found in dict if ingredient_dialog[id] and MethHelper._data.active_toggle == true or MethHelper._data.active_toggle == 'on' then - --check if Bag finished dialog wasn't played this happens i.E in cook off after bag 8 - -- If "batch finished" dialogue is played if isMethFinished(id) == true then -- If "BAg finished" dialogue is played @@ -208,14 +206,16 @@ function DialogManager:queue_dialog(id, ...) lastAdded = false end end - elseif isIngredient(id) and lastAdded == true and countAddedIngredients(currentRecipeList) != getTotalIngredients(currentRecipeList) then - sendMethMessage(4, id) --something went wrong + --check if Bag finished dialog wasn't played this happens i.E in cook off after bag 8! + elseif isIngredient(id) and lastAdded == true and countAddedIngredients(currentRecipeList) == getTotalIngredients(currentRecipeList) then + sendMethMessage(4, id) --something went wrong warn player about bag count OldIngredientCount = 0 totalBags = totalBags + 1 - -- Reset recipe state + -- Reset recipe state because finished dialouge will not be played anymore currentRecipeList['Muriatic Acid'] = false currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false + lastAdded = false sendMethMessage(3, id) --guessed total bags else -- Check to make sure that the ingredient is not already being echoed @@ -227,20 +227,6 @@ function DialogManager:queue_dialog(id, ...) end end end - - -- ideas to fix: - -- create a variable which saves the last ingredient - -- check if dialog ID is a new ingredient --> if so reset counter - -- give warning after bag 8 and remind that calculations might be wrong - -- You might have to pour in twice the same in a row - -- need a solution for that - -- if it is an ingredient and last ingrediend was already added you can assure it is faulty and warn the player - - -- Possibility to trigger when 3 ingredients are added and next dialog is not an ID-Dialog? - -- Is there always a dialog inbetween? - -- Might happen between finish and last ingredient - --> Faulty value - -- -- for event mapping log("DialogManager: said " .. tostring(id)) managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) From 37d3d2eb27fc9dbe2199ce1bc773b5b8770ef65e Mon Sep 17 00:00:00 2001 From: Gurkoel Date: Mon, 20 Jan 2020 17:03:27 +0100 Subject: [PATCH 14/15] 8-bag bug fixed --- lua/MethHelper.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 2cde25f..ac12046 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -216,7 +216,8 @@ function DialogManager:queue_dialog(id, ...) currentRecipeList['Caustic Soda'] = false currentRecipeList['Hydrogen Chloride'] = false lastAdded = false - sendMethMessage(3, id) --guessed total bags + sendMethMessage(3, id) -- guessed total bags + sendMethMessage(2, id) -- needed Ingredient else -- Check to make sure that the ingredient is not already being echoed if currentRecipeList[ingredient_dialog[id]] == false then @@ -228,9 +229,9 @@ function DialogManager:queue_dialog(id, ...) end end -- for event mapping - log("DialogManager: said " .. tostring(id)) + --[[ log("DialogManager: said " .. tostring(id)) managers.chat:send_message(ChatManager.GAME, managers.network.account:username() or "Offline", id) - + ]] return _queue_dialog_orig(self, id, ...) end -- feed_system_message () shows it to you and nobody else From 4a9ada694c80c6bb9bacdbb0bd57539deb78177f Mon Sep 17 00:00:00 2001 From: Gurkoel <42492351+Gurkoel@users.noreply.github.com> Date: Thu, 3 Sep 2020 13:48:01 +0200 Subject: [PATCH 15/15] Update MethHelper.lua Fixed wrong methcounter on border crystals --- lua/MethHelper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/MethHelper.lua b/lua/MethHelper.lua index 3e9a7a0..14b429c 100644 --- a/lua/MethHelper.lua +++ b/lua/MethHelper.lua @@ -88,7 +88,7 @@ ingredient_dialog['Play_loc_mex_cook_04'] = 'Caustic Soda' ingredient_dialog['Play_loc_mex_cook_05'] = 'Hydrogen Chloride' -- Round about hacky way to trigger by both ingredients and recipe state dialogue -local batchFinishedDialog = {"pln_rat_stage1_28","pln_rt1_28","Play_loc_mex_cook_17","Play_loc_mex_cook_13","Play_loc_mex_cook_22"} +local batchFinishedDialog = {"pln_rat_stage1_28","pln_rt1_28","Play_loc_mex_cook_17","Play_loc_mex_cook_13"} ingredient_dialog[RatsFinishedID] = true ingredient_dialog[RatsAddedID] = true