Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- tArgs[1] = tArgs[1] or 42
- local ok, errr = xpcall(function()
- fs.delete("dialogueTools.lua")
- print("Downloading dialogueTools.lua... ")
- shell.run("pastebin get vcFgTaRV dialogueTools.lua")
- print("Done.")
- local dt = require("dialogueTools")
- local mon = peripheral.find("monitor")
- local modem = peripheral.find("modem")
- local oldTerm = term.redirect(mon)
- modem.open(tArgs[1])
- mon.clear()
- mon.setTextScale(0.5)
- mon.setCursorPos(1,1)
- local function bug(a)
- mon.write(a)
- local x, y = mon.getCursorPos()
- mon.setCursorPos(1,y + 1)
- end
- --[[
- local function newBranch(labelString,responseString,cID,tID)
- return { label = labelString, response = responseString, branchID = cID, targetID = tID }
- end
- ]]
- local npcGroups = {
- --assign npcName = "npcGroup"
- elderango = "elderango"
- }
- local dialogueTree = {
- --NPC groups
- elderango = {
- --Text color for group
- color = colors.orange,
- --Dialogue branches
- dt.newBranch(0,0,"",""), --Goodbye
- dt.newBranch(1,10,"...","HEEYY BROTHER"),
- --1st main option list
- dt.newBranch(10,20,"How's it going?","BROTHER IT'S NEVER BEEN MORE RADICAL"),
- dt.newBranch(10,10,"I can only say this once per converstation.","CORRECTOMUNDO","prune"), -- Pruning tag
- --Mood responses
- dt.newBranch(20,21,"What's so radical?","BROTHER I ACTUALLY LIED. IT'S NOT RADICAL. I'M IN CRIPPLING DEBT BECAUSE I CAN'T MAINTAIN A STEADY JOB TALKING LIKE THIS."),
- dt.newBranch(21,10,"Oh, I'm sorry to hear that...","..."),
- dt.newBranch(20,10,"Gnarly","HEEELL YEAH"),
- --Logs quest
- dt.newBranch(10,30,"Do you have anything you need help with?","HOW KIND OF YOU TO ASK. I AM IN NEED OF 32 OAK LOGS. COULD YOU GET THEM FOR ME?"), --If/then tag for quest accepted
- dt.newBranch(30,10,"Sure thing","MUCHO APPRECIANTO, BROTHER.", quest = dt.setQuest("elderangoOakLogs","minecraft:oak_log",32) ), --Quest setter tag
- dt.newBranch(30,10,"Sorry, I'm busy right now.","THAT'S UNDERSTANDABLE."),
- dt.newBranch(31,32,"","HEY BROTHER, HOW'S THOSE LOGS COMING?"), --Alternate dialogue start if quest is active. Mutually exclusive option with 33 tag
- dt.newBranch(32,33,"I've got the logs","NICE JOB BROTHER. I KNEW YOU COULD DO IT"), --Mutually exclusive option with 32 tag
- dt.newBranch(32,10,"Still working on it.","ALRIGHT, NO RUSH BRO. TAKE YOUR TIME"), --Quest not complete
- dt.newBranch(33,10,"Any time","SINCE YOU DID ME A SOLID, BRO, TAKE THIS. IT'S THE LEAST I CAN DO"), --Quest is complete, reward tag
- dt.newBranch(10,41,"Hey, what are you going to use those logs for?","I PLAN ON BUILDING AN ANIMAL SHELTER FOR THE GNARLY LITTLE CRITTERS WITHOUT HOMES OR CARING OWNERS."), --If/then tag
- dt.newBranch(41,10,"Wow that's actually really sweet","IT'S SWEET AS HELL, BRO. UNLIKE THE PAIN THOSE LITTLE BUDDIES FEEL"),
- },
- }
- local function msgWait()
- local event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
- local targetID = message.targetID
- local selectedIndex = message.selectedIndex
- local name = message.name
- return targetID, selectedIndex, name
- end
- local tagList = dt.makeTagList(dialogueTree)
- bug("Saving taglist...")
- bug(textutils.serialize(tagList))
- local f, err = fs.open("branchTags.txt", "w")
- assert(f, err)
- f.write(textutils.serialize(tagList))
- f.close()
- bug("Saved tagList")
- --Main loop
- while true do
- local targetID, selectedIndex, name = msgWait()
- local package
- mon.clear()
- mon.setCursorPos(1,1)
- bug("Main: Request from "..name.." for ID "..targetID.." with index "..selectedIndex)
- if not npcGroups[name] then --Check if turtle has an assigned group
- package = "missingName"
- modem.transmit(42, tArgs[1], package)
- error("Msg: Missing name "..name)
- else
- local group = npcGroups[name]
- bug("Main: Group sucessfully assigned for "..name.." as group: "..group)
- if not dt.checkID(dialogueTree,group,targetID) then --Check if requested target ID exists
- package = "missingTID"
- modem.transmit(42, tArgs[1], package)
- error("Msg: missing target ID")
- else
- package = { tName = name, color = dialogueTree[group].color, branches = {} }
- --Fill package with data
- bug("Main: Filling package with data...")
- for i = 1, #dialogueTree[group] do
- local f, err = fs.open("branchTags.txt", "r")
- assert(f, err)
- local contents = textutils.unserialize(f.readAll())
- f.close()
- if dialogueTree[group][i].branchID == targetID then
- if dialogueTree[group][i].tags then
- bug("Tags: Branch "..i.." in group "..group.." has tags: "..textutils.serialize(dialogueTree[group][i].tags))
- for k in pairs(contents[group][i][1]) do
- if k == "prune" then
- bug("Tags: Found prune tag in tagList for branch "..i)
- if contents[group][i][1].prune == false then
- if selectedIndex == i then
- contents[group][i][1].prune = true
- local f, err = fs.open("branchTags.txt", "w")
- assert(f, err)
- f.write(textutils.serialize(contents))
- f.close()
- bug("Tags: prune branch and set prune to true")
- else
- bug("Fill: Added branch "..i)
- table.insert(package.branches, dialogueTree[group][i])
- package.branches[#package.branches].index = i
- end
- end
- elseif k == "quest" then
- bug("Tags: Found quest tag in tagList for branch "..i)
- local questName = contents[groupName][i][1].quest.questName
- if contents.quests[questName].isActive == false then
- if selectedIndex == i then
- contents.quests[questName].isActive = true
- local f, err = fs.open("branchTags.txt", "w")
- assert(f, err)
- f.write(textutils.serialize(contents))
- f.close()
- bug("Tags: Quest "..questName.." set to active and pruned")
- else
- bug("Fill: Added branch "..i)
- table.insert(package.branches, dialogueTree[group][i])
- package.branches[#package.branches].index = i
- end
- end
- end
- end
- bug("Tags: Processed tags for branch "..i)
- else
- bug("Fill: Added branch "..i)
- table.insert(package.branches, dialogueTree[group][i])
- package.branches[#package.branches].index = i
- end
- end
- end
- bug("Main: Sending package with "..#package.branches.." branches")
- --Send package
- modem.transmit(42, tArgs[1], package)
- end
- end
- end
- end, debug.traceback) if not ok then printError(errr) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement