Sign in to follow this  
stein102

Quest system

Recommended Posts

stein102    556

I'm writing a RPG in Java and am starting to think about how I'm going to implement my Quest system. My first thought was to store everything into XML and read from that. Although after doing a little research into the topic, I see a lot of people suggest using a scripting language to do this. I've never really played with this kind of stuff, so naturally I have a few questions

 

1) What would be the pros/cons to using scripting compared to XML?

2) How would I write a script to represent a quest in my game?

3) How would I parse this script into something I can work with in Java/LibGdx?

 

//A sample quest in XML(Not a real example from game)

<quest id = "0" name = "Rat hunter!">
	<description>Slay 10 rats and return to me when you're finished</description>
	<objective type = "slay" number = "10" monster = "54"/>
	<reward type = "experience"	skill = "attack" value = "500"/>
	<reward type = "item" id = "4"/>
	<return npc = "63"/>
</quest>

Basically a quest where you need to kill 10 rats(monster ID = 54). Your reward is 500 attack experience and an item with an ID of 4. You must return this quest to an NPC with the ID of 63. I just wrote that quest in about a minute, so it's a rough example.

Share this post


Link to post
Share on other sites

Well you *could* store all your quests in an xml format, but then you'd have to stick to a predefined structure. This limits the quests you can make to a few types ("slay", "deliver", etc). You also wouldn't be able to easily implement game logic like giving the player a special hammer or branching the quest plot if the player decides to do something particularly evil along the way. I imagine the experience would become repetitive after a while since you're just handing the player the same quest with different parameters over and over.

 

To put it more simply: xml is for storing "static" stuff like the inventory of a player.

A quest should (ideally) be a more dynamic experience and that's where scripting languages come in: You have full control over the objects of the game but you don't have to touch the "guts" of the game engine. If you were to develop the game with a friend who isn't a java programmer he can still create quests by writing scripts (which are generally less complex). He doesn't need to know how a goblin is spawned in the java code - he simply scripts "spawnGoblin(x,y)".

 

The obvious advantage over XML is that you don't need to stick to a particular quest 'format' and are able to craft a more finely tuned experience. You store the script for a quest in its own file and run it when needed.

 

 

You *could* code the quests in java but that would mean recompiling the game every time you change something and would probably produce code that's more difficult to understand (and takes longer to write) than the more 'high level' script code.

 

A quick google search shows this example script for a quest

function Escort_Spawn(QuestGiver, Event)
pQuestGiver:SendChatMessage(12, 0, "Watch out!")
pQuestGiver:GetX()
pQuestGiver:GetY()
pQuestGiver:GetZ()
pQuestGiver:SpawnCreature(NPC_ID2, x+5, z+5, y, 0)
pQuestGiver:SpawnCreature(NPC_ID3, x+10, z+5, y, 0)
pQuestGiver:SpawnCreature(NPC_ID4, x+7, z+7, y, 0)
pQuestGiver:RegisterEvent("Escort_Move4", 40000, 1)
end

As you can see, this code is easy enough to understand without knowing anything about the functions and objects being used.

 

As for the actual implementation of a scripting engine: since you're working with Java there are plenty of libraries at your disposal. It's as easy as picking a scripting langauge (lua, python, ...) and then finding a decent scripting engine for it (LuaJ, Jython, ...) .

 

 

recommended reading (not java specific but it will give you a general idea to use as a starting point):

http://www.gameengineer.net/downloads/tutorials/AngelScript/Game%20Scripting%20101.pdf

http://www.gamedev.net/page/resources/_/technical/game-programming/an-introduction-to-lua-r1932

http://www.gdcvault.com/play/1012427/Lua-Scripting-in-Game

Edited by molehill mountaineer

Share this post


Link to post
Share on other sites
stein102    556

Okay, so I'll use scripting for this like you suggested. Which language would you suggest based on what information I gave you? I've never used either, so that needs to be taken into consideration. I don't really see it as being a big deal though, a language is a language. Personally I'm leaning a little more towards lua because it's more valuable to know if I wanted to get a job in the industry.

 

I'm still somewhat lost on how the system would work though. My idea is that a Quest would just be a collection of objectives and the objectives and the objective would hold what the player needs to do next in the quest, then when it's completed, gets popped and goes to the next objective.

 

The idea of using scripting is still really weird to me though.

Share this post


Link to post
Share on other sites

Well you can certainly implement the quest system that way, but it would have the limitations I mentioned in my previous post. Really it's up to you - if you make the quest system with XML I'm sure that would be a great learning experience. I'd be willing to bet you won't go down the same route for the project after that. Really, I have learned the most from making mistakes and strange design choices so I'd never be one to say don't ever do X or Y (as long as you learn something from it). 

 

Picking a language is, again, up to you - certainly Lua is a common choice for professional games (but finishing your project should be your top priority rather than "doing what the pro's do").  

 

This might help you along a bit: http://www.godpatterns.com/2005/07/using-lua-scripting-for-games.html

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this