Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Event Dissapearing

For my ABS I am using the following small script to delete dead enemies,
however, whenever I kill the first enemies, all other enemies die after one hit.
Can anyone help me with this?

Code:
     if Input.trigger?(Input::C)
        hero_attack
        enemy_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        enemy_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        for event in $game_map.events.values
          if event.x == enemy_x and event.y == enemy_y
            target = $game_troop.smooth_target_enemy(event.id - 1)
            troop = $data_troops[$game_temp.battle_troop_id]
            @enemy_id = troop.members[event.id - 1].enemy_id
            enemy = $game_troop.enemies[@enemy_id]
            if enemy.hp == 0
              $game_map.events[event.id].erase
            else
              target.attack_effect($game_actors[0])
            end
          end
        end
      end
Thanks in advanced!
 
You can use a break function, to end your loop, as you won't have more than 1 event on the same spot (I think).

Code:
     if Input.trigger?(Input::C)
        hero_attack
        enemy_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        enemy_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        for event in $game_map.events.values
          if event.x == enemy_x and event.y == enemy_y
            target = $game_troop.smooth_target_enemy(event.id - 1)
            troop = $data_troops[$game_temp.battle_troop_id]
            @enemy_id = troop.members[event.id - 1].enemy_id
            enemy = $game_troop.enemies[@enemy_id]
            if enemy.hp == 0
              $game_map.events[event.id].erase
            else
              target.attack_effect($game_actors[0])
            end
            break
          end
        end
      end

You can try that. (I don't have time to fully study the code, but should work).
 
: ) I have no idea what in the H**l you are talking about...
Im really not the best scripter in the world, however me and a couple of my friends are making a game and I am the only one who knows anything about scripting...
I think i just though of a way to do this, but if you think you know a more simple way, mind letting me in on the secret?!? : )

Edit: Would it be more helpful if I sent you my project so you could see everything???
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top