ID:1813899
 
(See the best response by Nadrew.)
Code:
    NPC
ExampleQuestNPC
icon='Apop.dmi'
icon_state=""
density=1
Click()
switch(alert("Hello! I'd like to give you an example quest! All I need you to do is say hello! Will you take it?","Example Quest","Yes","No"))
if("Yes")
alert("Thank you for taking the quest! Your Quest Log has been updated with my quest!")
var/obj/Quests/Example_Quest/Q=new
usr.contents+=Q
usr.QuestUpdate()
if("No")
alert("Forget you then. I'll just go do something important, LIKE GIVING APOPHIS HIS SUB.")

obj
var
QDesc
QTeacher
QReward
QToDo
QStatus
QProgress=0
Quests
icon='Apop.dmi'
icon_state=""
Example_Quest
QStatus="<b>ACTIVE:</b>"
QTeacher="Example Quest NPC"
QReward="A Handshake!"
QToDo="Say hello!"
QDesc="The Example Quest NPC has requested that you simply say hello!"
QProgress=0
Click()
usr << output("<center><b>[src.name] --- [src.QStatus]</b><br><i>[src.QDesc]</i><p><b>Quest NPC: [src.QTeacher]</b><br><b>Quest Progress</b>: [src.QProgress]/1</center>","Quest.desc1")
usr << output("<b>To Do</b>: [src.QToDo]<p><b>Reward:</b> [src.QReward]","Quest.desc2")

mob/proc/QuestUpdate()
for(var/obj/Quests/Q in src.contents)
src << output(Q,"Quest.Q")


Problem description:

If you click on the same quest, it'll build up the outputs. Is there any way to clear them when the object is clicked, then display the information so it doesn't clutter up?

Also, I'm unsure if the Quest objs are going to display in the inventory window(src.contents) or if they'll stay in the Quest.Q grid like they're supposed to. I also need a way to check to see if someone has the quest for completion purposes.

Like, for the example quest, when saying "Hello" with the say verb, how do I have it check to see if the user has the Example_Quest obj in their Quest Log?

Best response
You can clear an output control (and various others like a grid) by output()'ing null to them.

src << output(null,"window.outputcontrol")


The quests will display as inventory, unless you filter it, but you can probably just store the quest in your own list and leave the contents list alone for inventory stuff.

mob
var/list/quests = list()


Now instead of using contents you just use 'quests' instead, the list will work the same way, especially if you're just going to be outputting it to a grid.

As for checking if they have the quest in their log, you can use the locate() proc on the list the quests belong to.

var/obj/Quests/Example_Quest/exists = locate() in src.quests
if(exists) // They have it
// Do stuff
else
// They don't have it.


Alternatively,

if(!exists) // Don't have it
else // Do have it


But that's really just a matter of how you need the code to flow, you may only want to do something if they don't have it and exclude the 'do have' condition entirely, up to you.

As a bonus, the 'exists' variable in this case will be an actual type-casted reference to the existing object in the inventory, and you can treat it as such by accessing/changing variables and procs belonging to it.
Thank you so much! That really helped me! ^^