From f234ee1950986c636d2fc44574c39b1eea7865c1 Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jul 2024 21:31:37 +0100 Subject: [PATCH] Added `RandomNPCMissions` --- Randomiser/Meta.ini | 9 ++++ .../Modules/Chaos/RandomNPCMissions.lua | 49 +++++++++++++++++++ .../Modules/General/SettingsInfo.lua | 1 + 3 files changed, 59 insertions(+) create mode 100644 Randomiser/Resources/Modules/Chaos/RandomNPCMissions.lua diff --git a/Randomiser/Meta.ini b/Randomiser/Meta.ini index 8680a77..5fb8d6e 100644 --- a/Randomiser/Meta.ini +++ b/Randomiser/Meta.ini @@ -517,6 +517,15 @@ Tooltip=Randomises all the mission order per level. Page=Chaos Randomisations Group=Missions +[Setting] +Name=RandomNPCMissions +Title=Random NPC Missions +Type=TickBox +Default=0 +Tooltip=Randomises who gives the races and bonus mission in a level. +Page=Chaos Randomisations +Group=Missions + ; Car pools - I hate this diff --git a/Randomiser/Resources/Modules/Chaos/RandomNPCMissions.lua b/Randomiser/Resources/Modules/Chaos/RandomNPCMissions.lua new file mode 100644 index 0000000..b619720 --- /dev/null +++ b/Randomiser/Resources/Modules/Chaos/RandomNPCMissions.lua @@ -0,0 +1,49 @@ +local math_random = math.random +local table_remove = table.remove + +local RandomNPCMissions = Module("Random NPC Missions", "RandomNPCMissions") + +RandomNPCMissions:AddLevelHandler(function(LevelNumber, LevelLoad, LevelInit) + local functions = LevelInit.Functions + + local NPCMissions = {} + + for i=1,#functions do + local func = functions[i] + if func.Name:lower() == "addnpccharacterbonusmission" then + NPCMissions[#NPCMissions + 1] = { func.Arguments[4], func.Arguments[5], func.Arguments[7] } + end + end + + local npcMissionPosMap = {} + for i=1,#functions do + local func = functions[i] + local name = func.Name:lower() + if name == "addnpccharacterbonusmission" then + local index = math_random(#NPCMissions) + local NPCMission = NPCMissions[index] + table_remove(NPCMissions, index) + print("Replacing NPC mission \"" .. func.Arguments[4] .. "\" with: " .. NPCMission[1]) + npcMissionPosMap[func.Arguments[4]] = NPCMission[1] + func.Arguments[4] = NPCMission[1] + func.Arguments[5] = NPCMission[2] + func.Arguments[7] = NPCMission[3] + elseif name == "setbonusmissiondialoguepos" then + if npcMissionPosMap[func.Arguments[1]] then + func.Arguments[1] = npcMissionPosMap[func.Arguments[1]] + end + elseif name == "setconversationcam" then + if npcMissionPosMap[func.Arguments[3]] then + func.Arguments[3] = npcMissionPosMap[func.Arguments[3]] + end + elseif name == "setcambestside" then + if npcMissionPosMap[func.Arguments[2]] then + func.Arguments[2] = npcMissionPosMap[func.Arguments[2]] + end + end + end + + return true +end) + +return RandomNPCMissions \ No newline at end of file diff --git a/Randomiser/Resources/Modules/General/SettingsInfo.lua b/Randomiser/Resources/Modules/General/SettingsInfo.lua index de34cbe..50581f4 100644 --- a/Randomiser/Resources/Modules/General/SettingsInfo.lua +++ b/Randomiser/Resources/Modules/General/SettingsInfo.lua @@ -30,6 +30,7 @@ local ChaosSettings = { [1 << 1] = Settings.RandomText, [1 << 2] = Settings.RandomTextCase, [1 << 3] = Settings.RandomMissionOrder, + [1 << 4] = Settings.RandomNPCMissions, } local GameplayN = 0