onsdag 29 april 2009

What is game balance, really? Thoughts from a developers PoV.

A few words before we start:
I really enjoy creating a serious online-game. Especially the fact that getting a dedicated team is hard at best, and going indie (solo) requires even more dedication, and is even harder, since time will be more of an issue. This really seperates the serious developers who loves what they're doing, whom goes under the "Made by gamers, for gamers"-motto, and the developers interested in a potential money-gain without realizing what it truly requires to create a well done and loved game, which isn't always equal to a cash-camel, -cow, or -piñata.

In order to make a successful online game, you need balance between elements, and giving the game a depth. From an RPG PoV, classes has to be balanced, they need to scale "equally", and things like items, armors, mobs, bosses, even inventory of vendors has to have at least some degree of balance, if you want to give your gamers a serious impression. To some degree even such things as the players surroundings / scenery has to be properly balanced. One does not start playing a level 1 character in a game starting in the dragons lair killing rats, working their way to the rats lair, killing dragons. Balance and depth are keys.

But how do I achieve balance and depth?
In order to create a balanced game, I've had to do alot of sketching, alot of diagrams, and alot of number crunching. How and when should things scale? At what intervalls should the scaling be verified (read: synced)? What should scale? I can write it on paper, but how do I make the process automated? Where is the start and end of the scaling (level 1->X? Some games "start" at level 10)? Should there be a cap, if so, where, and on what: stats, avoidances, hit/crit, money, or things such as xp-gain or even onlinetime? If you haven't gotten the picture on how to create balance in your game yet, let me continue.

In my sketch-books, containing hundreds of pages of notes, propositions and examples, I've an example of a working balanced system, at least in theory. In order to implement it, I've done way more than I anticipated.

Adding 15 classes, all with different roles and dynamics, starting with gear in ~10 slots, 6 races, and 2 sexes, and keep them all BALANCED, with starting stats, starting gear, and what I call a "scaling-table", which is like a road-map the class in question uses when it gains a level for their automatic and/or manually distributed statgains. I've had to do alot of work. Starting to get the picture on what balance is? No? Let us continue then.

Working through all the already mentioned, I've also had to actually create both class specific prefabricated items, and a automated item creation system, since lets face it, we don't want our NPC's to have the same gear all the way to the level-cap, and we do want some variety in the gear provied. 2,4 million combinations of gear per item-level, which is hidden levels for the items to determine their strength, obviously, and to make sure that the gear used is actually intended and balanced for the level of the NPC. We wouldn't want a mid-level player running around with the most powerful weapon in the game. Item-level is a way for the game to measure the strength of any given item.

And for all previously mentioned elements to be balanced, I've had to create mobs and bosses with a difficulty rating that resembles the quality of the items which the player gains from killing the said mobs. Yeah. And how is that done, really? Is it balanced when a mob goes down quickly (Hack n' slash-genre warning), or should a mob actually provide a challenge? When is it too challenging? What should the droprate be? Should items be somehow bound to NPC's or the player, or should players be allowed to put any item up on the market for other players to buy? How would that affect the economy? Should items on the marked be available for players on the other continent? I can keep going with more vital and not-so vital questions. But the point is this;

What is balance?
Balance is truly in the eye of the beholder. The question is, should the game be balanced around the developers view of what is considered balance, or should he put himself in front of the screen of one of his players? Any gamer knows the answer to this question. Any gamer gone developer should know the answer to this question. But people who develop without actually playing, is like designing a moonbase for NASA without actually knowing what it'll be like living on the moon, along with what is appreciated from its users and what is not. Any serious developer does a decent amount of research. You're probably reading this article for that very reason. Heck, I've even read up on real-world ores, metalls, leathers, cloths and different kinds of processing techniques, just to find inspirations to the items, and that is just a small part of the entire game. So, I ask you, have you gotten the picture of how to create balance now?

The one and only way to achieve balance, in plain english:

If you've read through the article, you should already, on some level, already know the answer to this. The answer is planning. You can't create a balanced system on the fly, especially if it's big and complex. Even big-budget companies with a huge amount of developers spend months planning their several-years-project MMO's. I suggest getting a pen which feels good to grip and hold, and a notebook, which you carry around wherever you go. Whenever you get an idea, you write it down. Whenever you have time to kill, start sketching on ideas. Whenever *anything*, get it into your notebook. This is described by Stephen King in his book "On Writing", which is a book about writing books. In it he recommends anyone serious about writing to always carry a book with him/her, and read whenever an opportunity to do so arises, wherever he or she might be, even if it is "socially questionable", such as restaurants or in the bathroom. And it's actually not a bad idea. Carry a notebook and a pen wherever you go. When you wait for someone, you take it out. Whenever you're waiting for the train, you sketch in it. When the train has arrived and you've climbed aboard, you keep writing in it. When you're driving your car and can't write, I suggest listening to audio books. It doesn't have to be game-oriented. Anything that can act as an inspiration is a good source. Harry Potter, Sun Tzu's Art of War, and other well known books are good sources of insipration regardless of what type of game you're developing. They'll help you add depth to your game.

