0 Favourites

Damage calculations?

  • Hi, how would I go about making a system where a damage calculation is played based on the users attack variable, the attack's own damage value as a modifier of the users attack variable, and the targets defense, all calculated universally by calling the calc when ever damage is done.

    So that the only thing every hero or enemy object needs is an HP, ATT, and DEF variable in their instances?

    This is for a sidescroller by the way, so theres collision detection.

    Say for example, player uses fireball(Technique) on an enemy and it overlaps on them, then the damage calculation should be called: Players Attack*Techniques Power / Enemy Defense = Damage total, which is substract from the HP variable of the enemy.

    I don't want to go and use a simple system where I just type "-5" for the damage of a fireball on an enemy, independent of the user of the fireball. I want the fireballs damage to be based on the user, while the fireball itself has an attack value, it is a multiplier of the users own attack power, instead of being independent damage. Like say, Fireball's value is always 1.25, so if the player's attack is 100, then the total damage is 125, if the players attack is 8, then the total damage is 10. Then the enemies defense comes into play, dividing the damage by the defense value.

    How would I go about implementing this? What method is the most efficient?

    To reiterate: Player and enemies have HP, ATT, and DEF as stats. Attack techniques have POWER as a stat{damage modifier}. And theres a calculation that is called everytime damage occurs to a target, based on these values and subtracting the results from the self HP attribute of target.

  • Well, construct does allow you to do math in most(all?) variable changes, so how I would do it is:

    Stats associated with each player/enemy (HP, ATT, and DEF)

    Stats associated with each ability (POWER, Anything else needed (maybe cooldown, mana cost, w/e) -> This could be organized in an array.

    Then when you detect the collision, I would probably call a function "Damage Enemy" with the parameters EnemyID, ATT and POWER

    In this function, you pick the correct enemy and run an event such as

    Enemy -> Subtract from instance variable "HP" -> Amount = ATT * POWER / Enemy.DEF

    Then make a sub event checking (if Enemy.HP <= 0)

    Enemy -> Destroy

    You can also add other things into this function such as creating floating text displaying the damage dealt or sound effects for the enemy being hit.

  • Yes! This is what I was looking for, thanks. So Functions and Arrays is what I should be trying to use? So for the attacks properties, they should be assigned to an array while the player/enemy stats can remain as instance variables, or would ATT and DEF be in arrays while HP as a variable?

    Thanks, Robsta. Your post was very informative.

  • Functions and arrays is what I use a lot of because I come from a programming background, and I used a ton of functions and arrays in code.

    I would keep ATT and DEF as instance variables since you're likely going to have different ATT/DEF for every player/enemy.

    Having the abilities in an array is better because that way you can give the same ability to multiple people and reference it. (And it packages the ability's variables together quite nicely.)

    I'm glad my post was helpful.

  • Thanks, Robsta, another thing I wanted to know is if put this damage function in every event sheet of every level, or if there is a way to make a global event sheet? I notice that a level can only refer to a single event sheet, but maybe my limited knowledge is causing me to focus to much on that property in the menu.

  • Thanks, Robsta, another thing I wanted to know is if put this damage function in every event sheet of every level, or if there is a way to make a global event sheet? I notice that a level can only refer to a single event sheet, but maybe my limited knowledge is causing me to focus to much on that property in the menu.

    you can include event sheets in other event sheet (right click: include event sheet), and you can assign the same main event sheet to multiple layouts (through the layout proprieties)

  • Thanks, Aphrodite!

  • Almost forgot to mention, will I need more than the free version to do some of these things? I heard families group objects into a single group for easier referencing and what not.

    When I'm trying to set up the collision of the attack, it only allows me to choose 1 object. Which means I would have to copy and pasted a "Slash" Attack for every enemy in the game, even if a universal function is called to calculate the damage, I was hoping to make the attack overlapping have universal targetting so I wouldn't have to recopy and paste for everything. Anyway, thanks in advance for the info.

  • As someone who has not yet had the cash to get the license, I will tell you, you want the license.

    Don't get me wrong, free version is pretty incredible, but you're gonna want those limits removed.

    Also, there is certainly a way to set your slash attack up in such a way that doesn't require copy/pasting.

    Probably with a function that picks the object UID to decide how much/where the damage goes.

    There is (almost?) ALWAYS a better way than copy/pasting.

  • How do I make it select UID? It only gives me the option of selecting the enemy itself, instead of all enemies in general, which I heard the family feature does.

    Right now I'm trying to figure out what expressions are possible, like how all the variables of an object display when you pick an instance variable action. I'm to make that equation in a response post from above as I write this. {I was still trying to implement the character select screen at the time I posted the OP for when I got there.}

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • search the tutorials/manual/forums for "pick" and "UID" and "instance variables" and such. I'm not exactly sure if that's even what you're needing. You may very well be wanting families.

  • When I finally got to the attack last night, I was outstanded that the formula worked. Seeing the Users Attack multiplied by the techniques intensity, divided by the enemies defense, and turned into HP damage, it was sweet. : D Then the most miraculously thing happened, the next event I put it, to eliminate the HP indicator along with the enemy, I got the announcement "You've reached 100 events, buy the program". It was quite funny. = 3 Anyway, is it bad that I'm already at 100 events?

  • Well, as the asteroids example shows, you can do a lot in 100 events if you use them well, but number of events doesn't necessarily mean efficiency.

    I've written quite a few games that use over 100 events, because they're more complicated then asteroids.

  • Does the number of events affect how fast the game runs in html? I'll be posting the playable portion of the game soon or at least a video.

  • I don't believe just having more events affects the performance, it's going to depend on what exactly these events are doing..

    I was just reading here: which says, basically, that logic (more events) has hardly any affect on performance after rendering is taken into account.

    EDIT: oh.. I can't post links yet, heh.. it was a blog post called "optimisation: don't waste your time"

    I found a link to it from the performance tips section of the manual.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Topic
23 3,416
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
27 1,538
Azu's avatar
Azu
Unread hot topic
0 Favourites
[Effect] VHS Damage
27 13,352
InvaderXYZ's avatar
InvaderXYZ