[Need Help] Simple Quest System

hi guys ,so i wanna made my second attempt to make game using unity :smile: ,my first game is a really simple side scroller ,like mario :smile:
on this second game i wanna make a storyline and quest system
i already made the quest system by my self ,but i think it’s not effective ,it’s something like this :

if(quest1)
	{
		if(questMark == 0)
		{
		  
			 if(render)
				 {
					//do something
				 }
		 
		 }
		 
		if(questMark == 1)
		{
			if(render)
				{
                      //do something
			 	}
		}
			 
		if(questMark == 2)
		{	
			 if(render)
				{
				 	 //do something
			 	}
			 
		}
	}

it’s long ,and it’s just for one quest ,too many unnecessary process and variabel :frowning:

i wanna use some array for it ,i got the idea ,but i confuise how to implemented it ,hope someone will show me the rope :smile:

EXTRA QUESTION :
which is do you guys thinks more effective , 1 script for all quest (so it’s just will detect tag name for each quest NPC) or make a seperate script for each quest/npc?

thanks guys for your help :smile: ,sorry if my english not good ,not my first languange :smile:

What you can do is that you create a generic base quest class. All your quests will inherit from that base quest class (or use that base quest class). You’ll want to read the information of the quest so what I would do is to store the information externally and have a function for me to call so I can read the information. Of course, all the quests should be stored in a list or an array in a single instance (like a manager) in the game. I would use a list so I can manage all my active quests.

Just a suggestion. There’s no right or wrong answer to a problem. Only how easy and efficient it is to implement it.

hey ,thanks for the reply ,sorry late reply ,i have mid exam and not in touch with unity since then
so i already made the simplest system i can think

i made 2 script ,1 script for the NPC as a detector what npc we thouch ,and the 2nd one is for the receiver and GUI system
what i want to ask is ,how can i print OnGUI with array value?

in normal way ,you can just make
GUI.Box(Rect(Screen.width /2 - 100,Screen.height /2 - 100,250,200), “quest taken”);

but i want to make it like
GUI.Box(Rect(Screen.width /2 - 100,Screen.height /2 - 100,250,200), [array value here]);
and it will display text based on array value on the each spesific NPC ,i am still confuse how to do that :confused:

sorry if i am not explain it properly ,i am not really good with english :smile:

You can only use “1” value to fill your GUI.Box… so the trick is to get a new variable and filling it with your array. (you can still add stuff with +, but it would be a very long line if you’ll use array[0]+array[1]+…).

string questInfo = "";
for(int i=0; i<array.length; i++)
{
   questInfo += array[i];
}

you can also add additional stuff like whitespaces ( ), new lines (\n), tabs (\t), etc to make it look better.

If you just need to show 1 array value you can easily pick it up and use something like an index for it: array[quest]

Personally I’d make use of a few things unity has to offer.

Firstly I’d make an npc script which has variables you can assign in the playerprefs. For example, if say i was doing an RPG and i wanted to kill a wolf enemy, I’d make a singleton that returned a count to the npc script im making, but one. IE when the quest script is active and the playerpref which is assigned to it, for each time a wolf dies the script will go up.

Let me explain this in detail as I myself took almost a year to work this out as i couldn’t find anything to help me:

So you first want to make a general Enemy class, this holds info like health ect, except make this hold the values for each animal ingame, with this base class, you can assign what a wolf is ect, were you might put a public bool on the script so in the inspector you can just drag to wolf, tick the box as a wolf and away you go.

Anyways, with the above done, you’d need to make a quest script. So You can have this in one giant class, but you need to make sure you use the playerprefs (See scripting reference OR Youtube!). So for my first quest, which this falls under, let’s say we make a playerpref

So we do PlayerPrefs.SetInt("Quest1",0);

This basically makes our playerprefs value for quest one, 0 being the default and therefore inactive.
So, if we then look at our npc script you can basically code up a GUI.Button saying “Yes”. What this will do is basically give us the option of letting the player accept the quest. If he or she accepts the quest you then want to declare the value set above as active, so therefore:

