Conditional eval for Game_Troop member

Discussion in 'RGSSx Script Support' started by Hero_Claive, Jun 3, 2018.

  1. Hero_Claive

    Hero_Claive (Phoenix Ember) Veteran

    Messages:
    149
    Likes Received:
    81
    First Language:
    English
    Primarily Uses:
    RMVXA
    I've been trying to figure this out for the better part of the last two hours, so I'm throwing in the towel and coming here.

    Basically, I'm trying to write a snippet where an actor becomes affected by x state while an enemy is present. The first part of placing the conditional eval is easy since I'm just using Victor's Conditional States script which allows for evals at certain intervals to check whether a state should be applied or not.

    The difficult part is that I can't seem to figure out how to search Game_Troop.members for specific enemy ids. In the setup method:

    Code:
      def setup(troop_id)
        clear
        @troop_id = troop_id
        @enemies = []
        troop.members.each do |member|
          next unless $data_enemies[member.enemy_id]
          enemy = Game_Enemy.new(@enemies.size, member.enemy_id)
          enemy.hide if member.hidden
          enemy.screen_x = member.x
          enemy.screen_y = member.y
          @enemies.push(enemy)
        end
        init_screen_tone
        make_unique_names
      end
    ...It's pretty clear that each value is stored inside an array, @enemies, where each array within the array contains two values, the enemy index and the enemy id. I just don't know how to access the second one though (the index is irrelevant). It would be awesome to get an answer to my title question, but it would also be great to let me know how to access specific variables in an array like this one. Thanks!
     
    #1
    Sauteed_Onion likes this.
  2. A-Moonless-Night

    A-Moonless-Night WINTER IS COMING Veteran

    Messages:
    476
    Likes Received:
    341
    Location:
    New Zealand
    First Language:
    English
    Primarily Uses:
    RMVXA
    You can use:
    Code:
    $data_enemies[ID]
     
    #2
    Sauteed_Onion likes this.
  3. DrDhoom

    DrDhoom Monkey Needs a Hug Veteran

    Messages:
    152
    Likes Received:
    146
    Location:
    South Borneo
    First Language:
    Indonesian
    Primarily Uses:
    N/A
    This will return true if there is any enemy with the ID of ENEMYID and that enemy is appeared and still alive.
    Code:
    $game_troop.members.any? { |enemy| enemy.enemy_id == ENEMYID && enemy.alive? }
     
    #3
  4. Hero_Claive

    Hero_Claive (Phoenix Ember) Veteran

    Messages:
    149
    Likes Received:
    81
    First Language:
    English
    Primarily Uses:
    RMVXA
    Awesome, this works perfectly! Thank you!
     
    #4

Share This Page