RPG Battle System

Started by
15 comments, last by ARC inc 14 years, 1 month ago
Anyone know where I can find a decent RPG Battle system that I can take a look at to improve mine? Because mine doesn't work properly this should be in C++
Advertisement
You'll probably get better help if you explain why yours doesn't work, but here's a decent RPG system.
here is my battle system but it always says that my player does 0 damage etc.

	int x;		x = rand() %5;	if(x == 0)	{		c.str = c.dmg + 1;	m.health -= c.dmg;	cout << "Your attack deals\n" << c.dmg << "Damage\n";	}	if(x == 1)	{		c.str = c.dmg - 1;	m.health -= c.dmg;	cout << "Your attack deals\n" << c.dmg << "Damage\n";	}	if(x == 2)	{		c.str = c.dmg / 2;	m.health -= c.dmg;	cout << "Your attack deals\n" << c.dmg << "Damage\n";	}	if(x == 3)	{		c.str = c.dmg * 3;		m.health -= c.dmg;	cout << "Your attack deals\n" << c.dmg << "Damage\n";	}	if(x == 4)	{		c.dmg = 0;	cout << "Monster Blocked your attack!\n";	}	if(m.health <=0)	{		cout << "You killed the monster!!\n";	}	else	{		cout << "Leaving the monster with\n" << m.health << "Health Points\n" << m.monster_name << "Will now attack you!\n";		 				int y;				y = rand() % 5;				if (y == 0)				{				   m.str = m.dmg;				}				else if (y == 1)				{				   m.str = m.dmg - 1;               }				else if (y == 2)				{				   m.str = m.dmg + 1;               }				else if (y == 3)				{				   m.str = m.dmg*2;               }				else if (y == 4)				{				   m.dmg = 0;                     cout << "Miss\n" << endl;               }				c.health = c.health - m.dmg;			   if(c.health <0)			   {				   cout << "Game Over\n";			   }	}	monster_load.close();	load_account.close();


it also never lets the monster attack, it just skips over that part. Any ideas?
You never set your dmg variable. You need to swap str and dmg in your damage calculations.
Developer for Novus Dawn : a [s]Flash[/s] Unity Isometric Tactical RPG - Forums - Facebook - DevLog
Also
Quote:x = rand() %5;
where rand() is [0, 1), which means modulo 5 will always return 0. I think you are wanting rand() * 5 which will give [0, 5) as a result.
rand() returns an integer between 0 and RAND_MAX, so rand() % 5 returns an integer between 0 and 4 inclusive. It is correct, although not a perfect distribution.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Sorry fellas didn't work I did get the monster to do damage an it's giving me weird amount of damage an def not showing up so I am thinking I did something wrong with code somewhere along the line idk though
Are you seeding the random number generator?

#include <time.h>int x;srand(time(NULL)); //Seed the random number generator, or you'll always get the same number.x = rand() % 5;//The rest of your code.


I think you only need to seed it once, so probably in your main() function and not in your battle function.
yeah i tried that still didn't get me what i needed
for some reason my rand keeps on landing on the same rand, and never changes any ideas?

srand(time_t(NULL));int hit_miss;hit_miss = rand() %4;		if(hit_miss == 0)	{		c.dmg = c.str+1;		m.health -=c.str;		cout << "(rand 0) You do\n" << c.dmg << "Damage Leaving\n" << m.monster_name << "With\n" << m.health << "Health points\n";	}		else if(hit_miss == 1)	{		c.dmg = c.str+1;		m.health -=c.str;		cout << "(rand 1)You do\n" << c.dmg << "Damage Leaving\n" << m.monster_name << "With\n" << m.health << "Health points\n";	}	else if(hit_miss == 2)	{		c.dmg = c.str*2;		m.health -=c.str;		cout << "(rand 2)You do\n" << c.dmg << "Damage Leaving\n" << m.monster_name << "With\n" << m.health << "Health points\n";	}		else if(hit_miss == 3)	{		c.dmg = 0;		cout << "(rand 3)You miss\n";	}

This topic is closed to new replies.

Advertisement