Quote from: monkE3y_05_06 on Fri 08/07/2011 06:28:07
This has actually been asked many a time. It's relatively simple to store current and max health levels in int variables. You can also use extender methods to link your variables into your characters, which is primarily aesthetic, but is nice for organization and such.Code: ags // Script.ash import int GetHealth(this Character*); import int GetMaxHealth(this Character*); import void SetHealth(this Character*, int health); import void SetMaxHealth(this Character*, int maxHealth); // Script.asc int character_health[]; int character_max_health[]; function game_start() { character_health = new int[Game.CharacterCount]; character_max_health = new int[Game.CharacterCount]; } int GetHealth(this Character*) { return character_health[this.ID]; } int GetMaxHealth(this Character*) { return character_max_health[this.ID]; } void SetHealth(this Character*, int health) { character_health[this.ID] = health; } void SetMaxHealth(this Character*, int maxHealth) { character_max_health[this.ID] = maxHealth; }
Usage would then be something like:Code: ags player.SetHealth(80);
Of course you may want to add some checks to make sure health isn't set to exceed max health, but that's the basic gist of it.
As for displaying this on a GUI, there's various ways you could implement that. For example you could have a button with a background image set to represent full health, then simply change the button width according to the character's health percentage. So long as you have it set to clip the image then you now have a functioning health bar.
There's other ways to do it too of course, but it would depend exactly what you are wanting to achieve.
thanks dude!!! but is there a way that i can lower this health occording to if they get hit (like a fighting game)