Forum Mod Bakery Docs

Dialog.lua (and maybe other lua scripts)

Please login to contribute to the conversation.
This resource is a Lua script that makes it easy to add dialog (convinit's and noboxconvs's) by dynamically searching the conversations folder and subfolders and appending it to dialog.spt, this means you no longer need to edit dialog.spt to add new dialog or even have it in CustomFiles at all. This also saves some file size since dialog.spt is 574 KB and this script is just 1.82 KB which makes it 0.003% smaller.

If you are making a total conversion / campaign mod, you can set RemoveVanillaDialog to true and it will not load vanilla dialog which saves some memory

Dialog.lua v1.1

(and maybe other lua scripts)
Thread Title
I may add other lua modules I have made to this thread later on
peng mate, cheers
Specifically about the dialog.lua script (in case you do post others later):
  • You need to have RequiredHack=FileSystemRCFs in your Meta.ini in order to ReadFile the base game's dialog file, as it's stored in an RCF.
  • In order to support all the languages, you will have to make sure to add a PathHandler for:
    • sound/scripts/dialog.spt
    • sound/scripts/dialogfr.spt
    • sound/scripts/dialogge.spt
    • sound/scripts/dialogsp.spt
  • It might be worth doing an IsHackLoaded check on OggVorbisSupport before checking if the extension is ogg.
  • It also might be worth adding the very rarely used FLACSupport.
  • In a situation where you need to remove some of the base-game entries, I'd suggest combining your script with my script from this thread with something like this (written in thread untested):
Example code
-- Load the requested SPT file
local Orig = ReadFile("/GameData/" .. GetPath())
-- Table with conversations we need to remove for whatever reason
local DefaultRemove = {
	["C_icecream_1_convinit_Mrg_L1"] = true,
	["C_icecream_2_convinit_Hom_L1"] = true,
}

-- Loop through each SoundData in the loaded SPT
for SoundData in Orig:gmatch("[^}]+") do
	-- Parse the name of the data
	local name = SoundData:match("named ([^\r\n]+)")
	-- If the name was found (so it's a valid soundData), and it's not a match in the remove table, output it
	if name and not DefaultRemove[name] then
		Output(SoundData)
		Output("}")
	end
end

-- This is now our additional sound data entries.
local extensions = {[".rsd"]=true}
if IsHackLoaded("OggVorbisSupport") then extensions[".ogg"] = true end
if IsHackLoaded("FLACSupport") then extensions[".flac"] = true end
local ModCF = GetModPath().."/CustomFiles/"
local function GetDialog(directory)
	DirectoryGetEntries(directory, function(FileOrDirectory, IsDirectory)
		if IsDirectory then
			GetDialog(directory.."/"..FileOrDirectory)
		elseif not IsDirectory then
			local ext = GetFileExtension(FileOrDirectory)
			if extensions[ext] then
				Output("\ncreate daSoundResourceData named "..RemoveFileExtension(FileOrDirectory).."\n{\n")
				local dir = directory:gsub(ModCF, "")
				if dir:sub(-1) ~= "/" then dir = dir .. "/" end
				Output("\tAddFilename ( \""..dir..FileOrDirectory.."\" 1.000000 )\n\tSetStreaming ( true )\n}")
			end
		end
		return true
	end)
end
GetDialog(ModCF .. "conversations")