Help - Search - Members - Calendar
Full Version: [RESOLVED] Yerd_TargetEffects support please!
RPG RPG Revolution Forums > Scripting > Script Development and Support
Guyver's Bane
It's been awhile since i posted a new topic and it figures it would be for support lol. Well here's my problem:

This following script piece is a custom targeting choice i was given support on (i cant remember who from )and what it does is target enemies of the same id only. What i'm wondering is if theres a way to make target two random enemies of the same id?
Thanks to anyone who helps me out and credit will be given!

CODE
when 3 # target a group
      return if @target_index == -1 # target index not valid
      ptarg = opponents_unit.members[@target_index] # get potential target
      return if ptarg.nil? # potential target is out of range (should not happen)
      type = opponents_unit.existing_members.find{|member| member.is_a?(Game_Enemy) ? member.enemy_id == ptarg.enemy_id : member == ptarg }
      # find first living battler of the selected type
      type ||= opponents_unit.smooth_target(@target_index)
      # if the type was not found, get another group      
      if type.is_a?(Game_Enemy) # if enemy
        opponents_unit.existing_members.each {|enemy|
        selected.push(enemy) if enemy.enemy_id == type.enemy_id target# target all enemies of this id
        }
      elsif type.is_a?(Game_Actor) # if actor
        selected.push(type) # target 'this actor' only
      end
      # if type points to nil, no targets are added
Guyver's Bane
*BUMP* Lol.
Guyver's Bane
*BUMP*
Guyver's Bane
*BUMP*
Guyver's Bane
*BUMP*
Night_Runner
From what I understand of the code it should automatically select all enemies of the correct ID.
So I'm guessing that this request is to limit it, so the script only targets 2 enemies of the correct ID (selected at random), not all of them?

Fingers crossed, something like this should work for you:
CODE
when 3 # target a group
      return if @target_index == -1 # target index not valid
      ptarg = opponents_unit.members[@target_index] # get potential target
      return if ptarg.nil? # potential target is out of range (should not happen)
      type =
        opponents_unit.existing_members.find { |member|
          if member.is_a?(Game_Enemy) ? member.enemy_id == ptarg.enemy_id : member == ptarg
        }
      # find first living battler of the selected type
      type ||= opponents_unit.smooth_target(@target_index)
      # if the type was not found, get another group      
      if type.is_a?(Game_Enemy) # if enemy
        possible_enemies = []
        opponents_unit.existing_members.each {|enemy|
          possible_enemies.push(enemy) if enemy.enemy_id == type.enemy_id target# target all enemies of this id
        }
        selected.push( possible_enemies.map { |each| [each, Random.rand(100)] }.sort { |a,b|­ a[1]<=>b[1] }[0..1].map { |each| each[0] } )
      elsif type.is_a?(Game_Actor) # if actor
        selected.push(type) # target 'this actor' only
      end
      # if type points to nil, no targets are added

Otherwise I would have to ask for a demo, so I could properly debug it, without having to waste your time sending it to you to test each attempt.
Guyver's Bane
Thanks for taking this up man! I tried the code you gave and it gives me a syntax error on line 117. I'm including a demo with the script like you suggested. Any help is greatly appreciated.

Click to view attachment
Night_Runner
I forgot I edited that line, I didn't need to touch it though.

The real edits come later, in your original post you had;
CODE
      if type.is_a?(Game_Enemy) # if enemy
        opponents_unit.existing_members.each {|enemy|
        selected.push(enemy) if enemy.enemy_id == type.enemy_id target# target all enemies of this id
        }

There is a problem with the end of that line, how it has target after a whitepace, I don't believe that it should work like that.
Instead of directly pushing the onto the selected I've made a temporary array, p_enemies, and pushed the enemy, using the same code, onto p_enemies instead of selected. If you could find the original code and make that change (see the code above vs the code below, i've swapped selected for p_enemies) that would be great.
And I've inserted a fancy line at the end that limits it to 2 randomly selected enemies, which can be copied and pasted.
CODE
      if type.is_a?(Game_Enemy) # if enemy
        p_enemies = []
        opponents_unit.existing_members.each {|enemy|
        p_enemies.push(enemy) if enemy.enemy_id == type.enemy_id target# target all enemies of this id
        }
        selected.push( p_enemies.map { |each| [each, Random.rand(100)] }.sort { |a,b|­ a[1]<=>b[1] }[0..1].map { |each| each[0] } )
Guyver's Bane
Okay i made the changes and its still giving a syntax error when the code reaches this " } " character under this code:

CODE
if member.is_a?(Game_Enemy) ? member.enemy_id == ptarg.enemy_id : member == ptarg

Guyver's Bane
This topic has been resolved so would a mod please close it smile.gif

Night_Runner - Topic Closed
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.