PDA

View Full Version : [HELP] RPG formulas



Neverbirth
April 5th, 2007, 12:20 PM
Hi everyone, I'm currently working on a turn-based RPG. This is not only my first serious game, but it's my first RPG game as well (no, this is not the typical situation of the newbie programmer dream heh, and every person that has seen it so far gets a good impression with it).

So far I've just made some rather simple games in the past like a Tic-Tac-Toe, a horizontal Shoot'em Up (with just a simple starfield generator in order to simulate scrolling), etc, and I mainly work making desktop applications in other languages.

Because of this and my limited spare time I wonder if any of the common users here happens to have a list of formulas used for battles. Right now I'm just looking for the mainly ones for attacking damage, critical ratio, guard damage, etc.

Each character has these stats so far: Level, HP, EP (for specials), Strength, Speed, Endurance and I'm adding Luck (for criticals and enemy items) and maybe Intelligence as well (mainly for specials damage).

So, can anyone provide me with some formulas? I guess it's not very difficult to make some, but I prefer to center on other aspects of the game before worrying on final formulas.

EDIT: It would be nice if somebody could provide as well some nice formula for the stats change on each level-up based on some initial stats... that would be better than making some sort of look-up tables... Although I may end adding some sort of distribution points for each level tho.

Hansol
April 5th, 2007, 04:47 PM
I have some code from my RPG but its not turn base but anyways here it is i dont know if its exactly what you want. Its pretty basic but if you want me to explain it i can.

This is for when you level up it gives some hp/mp some points and does many other things. Its not that hard to understand what it does.


function addexp() {
if (lexp>=totalexp) {
savelexp = lexp-totalexp;
totalexp += 250;
lexp = 0;
lexp += savelexp;
level += 1;
skillpoints += 4;
totalhealth += 6;
totalmana += 10;
health = totalhealth;
mana = totalmana;
_root.stage.char.attachMovie("levelupanimation", "lua", this.getNextHighestDepth());
_root.imptxt = "Congrats, on level "+_root.level+"!";
_root.txtfade.gotoAndPlay(2);
lua._x = _root.stage.char._x;
lua._y = _root.stage.char._y;
}
}

Neverbirth
April 5th, 2007, 06:36 PM
Thanks, I was expecting something less strict tho, so the initial stats have some effect on a random number generation

I've heard of some formulas that give some possible value, by taking into account a third value... for example, something like the final damage in an attack may be the 65%, 78%, 85% and 93% of the initial strength, and the percentage is chosen by a roll based on luck, but I have no idea of how this is done... any tip?

Dhryn
April 5th, 2007, 08:51 PM
To work out the percentage like that I would do something like this:


// for this luck is between 0 and 50
luck = 25;
/percentage based off luck
function percentage(){
var hitPercent = 50+random(luck);
return hitPercentage;
}


this will work out a the percentage, problem with this is that you cant get 100 percent without 50 luck.

pingnak
April 5th, 2007, 09:51 PM
Any old formula will do; you're making the rules, after all.

One thing that's handy, try pecking the stats and formulas into a spreadsheet.

You can get fairly 'instant' feedback from what you do to it, and spreadsheet formulas can be a regular-expression search&replace (OK, several) away from being code. Or you can save it as 'CSV' data (with whatever passes for 'Show Formulas' turned on) and write a little tool to eat the text and spit out code, if there's going to be a ton of it.

Or you can just hand-apply what you work out from the spreadsheet to your code.

Anyway, the point is, if you're going to do some number crunching, do it in something that makes it easy, and you'll have your formulas perfected in no time.

SacrificialLamb
April 6th, 2007, 01:23 AM
this code should get the numbers 65%, 78%, 85% and 93%

x = 1+random(4);
percent = ((Math.pow(x, 3))*(3.5/3))+((Math.pow(x, 2))*(-10))+(x*(104.5/3))+39;
trace(percent);
damage = initial_strength*(percent/100);
for another game where I was upgrading the enemy and player built speed only I used

function levelUp() {
life<5 ? life++ : p;
hart();
bul_sp+=.5;
lv_ki += 5;
en_sp+=.5;
nx_lvl = 0;
score += 500*level;
level++;
// trace("you have gone up one level to "+level);
if (Math.abs(level%5) == 4) {
//trace("shoult gun updrad");
acbul++;
}
}
And for a RPG I made a long time ago I have some attack code (try to decipher it at your own risk)

hero_attack = function(obj){
if (obj.attacktime<=(100-10*obj.GAg)) {
obj.attacktime += 10;//time betwen attaks
}
if (obj.got_him == 1 && obj.attacktime>=(100-10*obj.GAg)) {
obj.attacktime = 0;
obj.MAg = _global.mane_man_ag;
obj.GAg = obj.me_agility;
if (obj.got_him == 1) {
obj.atack = ((obj.GAg)*(random(10)+obj.MAg));//chans attacker has to miss...
obj.def = ((obj.MAg)*(random(4)+obj.GAg)); //and armer save worked out
if (obj.atack>obj.def) { //and compered
obj.die = (random(4+(obj.me_strength))*((99-obj.me_agility)/100))-obj.me_strength/4;
obj.d = ((5*(obj.me_strength))+obj.die)+random(4); //hit
obj.damig = Math.ceil(obj.d);//Damige given -- calculated in the this and last 2 lines
_global.mane_man_hp -= obj.damig;
trace("_________ghoul hit"+obj.damig);
} else {//miss
trace("__________ghoul miss");
}
}
}
}
attack_ghoul = function(obj){
obj.MAg = _global.mane_man_ag;
obj.GAg = obj.me_agility;
if (obj.got_him == 1) {
obj.atack = ((obj.MAg)*(random(10)+obj.GAg));
obj.def = ((obj.GAg)*(random(4)+obj.MAg));
_root.mane_man.man_1i.attack_me.gotoAndPlay(2)
if (obj.atack>obj.def) {
obj.die = (random(4+(_global.mane_man_s))*((99-_global.mane_man_ag)/100))-_global.mane_man_s/4;
obj.d = ((5*(_global.mane_man_s))+obj.die)+random(4);//hit
obj.damig = Math.ceil(obj.d);
obj.me_hp -= obj.damig;
trace(" hit"+obj.damig);



} else {
trace(" miss");//miss
}
}
}

Neverbirth
April 11th, 2007, 08:44 AM
I haven't had too much time to work on this these days. But after talking with a friend I decided to use a code similar to this one for the roll-based on luck:


function rollBasedLuck(charLuck:Number):Number {
var i:Number;
for (i = 3; i > 0; i--) {
if (Math.floor(Math.random() * (MAX_LUCK * 1.5)) < charLuck)
break;
}
return i;
}And this way I get the array index to use for the percentage.

I already added as well some basic functions for the attack damage, dodging, criticals, and some other things.