PlayerPrefs.SetInt("Quest1",1);

Will be between the button If statement. Now you might consider making the npc script for the start quest, middle quest (Ie when you go up to npc when quest is incomplete the text changes to “Have you killed those wolfs?”) and finally the end, where you declare the quest done and change the player prefs to :

PlayerPrefs.SetInt("Quest1",2);

Note: we set it 1 higher than the active value and not 0 as we don’t want the player to have the quest reset(unless you want that feature).

Now back to the part where the player accepts the quest, so in our example we want the player to kill say 8 wolfs, when he or she accepts in our code :

PlayerPrefs.SetInt("Quest1",1);

so then in our Enemy class OR What ever your are using which keeps track of the wolf health, you want to setup a singleton, All you need to do is within the wolf health script, ie where the health is = 0 (or the wolf dies).
you make an : if(PlayerPrefs.SetInt("Quest1",1)){Singletongoes inside here }

Once you’ve setup a singleton, you can then go back to the quest middle, as forexample if you setup a quest counter on the side, set the current wolfs killed count to rise. To make this rise, you basically make the singleton raise the current wolfs killed int by 1, per kill. Then after that it’s just a case of when current wolfs killed = max wolfs killed:
PlayerPrefs.SetInt("Quest1",2); And then the quest complete GUI become active.

I really hope this helps you, I tried to make that as easy to follow as possible. I did the playerprefs in c# so if you’re a java user you may need to change that. Now I was under the assumption you’d know what a singleton is, however if you don’t there are loads of tutorials regarding singletons on youtube so please check those out, also if your not good a doing class’s check out burgzergarcades tuts and learn about arrays.

Anyways i hope this helps you understand how to make a quest system ingame.

Regards,
Ice

aaaahh i see :smile: ,thanks dude :smile: ,you save me :smile:

that is one awesome reply :smile:
thanks for the help dude :smile:
i will report if something going wrong as soon as possible :smile:

thanks guys :smile:

well I hope it goes well for you. I’ve been meaning to make a video explaining this as it was an issue i struggled with. Once the game I’m making is a tiny bit further along in devolopment, I’ll make a video (say, 1 - 2 weeks), I’ll give you the link as a resource to use.

Also, I made an error as i wrote this up late at night. The line that is :

if(PlayerPrefs.SetInt("Quest1",0)){Singletongoes inside here }

To:

if(PlayerPrefs.SetInt("Quest1",1)){Singletongoes inside here }

As PlayerPrefs.SetInt(“Quest1”,1) is when the quest is active and not PlayerPrefs.SetInt(“Quest1”,0).

Good luck with the codes,

Ice

thanks for the correction :smile: ,phew ,i got too many project from school and can’t actually do the quest system and now all my project done , and i can working on my game freely :smile:

but i need more help :frowning:
1.if i put too many tags on my game on each object (since i assume for the quest system it will check each npc tag) ,will it effect on my game performance?

2.and on this script if(PlayerPrefs.SetInt(“Quest1”,1)){Singletongoes inside here } ,that means each different tag will have different singetones right? (since each NPC will give different quest), and i assume it will be have different whole new script for each NPC ? ,
i meant if we in touch with npc 1 ,we will execute PlayerPrefs.SetInt(“Quest1”,0);,PlayerPrefs.SetInt(“Quest1”,1); and PlayerPrefs.SetInt(“Quest1”,2);
and if we touch the npc 2 ,we will execute again a whole new script like the one on npc 1 right ? ,it will be PlayerPrefs.SetInt(“Quest2”,0); , PlayerPrefs.SetInt(“Quest2”,1); and PlayerPrefs.SetInt(“Quest2”,2);

i am sorry ,i still a little bit confuse right there ,still learning about singleton right now :smile:

thank you :smile:

up :cry:

up…and i can’t delete my post ,*sigh