Questing Logic

I’m still trying to figure out the logic behind setting up a questing system. It seems like using classes might be my best way about creating this system, I personally haven’t messed around with them to much. Pretty much it will be a system for dropping an npc prefab into the scene and then assigning a specific quest to each npc. I’m just confused about keeping track of everything. The basics would be assigning what type of quest it is, if it’s a kill quest I would probably use enemy tags to specify which enemies need to be killed specifically for a certain quest. I still can’t seem to figure out the logic behind checking if the player is on the quest, if an enemy has been killed adding it to the quest log or when the quest is completed turning it in and moving onto the next quest if there is one. Hoping that someone who has had experience with setting up a system could pass any helpful knowledge they might know, I’ve been searching around and trying to plan out the code but not much luck figuring it out.

This is actually something that I worked on for my game, which has also ended up in my asset store package (below).

Basically the way I’ve done it is to have an NPC Script which is your basic NPC, has a name, some conversation lines (done in a string array for example).

You then have your quest scripts which essentially define a quest. So there will be variables such as : MonsterToKill, NumberToKill, NumberKilled.

For the player to know what quests he is on, you can simply add and remove these quests from a List (e.g. List PlayerQuests). This list can be iterated through for a quest log etc. I’ve handled tracking monsters by checking everytime a monster is killed if the name of the monster matches “MonsterToKill” in any of the quests in List.

You can then assign Quests to an NPC either by having " List ThisNPCsQuests " or by deriving your quest script from Monobehaviour, attaching them to your NPC gameObject and using GetComponents to find all Quests.

Making this all work together is just a matter of references and drawing some onscreen GUI to let the user know what’s going on.

This is my implementation of it, which you can see here in demo form: https://dl.dropbox.com/u/94973732/DexteroRPGFramework/New.html

Now this I can wrap my head around more. So for the list of quests is it a single script containing all the quest info that is then assigned to a specific npc? Something like Quests.js ( quest1 info, quest 2 info, ect.) and then when an npc is placed select which quests the npc should be giving?

Yeah you could do it that way, the only thing I can recommend is to keep the variables as separate from the Questing Logic as possible. This way you can create Quests using simple variables, and then your Quest script will use these to check the player’s progress.

QuestName = "Starting quest";
QuestDescription = "This is a quest";
QuestType = QuestType.KillQuest;
MonsterToKill = "Skeleton";
NumberToKill = 5;

Funny I just checked back here after watching some class tutorials and wrote up a little system. Still not all the logic is here, maybe you can go over it and tell me if anything would need improvement. Still not sure how to assign a line of quests to a specific npc and keep track of what quest the players on.

function OnGui () {

if(killQuest1.questCompleted == true) {

	//display button to complete quest
	//if button is clicked give player reward
 }


}



function Update () {


var killQuest1 : Quest;

killQuest1.type = kill;
killQuest1.enemiesToKill = //monster tag
killQuest1.description = "Go kill those monsters";
killQuest1.levelRequired = 1;
killQuest1.reward = gold += 10;



if(killQuest1.enemiesKilled >= killQuest1.enemiesToKill) 
{
	killQuest1.questCompleted = true;
}


}





Class Quest
{

 var type;
 var enemiesToKill;
 var enemiesKilled;
 var levelRequired;
 var description;
 var questCompleted;
 var reward;



}