Dial
var/npct = "" //What the NPC will say
var/responses = list() // The available player responses
Resp
var/respt // What the response will say
var/Dial/next // Which Dialogue text the response will lead to.
mob
var
mob/talktarget // Who am I talking to?
Dial/activeDial // Which Dialogue message am I reading? (To prevent cheating with the "Topic")
proc
ShowDial() // This makes the Dialogue window pop up
winshow(src,"dial",1)
GetDial(mob/M,Dial/D) // Change what's showing in your dialogue window.
src.talktarget = M
src.activeDial = D // Remember which Dial is active so we can verify that a selected response is valid
if(D)
src << browse("<body bgcolor=black><font color=white><h3>[M.name]</h3><p>[D.npct]</p></font></body>", "window=dial")
var/i=1 //For our grid. This number changes per Resp.
for(var/Resp/R in D.responses) //We have Dial, now what datums are in the responses list?
src<<output("<a href='?src=\ref[src];action=respond;response=\ref[R]'>[R.respt]</a>","playerchoice:1,[i++]")
winset(src, "playerchoice", {"cells="1x[i-1]"})
mob
Topic(href,href_list[])
switch(href_list["action"])
if("respond") // If the link had its action set to "respond"
var/respId = href_list["response"] // Get the /Resp object's ID from the link's "response" param
var/Resp/R = locate(respId) // Use locate() to get the object based on the ID
if(istype(R) && activeDial && (R in activeDial.responses)) // Verify that this is a valid object, and not an old/spoofed link
GetDial(src.talktarget,R.next)
This is a dialogue system that I was troubleshooting a few months ago in the Developer Help forums. I'm now making the code free to use, no credits needed.
This obviously needs a little bit more explanation. The dialogue options and responses are handled like they are in The Elder Scrolls, where each player response and all of the NPC's lines are game objects. They are called Dial and Resp. Each Dial has a list of responses that the player can use, and they are all stored as Resp datums.
You can fool around with the code to make some Dials enable quests. I couldn't include this because each game handles quests differently.
Example of this snippet in action:
Dial
Greet
npct = "Greetings, traveller! How are you?"
responses = list(/Resp/Happy, /Resp/Mad)
Happy
npct = "Well, I'm glad to hear that! I'll be on my way!"
Mad
npct = "Oh, I'm sorry to hear that! I'll leave you alone!"
Resp
Happy
respt = "I'm doing great!"
next = /Dial/Happy
Mad
respt = "To be honest, I'm not doing too well, today. :("
next = /Dial/Mad
mob
OldMan
verb/talk()
ShowDial()
GetDial(src, /Dial/Greet)
Instead I'd suggest organizing it like this to maximize it's maintainability and bug proofing.
Just my thoughts on it.
{Added an underscore to the object's name because typically the default name is going to be used and a space will make it more readable. }