It's not about making something fun and turning it into work. It's about endulging yourself with your passion wherever you are.

måndag 27 april 2009

Creating a random name generator with PHP






While working on my auto-generated entry-level NPC's for my onlinegame, I noticed I wasn't really happy with the names that was generated. And since I spent time to make it sex-independent (males and females get seperate names), I decided to write a short article of how to create a random name generator using PHP. This guide is fantasy/rpg-based, but the principle can be applied to real names or what-have-you.

There are many ways to do it, this is simply one of them. First off you'll need to decide if you want the names to be compiled by two or more parts, or if you simply want to get a random name from a list of names. I will show how to create names compiled by three parts, which will be the prefix, infix, and suffix (beginning, middle, and end). The scripts can however be modified to use more or less parts to create the random names.

The reason behind me using three parts is because 1) it allows for a broader spectrum of possible names, and 2) gives me the option to use more combinations of masculine and feminine derivatives, both in the prefix and the traditional suffix. If you're interested in doing a good name-generator, I suggest you read up on derivatives.

You can either decide to use arrays which contains the names, use a database, or textfiles. I find the use of a database overkill, and the use of arrays can get messy with a bad overview if you have many parts and many combinations. But for a small range of combinations and alternatives, arrays might be an easier option, and the code-example can easily be modified to use arrays instead of including the files in the first step.

Now, on to the code. We'll show the feminine version.


# Add the parts to arrays
$prefix = file("includes/1_female.txt");
$infix = file("includes/2.txt");
$suffix = file("includes/3_female.txt");

# Randomize them
shuffle($prefix);
shuffle($infix);
shuffle($suffix);

# Pick a (randomized) value
$prefix = rtrim($prefix[0]);
$infix = rtrim($infix[0]);
$suffix = rtrim($suffix[0]);

$name = "" .$prefix ."". $infix ."". $suffix ."";
#Also works, but are considered "ugly":
# $name = "$prefix$infix$suffix";



*First part adds the contents of the files to variables as arrays, which means first row has the 0-key, second row has the 1-key, etc.
*Next we'll need to randomize the content. There are several ways of doing this, I personally prefer shuffle(), since it makes things look more tidy. You could also count the lines of the file to a variable to use as the key with rand(0,sizeof($var)-1), and then use $prefix[$var] at the third step to get a random line from the file, though I personally think it looks ugly. Nevertheless, it's an option.
*Third part is to pick out a random entry. Since we used shuffle(), we can use any valid key to get a random value, since we won't know the order of the array unless we peek inside it. First entry is always a good option, so we'll use the first key (0).
*Last part is to simply put the pieces together. I decided to give an extra option of how to do this, since both do the same thing, and the massive usage of quotationmarks can be abit disctracting for new programmers.

A very simple example of how the text-files are composed (suffix overlapping the prefix) using 2 parts to compose the names. Might be worth mentioning that when using infixes and suffixes, clever usage of blank lines works, and adds an extra dimension to the names, making some names to be shorter. But if you'd use the type of list below I'll guarantee that your names will look butt-ugly.


The result can be viewed on top. It's hardly meeting any fantasy-standards, and some names might be abit of a tongue twister, but should at least serve as an example of what the end result would look like. Both sexes uses the same infix, but I use different prefixes and suffixes for the masculine and feminine names. See the first part of the code-example and you can probably figure out what needs editing to add masculine derivatives.

Entry level NPC's

Yesterday I was reworking the NPC's database, along with working on the initial attributes of the NPC's (lvl1 stats), but had to call it a night since it was such a mammoth-sized job. Today I'm continuing the effort to have a balanced entry-level for the 4 starting classes (out of the 15), which serves as the yellow bricks on my road to class-balance. I'll also have to generate the gear for the newly created NPC's, but since I've already got the automatic item-generator working, I'll just need to tweak the entry level for stat-, armor- and damageallocation on the items. I'm estimating it to take roughly ten, or so, hours of wonderful numbercrunching, formula-editing, and the oh-so-lovely satisfying realization when I notice I spent an hour on something that can be done with three or four lines of code.

And after that it's time to move over to the combat simulation, which luckily already is tested and works, at least for the initial version of the game.

About this blog & Copyright information

10 months into developing my PHP game I decided to start a journal about the process of making an online game. This will help me remember the steps I took when I'm done, and will serve as a draft for the full guide I hopefully will be publishing. I've read many tutorials and (b)logs about how to create games, and short of a very narrow selection of books, there are no real sources of the game-making process, not counting the few (b)logs who ends after a chapter or two, more or less containing "this is what will be in this blog in the future", usually written years ago.

I'm here to listen, so feel free to post comments and ask questions.

Copyright information:
If you like what I write, please don't copy and paste the text to another site without asking me for permission first. It is okay to, without permission, and if I am the author, copy two or three sentences to another site as a quote if you also provide a link to the article from where the text was copied. If you do, I'd appreciate if you could link to it in a comment to the article in question, although it's not mandatory.