Lua unfortunaly doesn't support one-line if, for, function and while-loops. You always have to close them with the 'end' keyword.
Code: Select all
dialogSpeaker = 0
dialogTextTime = 0
dialogSpeakerTime = 0
dialogName = ""
dialogText = ""
-- Can the player press the key to skip the current line?
dialogSkippable = true
-- Does the dialogue halt the cutscene timing?
dialogPause = true
-- Does the player have to press a key to continue?
dialogEndWithInput = true
-- Can the entire cutscene be skipped?
cutsceneSkippable = true
-- Current cutscene time in frames
cutsceneFrame = 0
-- Constants
NPCID_DEMO = 101
NPCID_IRIS = 102
NPCID_KOOD = 103
function onLoad()
dialogSpeaker = 0
dialogTextTime = 0
dialogSpeakerTime = 0
dialogName = ""
dialogText = ""
dialogSkippable = true
dialogPause = true
dialogEndWithInput = true
cutsceneFrame = 0
setDialogRules(true, true, true)
end
function onLoop()
-- Trigger sequenced cutscene events
processCutscene()
-- Control specific NPC talking/idle animations
processNPCTalkAnim(NPCID_DEMO, 0, 3, 4, 7)
processNPCTalkAnim(NPCID_IRIS, 0, 0, 1, 4)
processNPCTalkAnim(NPCID_KOOD, 0, 15, 16, 19)
-- Control dialogue display
processDialog()
end
function processCutscene()
if(dialogPause == false or dialogTextTime <= 0)then
cutsceneFrame = cutsceneFrame + 1
end
-- Add subtitle commands here
timedDialog(30, NPCID_DEMO, "Demo", "Testing, testing, 1, 2, 3...", 120, 180)
timedDialog(60, NPCID_IRIS, "Iris", "Hey there, everyone!", 60, 120)
timedDialog(90, NPCID_KOOD, "Kood", "This is a test of a LunaLUA cutscene system.", 150, 180)
end
function setDialogRules(pause, skippable, needInput)
dialogPause = pause
dialogSkippable = skippable
dialogEndWithInput = needInput
end
function timedDialog(frame, speakerid, name, text, textTime, speakTime, sound)
if(cutsceneFrame == frame)then
-- Insert play sound command here
timedDialog(frame, speakerid, name, text, textTime, speakTime)
end
end
function timedDialog(frame, speakerid, name, text, textTime, speakTime)
if(cutsceneFrame == frame)then
triggerSpeaker(speakerid, speakTime)
triggerDialog(name, text, textTime)
end
end
function triggerSpeaker(npcid, time)
dialogSpeaker = npcid
dialogSpeakerTime = time
end
function triggerDialog(name,text,textTime)
dialogName = name
dialogText = text
dialogTextTime = textTime
end
function processDialog()
-- Decrement the dialogue timer.
if(dialogTextTime > 0)then
if(dialogEndWithInput == true and player:mem(0x134, FIELD_WORD) == 1)then
dialogTextTime = 0
dialogSpeakerTime = 0
else
dialogTextTime = dialogTextTime - 1
end
-- While the dialogue timer counts down, display the dialogue.
printText(dialogName..":\n"..dialogText, 30, 500)
end
-- When the speaker timer reaches zero, reset the speaker.
dialogSpeakerTime = dialogSpeakerTime - 1
if(dialogSpeakerTime == 0)then
dialogSpeaker = 0
end
end
function processNPCTalkAnim(npcid, idleMin, idleMax, talkMin, talkMax)
-- Control the specified NPC's animation based on whether or not it's currentSpeaker
if(currentSpeaker == npcid)then
clampNPCAnim(npcid, talkMin, talkMax)
else
clampNPCAnim(npcid, idleMin, idleMax)
end
end
function clampNPCAnim(npcid, min, max)
local myNPC = findnpcs(npcid, -1)[0]
animFrame = getNPCAnimFrame(myNPC)
if(animFrame < min or animFrame > max)then
setNPCAnimFrame(myNPC, min)
end
end
function getNPCAnimFrame(myNPC)
return myNPC:mem(0xE4, FIELD_WORD)
end
function setNPCAnimFrame(myNPC, frame)
myNPC:mem(0xE4, FIELD_WORD, frame)
end
function processNPCTalkAnim(npcid, idleMin, idleMax, talkMin, talkMax)
-- Control the specified NPC's animation based on whether or not it's currentSpeaker
if (currentSpeaker == npcid)then
clampNPCAnim(npcid, talkMin, talkMax)
else
clampNPCAnim(npcid, idleMin, idleMax)
end
end
function clampNPCAnim(npcid, min, max)
local myNPC = findnpcs(npcid, -1)[0]
animFrame = getNPCAnimFrame(myNPC)
if (animFrame < min or animFrame > max)then
setNPCAnimFrame(myNPC, min)
end
end
function getNPCAnimFrame(tarNPC)
return tarNPC:mem(0xE4, FIELD_WORD)
end
function setNPCAnimFrame(tarNPC, val)
tarNPC:mem(0xE4, FIELD_WORD, val)
end
Althought it doesn't work really as expect. May you need to test it...
btw, when you run the code, lua should give you the errors anyway.... (You can even use it in the editor)