1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GML Damage system

Discussion in 'Programming' started by Mikael.K, Sep 19, 2018.

  1. Mikael.K

    Mikael.K Guest


    I'm coding a damage system. I want to have the object that does the damage to store the IDs of its "victims", and then check if it already dealt damage to the victim or not. This is so that the object only does damage to the same object once, but can still damage other objects until it is destroyed.

    Like a bullet that travels through many objects and stores the ID of the objects it impacts along it's path.

    I'm thinking something like this.

    Step Event.
    1. Check to see how many objects it's colliding with.
    2. Check to see if it has done damage to those objects already - if not, do damage to the objects not on the "victim list"
    3. Store the IDs of the objects it has done damage to on the "victim list"

    Is this good logic? How can i code this?
  2. Mikael.K

    Mikael.K Guest

  3. CloseRange

    CloseRange Member

    Jul 2, 2016
    create event
    hit[0] = false;
    with(obj_enemy) {
        other.hit[id] = false;
    step event
    with(obj_enemy) {
        if(other.hit[id]) continue;
        if(place_meeting(x, y, other) {
            // do damage
            other.hit[id] = true;
    I just wrote this real quick so might have an error.
    this is how I usually do this sort of damage system. Make an array of enemys and set them to false. every fame loop through the enemys; check if it's already been hit and if so skip it; if not then check if it's colliding and do the damage.

    If you have differant enemy objects like obj_enemyA and obj_enemyB ect then make a obj_enemy_parent and make all enemys parent it. Then you can just call that object instead.
  4. Fabseven

    Fabseven Member

    Oct 7, 2016

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice