Game Development Community

RPG Level Up System

by Zuero · in Torque Game Engine · 06/24/2008 (12:47 am) · 9 replies

I have a question. I have been learning Torque Script for a little bit, and I want to know if it is possible to make a level up system like that of an RPG? And/or are they any tutorials on how to do so? Any help will be greatly appreciated.

#1
06/24/2008 (1:33 am)
If($monsterSlain)
$exp++;

if($exp => $targetexp){
$level++;
$stats++;}


If you need more specifics, then please provide a more specific question of what you are looking for.


Good luck.
#2
06/24/2008 (4:43 am)
From what I,ve read, the best way is to modify the source code in C++, NOT Torquescript.

That doesn't mean it can't be done, its just not the best way.

I know there is a tutorial on scripted attributes that may help you.

Good luck,
Tony
#3
06/24/2008 (4:50 am)
Brian's got some pseudo code there which contains the mechanic pretty well for assigning xp and levelling up when a certain threshold is reached.

Gameplay stuff like this is actually pretty easy (and fun) to write, just think up your formulas. The harder part is setting up all the GUIs and little specifics.

I can't think of any specific tutorials dealing with this, but I really encourage you to jump in, write down what you want to do, and give it a shot.. you will find the 90% mark of completion pretty quickly.

You'll probably want to do a few basic things and then improve. Most of the stuff happens on server side except for gui changes:

1) Store the values for your experience needed for each level:
$ExpToLevel[1] = 1000;
$ExpToLevel[2] = 2200;
etc...

2) Figure out how much exp the player gains from an activity/action. A common event is combat when a creature is killed. Hook into the something like the onDamage routine for ShapeBase, this will give the xp to the last damager, nothing fancy like who did the most damage.

3) Write a single routine to give new xp, and use that routine to check for level up condition. Here's a small example to get you started
function ShapeBase::addExp(%this,%expToAdd)
{
   %this.exp += %expToAdd;
   if(%this.exp >= $ExpToLevel[%this.level + 1])
      %this.LevelUp();
}

function ShapeBase::levelUp(%this)
{
   %this.level++;
   //Change Stats, assign new points, notify the client with new values, etc.
   if(isObject(%this.client))
   {
      commandToClient(%this.client,'LevelUp',%this.level);
   }
   
}

somewhere on client:
function clientCmdLevelUp(%level)
{
   //Change the GUI or something
   MessageBoxOK("Grats!","You have reached level " @ %level,"");
}


It's pretty easy! Go get 'em
#4
06/24/2008 (8:57 am)
Nice! Thanks for your help you guys. Especially you Dave. Now I have an idea of what to do. I will study your example a bit then I will mess around a bit and so on until I get there. :)
#5
06/24/2008 (9:07 am)
I would recommend looking at the AFXWeapon resource for ideas on how to do this in C++, even if you don't have AFX. It has some code put in place for a C++ stat system that might interest you.
#6
06/25/2008 (7:24 am)
You could also check out the scripted stat/experience system at www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13020
#7
06/25/2008 (7:36 am)
Dang, good one Andy! I did a search before I posted but I must've missed this one, nice link.
#8
07/03/2008 (9:20 am)
Anything on saving stats after death?

Got an issue where you can level up, but once you are killed you start backout at level 1 again.

Is there a way to save temporary progression after death so you can resume leveling or save game at that point?
#9
07/10/2008 (10:35 am)
You'd want to be saving it onto the client object I think. So just replace all those ShapeBase bits in Dave's example code to GameConnection and replace the %this.client bits with %this, then modify your addExp call to be just %obj.client.addExp or %client.addExp and you should be good to go.