[RESOLVED][RMXP] About use "last target" in Game_Troop

Started by finalholylight, June 15, 2013, 01:41:48 am

Previous topic - Next topic

finalholylight

June 15, 2013, 01:41:48 am Last Edit: June 21, 2013, 09:25:17 am by finalholylight
I try to edit def random_target_enemy in Game_Troop ,I want it will random enemies except last target enemy, I used battler.current_action.target_index to call "last target", then I used a condition to not add it into roulette index.
I test with a skill,I cast that skill to an enemy, then call common event force action cast other skill on random target, but sometime it still cast on previous enemy.

KK20

June 15, 2013, 02:44:35 am #1 Last Edit: June 15, 2013, 02:47:42 am by KK20
What exactly are you trying to do? The method "random_target_enemy" is only called when either
A.) The battler is applied with a state/status effect that makes it target randomly
B.) You are using the event call Force Action

If that's the case, you will need to add another parameter to the method that passes the current battler so that you have access to current_action.target_index. Then you will have to go into some of the default classes and make the changes to those method calls.

I'll look into it better later.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

finalholylight

June 15, 2013, 03:33:30 am #2 Last Edit: June 15, 2013, 03:35:32 am by finalholylight
I make a skill,troop have A, B and C ,first, I cast skill on A, then that skill will call common event Force Action (execute now) that cast other skill on random enemy except A, that other skill must cast on B or C.

Spoiler: ShowHide
  def random_target_enemy(hp0 = false)
   roulette = []
   lastenemy = @enemies[battler.current_action.target_index]
   for enemy in @enemies
     if (not hp0 and enemy.exist? and not lastenemy) or (hp0 and enemy.hp0?)
       roulette.push(enemy)
     end
   end
   if roulette.size == 0
     return nil
   end
   return roulette[rand(roulette.size)]
 end

Did I edit it right ? :-s

KK20

I can't guarantee anything, but try this out:
Spoiler: ShowHide

class Interpreter
  #--------------------------------------------------------------------------
  # * Force Action
  #--------------------------------------------------------------------------
  def command_339
    # Ignore if not in battle
    unless $game_temp.in_battle
      return true
    end
    # Ignore if number of turns = 0
    if $game_temp.battle_turn == 0
      return true
    end
    # Process with iterator (For convenience, this process won't be repeated)
    iterate_battler(@parameters[0], @parameters[1]) do |battler|
      # If battler exists
      if battler.exist?
        # Set action
        battler.current_action.kind = @parameters[2]
        if battler.current_action.kind == 0
          battler.current_action.basic = @parameters[3]
        else
          battler.current_action.skill_id = @parameters[3]
        end
        # Set action target
        if @parameters[4] == -2
          if battler.is_a?(Game_Enemy)
            battler.current_action.decide_last_target_for_enemy
          else
            battler.current_action.decide_last_target_for_actor
          end
        elsif @parameters[4] == -1
          if battler.is_a?(Game_Enemy)
            battler.current_action.decide_random_target_for_enemy
          else
            battler.current_action.decide_random_target_for_actor(battler)
          end
        elsif @parameters[4] >= 0
          battler.current_action.target_index = @parameters[4]
        end
        # Set force flag
        battler.current_action.forcing = true
        # If action is valid and [run now]
        if battler.current_action.valid? and @parameters[5] == 1
          # Set battler being forced into action
          $game_temp.forcing_battler = battler
          # Advance index
          @index += 1
          # End
          return false
        end
      end
    end
    # Continue
    return true
  end
end
class Game_BattleAction
  #--------------------------------------------------------------------------
  # * Random Target (for Actor)
  #--------------------------------------------------------------------------
  def decide_random_target_for_actor(active_battler = nil)
    # Diverge with effect scope
    if for_one_friend_hp0?
      battler = $game_party.random_target_actor_hp0
    elsif for_one_friend?
      battler = $game_party.random_target_actor
    else
      battler = $game_troop.random_target_enemy(false, active_battler)
    end
    # If a target exists, get an index, and if a target doesn't exist,
    # clear the action
    if battler != nil
      @target_index = battler.index
    else
      clear
    end
  end
end
class Game_Troop
  #--------------------------------------------------------------------------
  # * Random Selection of a Target Enemy
  #     hp0 : limited to enemies with 0 HP
  #--------------------------------------------------------------------------
  def random_target_enemy(hp0 = false, battler = nil)
    # Initialize roulette
    roulette = []
    # Loop
    for enemy in @enemies
      # If it fits the conditions
      if (not hp0 and enemy.exist?) or (hp0 and enemy.hp0?)
        if !battler.nil? and
        enemy == @enemies[battler.current_action.target_index]
          next
        end
        # Add an enemy to the roulette
        roulette.push(enemy)
      end
    end
    # If roulette size is 0
    if roulette.size == 0
      return nil
    end
    # Spin the roulette, choose an enemy
    return roulette[rand(roulette.size)]
  end
end

Placed between Scene_Debug and Main like usual.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

finalholylight

June 15, 2013, 04:46:42 am #4 Last Edit: June 15, 2013, 05:31:05 am by finalholylight
Hooo raaay, it works ! Thanks a lot  :)
Oops ! it works only once.
When I used that skill again, it did not call Force Action anymore.

KK20

How is the whole thing evented? Is it really as simple as assigning a skill with a common event and calling a Force Action in said common event? I didn't see any problems with that.

Also realized bug: You are aware that when you target an enemy that is no longer alive the game chooses another target for you? Let's assume there are enemies A, B, and C. Should you happen to use this skill of yours on enemy A who is dead, the game chooses B to attack. But the last target index still points to A. Thus, when your force action skill is called, it can still hit B again.

Today is massive cleaning and chore day in preparation for a Father's Day gathering, so I won't be available to help. :\

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

finalholylight

I test with two monsters, and they are still alive after end of skill, when I cast this skill again, Force Action don't work.
It should store new last target when I cast this skill and everything begin again.

KK20

It seems this requires new variables to pull off effectively--I'll check it out. Also not sure how the Force Skill isn't working for you a second time--works for me just fine. Did you test it in a new project?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

finalholylight

Oh no, I test again and realize that is my fault, I do wrong thing in common event, sorry for disturb you, thanks a lot for helping me :)