Skip to content

Commit

Permalink
Added RandomNPCMissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hampo committed Jul 3, 2024
1 parent 8ce3ffe commit f234ee1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Randomiser/Meta.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
49 changes: 49 additions & 0 deletions Randomiser/Resources/Modules/Chaos/RandomNPCMissions.lua
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Randomiser/Resources/Modules/General/SettingsInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f234ee1

Please sign in to comment.