Health/Damage System

Started by markcullinane, Sat 05/03/2005 12:18:12

Previous topic - Next topic

markcullinane

I'm at the moment trying to create a health/damage system for my game. It's an action-RPG very much in the vein of classic SNES title Secret of Mana, and its coming along fairly well at the moment.

I don't, though, have a clue about how to go about making a damage system. What I was hoping for was something like this:

-The player character has a health of 50, represented on-screen as 50/50, 45/50, whatever. When a player comes into contact with an enemy, his health is reduced by 5.

I haven't seen a thread on the forums addressing this topic, if anybody can help it would be great, and would give me a kickstart back into getting this game finally completed.
Thanks in advance.

Pumaman

You won't tend to find an existing thread on topics like this because it depends so much on your game. No two games implement health and damage the same way, and how you script it really depends on how you want it to work.

Anyway, for your idea, you could use RawDrawRectangle or a GUI Slider to keep the health bar on screen and up to date, and use AreCharactersColliding to determine if the player has touched an enemy.

markcullinane

Yeah, I understand that all games would be different. What I'm struggling with at the moment is defining variables for health, and adding or taking away health when characters collide, or when a health-restoring item is used. I'll worry about keeping the figures up to date and shown on-screen after I get the basic framework in place. I'm just at a loss at how to go about doing it. Anyone have any ideas how to begin?
Thanks

Ashen

Try the AGS: Can I Make an RPG with AGS? thread for some pointers, in particular CoolBlue-Gord10's tutorial looks like a comprehensive place to start. If you have any specific questions ask back but, as you know, a lot of the specifics will depend on how you choose to go.
I know what you're thinking ... Don't think that.

markcullinane

Right, I'll give them both a look. Thanks. I'll probably be back here with more questions soon...


SilverWizard_OTF

#5
My friend, i had the same problem too when i was trying to create a Battle-System for my game.
Well, hear what i did:
1. I created a new GUI, which was revealed only when a battle was started. In this GUI, there were written my hero's (Isildur) health statues and his enemy health statues like this:
Ã,  Ã,  ......................................................................
Ã,  Ã,  .ISILDURÃ,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  ENEMY
Ã,  Ã,  .
Ã,  Ã,  .50Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 50
Ã,  Ã,  .
Ã,  Ã,  .......................................................................

I had labels that were represented health stats, in which were wrote by default the number 50.

Now in the game:
When the enemy hits your hero, then you should add after the hit animation, the script command SetLabelText(6,1,ii_health); "ii_health" is a variable which is decreased too (it has also by default the value 50) with the script command ii_health=-20 (for example if you want too be decreased the health by 20 points).
Then you should run a conditional like:
Ã,  Ã, If (ii_health<=0) {
Ã,  Ã,  Ã, display("You have lost")
Ã,  Ã,  Ã, quitgame(0);
Ã,  Ã,  Ã, }

You might want to see this part from my code, for more help:

int isildur_health;
int badguy_health;
int who_starts;

function isildur_punch() {
Ã,  int punch=Random(1);
Ã,  if(punch==0) {
Ã,  Ã,  Display("You try to hit him to the face...");
Ã,  Ã,  Display("But you missed!");
Ã,  Ã,  }
Ã,  else if(punch==1) {
Ã,  Ã,  Display("You try to hit him to the face...");
Ã,  Ã,  Display("He can not stop you!");
Ã,  Ã,  Display("He makes a step back...");
Ã,  Ã,  badguy_health-=20;
Ã,  Ã,  string ii_health;
Ã,  Ã,  string ib_health;
Ã,  Ã,  StrFormat (ii_health, "%d",isildur_health);
Ã,  Ã,  StrFormat (ib_health,Ã,  "%d",badguy_health);
Ã,  Ã,  SetLabelText(6,1,ii_health);
Ã,  Ã,  SetLabelText(6,2,ib_health);
Ã,  Ã,  Wait(20);
Ã,  Ã,  }
Ã,  if(isildur_health<=0) {
Ã,  Ã,  Display("You can not believe what happened...");
Ã,  Ã,  Display("YOU HAVE LOST THE DUEL...");
Ã,  Ã,  NewRoom(51);
Ã,  Ã,  }
Ã,  if(badguy_health<=0) {
Ã,  Ã,  Display("VICTORY!");
Ã,  Ã,  Display("Mary-Ann might learn about this...");
Ã,  Ã,  Display("And that would be your best reward!");
Ã,  Ã,  Wait(20);
Ã,  Ã,  NewRoomEx(36,190,240);
Ã,  Ã,  return;
Ã,  Ã,  }
Ã,  Wait(1);
Ã,  }

Where each FUNCTION represents a kind of attack in my battle system.


At last, do not forget to make the necessary adds to the Script Header, in order to be able to use your global variables to Room Scripts if you wish.

Here is on example from my code:
Ã,  Ã,  SCRIPT HEADER
import int isildur_health;
import int badguy_health;
import int who_starts;
import function starti();
import function startb();
import function isildur_punch();
import function isildur_kick();



That's all! I hoped i helped you a bit. Please send me a reply in order to learn if this code helped you.
Ã,  Ã, Good luck


Also if anyone that reads this message, finds this code useful for creating rpg battle systems, please let me know!!!
"All we have to decide is what to do, with the time that is given to us"

markcullinane

I'll take a close look at that code tomorrow and get back to you then, SilverWizard. Thanks for it, it looks useful.
One thing I forgot to say, was that the game I'm making isn't strictly an RPG, at least in that the battle system is real-time as opposed to turn-based.
The main problem I'm having then is assigning a certain number of HP to an enemy and to the main character, and causing it to decrease when struck by an enemy or increase when I use a health potion or the like. I'm not going to try to do anything more complicated than that. 
I'll be back here soon! Thanks

SilverWizard_OTF

Personally i think that creating global variables that represent your characters' (heroes and enemies) health points, is a very good idea.
  With the process i described you before, the Health Status Gui will show the values of your variables. So, if your hero is strucked by enemy, you have just to script: hero_health=-20 (for example). Also then, you can run a conditional:
  If(hero_health>0) {
     //your code here
   }
  If(hero_health=<0) {
      Quitgame(1);
   }

Also, in my opinion an attack can be achieved using functions. as i described above (with some tricks, you can add these features to real time battle).
"All we have to decide is what to do, with the time that is given to us"

SMF spam blocked by CleanTalk