Skip to content

Instantly share code, notes, and snippets.

@marth8880
Last active March 17, 2024 14:28
Show Gist options
  • Select an option

  • Save marth8880/bb8950b6d6be10e31525ba37d80002e2 to your computer and use it in GitHub Desktop.

Select an option

Save marth8880/bb8950b6d6be10e31525ba37d80002e2 to your computer and use it in GitHub Desktop.
The dialogue system used for Return to Jinglin' Town
-- dialogue line definitions
-- 'name' : the name of the SoundStreamProperty
-- 'duration' : the length of the line in seconds rounded up a bit
voiceLines = {
Cut_1 = {
[1] = { name = "XM2_cut_1_1", duration = 7.6 },
[2] = { name = "XM2_cut_1_2", duration = 6.1 },
[3] = { name = "XM2_cut_2_1", duration = 5.65 },
[4] = { name = "XM2_cut_2_2", duration = 19.9 },
[5] = { name = "XM2_cut_2_3", duration = 9.9 },
},
Cut_Ad = {
[1] = { name = "XM2_cut_2_4", duration = 0.9 },
},
Cut_3 = {
[1] = { name = "XM2_cut_3_1", duration = 28.65 },
},
Obj_2A = {
[1] = { name = "XM2_obj_2_1", duration = 1.2 },
},
Obj_2B = {
[1] = { name = "XM2_obj_2_2", duration = 1.55 },
},
Obj_2C = {
[1] = { name = "XM2_obj_2_3", duration = 1.75 },
},
-- etc.
}
-- constants
DIALOGUE_LINE_DELAY = 0.500
-- implementation
-- 'lineBatch' : the table of voice lines to play,
-- 'exitFunction' : an optional anonymous function that will be played after all dialogue lines have played if specified
function PlayDialogueLines(lineBatch, exitFunction)
local duration = 0
for i, line in ipairs(lineBatch) do
print("PlayDialogueLines: Playing line "..line.name)
duration = duration + line.duration
ScriptCB_SndPlaySound(line.name) -- sound system automatically queues the requested sounds
end
SetTimerValue(PlayDialogueLines_DurationTimer, duration + DIALOGUE_LINE_DELAY)
StartTimer(PlayDialogueLines_DurationTimer)
-- ShowTimer(PlayDialogueLines_DurationTimer)
local durationTimerElapseHandler = OnTimerElapse(
function(timer)
ReleaseTimerElapse(durationTimerElapseHandler)
durationTimerElapseHandler = nil
-- StopTimer(PlayDialogueLines_DurationTimer)
if exitFunction then
print("PlayDialogueLines: Executing exit function")
exitFunction()
exitFunction = nil
end
end,
PlayDialogueLines_DurationTimer
)
end
-- Create reused timers
PlayDialogueLines_DurationTimer = CreateTimer("PlayDialogueLines_DurationTimer")
-- usage
PlayDialogueLines(voiceLines.Obj_2B)
-- with exit function
PlayDialogueLines(voiceLines.Obj_4A,
function()
SetProperty("drunksanta1", "IsVisible", 0)
SetProperty("collision_drunksanta1", "MaxHealth", 1e+37)
SetProperty("collision_drunksanta1", "CurHealth", 0)
KillObject("presentcollision")
present_spawn = GetPathPoint("present_path", 0)
give_present = CreateEntity("xms_item_life", present_spawn, "xms_item_life15")
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment