Skip to content

Commit

Permalink
Efficiency and typos
Browse files Browse the repository at this point in the history
- Made `LicenseScreen` remove its handlers when done - they're one-time changes
- Fixed `RandomMissionCharacters` changing ambient characters instead of bonus characters
- Fixed `RandomPedestrians` not changing ambient characters
- Fixed typo in `RandomPedestrians`
  • Loading branch information
Hampo committed Jun 28, 2024
1 parent e1666d8 commit d82a697
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
2 changes: 2 additions & 0 deletions Randomiser/Resources/Modules/LicenseScreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local licensesN = #licenses
assert(licensesN > 0, "Failed to find any license images")

LicenseScreen:AddP3DHandler("art/frontend/dynaload/images/license/*license*.p3d", function(Path, P3DFile)
LicenseScreen.Handlers.P3D = {}

local Sprite = P3DFile:GetChunk(P3D.Identifiers.Sprite)
if not Sprite then
return false
Expand Down
2 changes: 1 addition & 1 deletion Randomiser/Resources/Modules/RandomMissionCharacters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RandomMissionCharacters:AddLevelHandler(function(LevelNumber, LevelLoad, LevelIn
for i=1,#LevelInit.Functions do
local func = LevelInit.Functions[i]
local name = func.Name:lower()
if name == "addambientcharacter" then
if name == "addnpccharacterbonusmission" then
local char = func.Arguments[1]
if #char > 6 then
char = string_sub(char, 1, 6)
Expand Down
33 changes: 0 additions & 33 deletions Randomiser/Resources/Modules/RandomPedenstrians.lua

This file was deleted.

46 changes: 46 additions & 0 deletions Randomiser/Resources/Modules/RandomPedestrians.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local math_random = math.random
local string_sub = string.sub
local table_remove = table.remove
local table_unpack = table.unpack

local RandomPedestrians = Module("Random Pedestrians")

local function ReplaceCharacter(Path, P3DFile)
return P3DUtils.ReplaceCharacter(P3DFile)
end

RandomPedestrians:AddLevelHandler(function(LevelNumber, LevelLoad, LevelInit)
RandomPedestrians.Handlers.P3D = {}

local pedPool = {table_unpack(CharNames)}

local functions = LevelInit.Functions
for i=#functions,1,-1 do
local func = functions[i]
local name = func.Name:lower()
if name == "addped" then
table_remove(functions, i)
elseif name == "createpedgroup" then
for j=1,7 do
local randomPedIndex = math_random(#pedPool)
local randomPed = pedPool[randomPedIndex]:sub(1,-3)
table_remove(pedPool, randomPedIndex)
if #pedPool == 0 then
pedPool = {table_unpack(CharNames)}
end

LevelInit:InsertFunction(i + 1, "AddPed", {randomPed, 1})
end
elseif name == "addambientcharacter" then
local char = func.Arguments[1]
if #char > 6 then
char = string_sub(char, 1, 6)
end
RandomPedestrians:AddP3DHandler("art/chars/" .. char .. "_m.p3d", ReplaceCharacter)
end
end

return true
end)

return RandomPedestrians

0 comments on commit d82a697

Please sign in to comment.