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.

Somewhat of a tag-switch system for battles.

Sorry. I know the title's a bit vague. I wasn't sure how I could accurately summarize it in a title.

Anyways, what I'm wanting is a script that pairs together each actor with another specified actor. Like a buddy system. Then when a specific skill is used, the two switch places with each other. In other words, when a character uses the specified skill, he is removed from the party and the partner assigned to him is placed into the same slot. Basically like tag-team.

I don't care whether it only uses one skill to do the switching or has a unique one for each pair of actors, whichever would be easier for you to script. Just as long as it works both from the menu and in battles, and it keeps the party in order (the new member should be put in wherever it's partner previously was instead of at the end of the list).

Lastly, I'd appreciate it if you commented on it or gave me specific instructions on how to manipulate it since I know absolutely nothing about scripting.

Thanks for looking. I'll make sure to credit whoever can do this.
 
Before I can help (actually I'm working on it, but I can't continue because of this), do you use big party system (i.e. your party member can go more than 4 actors)? If yes, which one?

I managed to make one, assuming you don't use any big party script, but now there is a glitch when used in menu. Let's say Arshes is swapped with Basil: Arshes' skill will be still in screen and usable. Should I make it so the game immediately shows Basil skills? Just to make sure...
(And FYI, swapping in battle means the new party member will lose his/her turn.)
 
No. I just have 4 members.

And yes I'm fine with swapped characters losing a turn.
And don't worry about the menu glitch for now.
EDIT: Actually, could you make it return to the main menu after the skill is used? If you'd rather not, then don't worry about it.
 
Okay then, but there's something bugging me now (silly me ^_^;).

Let's say our party consists of Arshes, Basil, Gloria, and Dorothy. Arshes' buddy is Felix. Does Felix need to ever join the party before Arshes can swap? It would not make sense if Felix never joined but Arshes can swap with him (except, well, of course, you plotted it that way).

(As for the script I'm making now, when Felix joins the party, he will be counted toward 4 party limit, so Felix cannot be controlled nor gain any EXP until Arshes swaps with him. The active party member will be still Arshes, Basil, Gloria, and Dorothy.)

Don't worry, the menu glitch is gone by now, and it will be very easy to go back to main menu after the skill is used. By the way, I use only one skill, self-targeting.
 
What I'm going to use this for is more like transformation than swapping. Some of my characters will have a human and dragon form (or in the case of one character, a demon form), both of which level up seperately and have different stats and skills, and thus are treated like separate characters.

So no, the swap should not require the partners to be in the party already. And no character will ever be in the party at the same time as its partner.
 
May I ask what you're refining?

Don't worry about the conditions in which switching is possible. If it's controlled by a skill, then all I need to do is use events to add/remove it whenever I need to, right?

Thanks a lot.
 
Well, basically the party system; I used my assumption before, so I need to refine so buddies no longer have to join party (act as reserved actors instead).

And one more thing, can swapped actor be swapped back with his buddy? For example, after Arshes is swapped with Felix, can Felix use the same skill to swap back with Arshes? Again, I will assume this would happen, so if it doesn't match your need, just tell me.

Yes, you only need to add/remove the skill as desired.
 
It's done, but I forgot to ask you one thing:

Can swapping be done if:
1. Actor is dead?
2. Buddy is dead?

For now, the script doesn't check those conditions. And may I know the battle system you're using?
 
No. But if the actor is dead, then wouldn't that mean that swapping wouldn't be possible anyways since the actor has to use a skill to activate it?
If yes, then leave it how it is.

And I'm currently using the default battle system.
 
OK. Just in case when buddy is dead, player may be given a chance to swap back to actor (but it wouldn't possible either when buddy is dead, silly me...).

Here it is:
Code:
# SETTINGS BEGIN
# Skill ID to perform swap
TAG_SKILL_ID = 1
# Define buddy for each actor
# in format:
#
# actor_id => buddy_actor_id
#
# You don't need to define for all actors, just those who have one.
# You also don't need to define closed loops as exampled below:
# 1 => 7,
# 7 => 1
# as 1 will exclusively swapped with 7 and vice versa.
#
# MAKE SURE an actor has exclusively only one buddy
# so DON'T do this:
# 1 => 5,
# 2 => 6,
# 7 => 1 --> invalid, 1's buddy is 5
# When 5 and 7 is in party, 7 can swap with 1,
# so 1 can join party along with 5!!!
# Also, 5 can no longer be swapped with 1 if they're in one party.
ACTOR_TAG =
{
1 => 5,
2 => 6,
}
# SETTINGS END

class Game_Party
  attr_accessor :reserved_actors
  
  alias tag_initialize initialize
  def initialize
    tag_initialize
    @reserved_actors = []
  end
  
  def tag_change(actor, skill_cost)
    # Buddy will be defined by this point...
    buddy = actor.buddy
    # Find the position of current actor
    for i in 0 ... @actors.size
      current_actor = @actors[i]
      if current_actor.id == actor.id
        actor_index = i
        break
      end
    end
    # Now swap actor with buddy
    temp_actor = @actors[actor_index]
    @actors[actor_index] = buddy
    # Delete buddy from reserved actors list
    @reserved_actors.delete(buddy)
    # Add current actor to reserved actors list
    @reserved_actors.push(temp_actor)
    # calling from menu?
    if $scene.is_a?(Scene_Skill)
      $scene = Scene_Menu.new(1)
    end
    # Refresh player
    $game_player.refresh
  end
end

class Game_Battler
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #     user  : the one using skills (battler)
  #     skill : skill
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    # Clear critical flag
    self.critical = false
    # If skill scope is for ally with 1 or more HP, and your own HP = 0,
    # or skill scope is for ally with 0, and your own HP = 1 or more
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
       ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= skill.common_event_id > 0
    # First hit detection
    hit = skill.hit
    if skill.atk_f > 0
      hit *= user.hit / 100
    end
    hit_result = (rand(100) < hit)
    # Set effective flag if skill is uncertain
    effective |= hit < 100
    # If hit occurs
    if hit_result == true
      # Calculate power
      power = skill.power + user.atk * skill.atk_f / 100
      if power > 0
        power -= self.pdef * skill.pdef_f / 200
        power -= self.mdef * skill.mdef_f / 200
        power = [power, 0].max
      end
      # Calculate rate
      rate = 20
      rate += (user.str * skill.str_f / 100)
      rate += (user.dex * skill.dex_f / 100)
      rate += (user.agi * skill.agi_f / 100)
      rate += (user.int * skill.int_f / 100)
      # Calculate basic damage
      self.damage = power * rate / 20
      # Element correction
      self.damage *= elements_correct(skill.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if skill.variance > 0 and self.damage.abs > 0
        amp = [self.damage.abs * skill.variance / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / user.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
      # Set effective flag if skill is uncertain
      effective |= hit < 100
    end
    # If hit occurs
    if hit_result == true
      # If physical attack has power other than 0
      if skill.power != 0 and skill.atk_f > 0
        # State Removed by Shock
        remove_states_shock
        # Set to effective flag
        effective = true
      end
      # Tag skill performed?
      if skill.id == TAG_SKILL_ID
        self.damage = 0
        $game_party.tag_change(user, skill.sp_cost)
      else
        # Substract damage from HP
        last_hp = self.hp
        self.hp -= self.damage
      end
      effective |= self.hp != last_hp
      # State change
      @state_changed = false
      effective |= states_plus(skill.plus_state_set)
      effective |= states_minus(skill.minus_state_set)
      # If power is 0
      if skill.power == 0
        # Set damage to an empty string
        self.damage = ""
        # If state is unchanged
        unless @state_changed
          # Set damage to "Miss"
          self.damage = "Miss"
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return effective
  end
end

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    if not skill_learn?(skill_id)
      return false
    elsif skill_id == TAG_SKILL_ID
      if buddy == nil
        return false
      else
        # There is any chance that buddy is in party
        # Can't use skill if buddy is already in party
        for i in 0 ... $game_party.actors.size
          if $game_party.actors[i].id == buddy.id
            return false
          end
        end
        # Buddy not found, continue
      end
    end
    return super
  end
  # Return buddy
  def buddy
    # Has buddy?
    if ACTOR_TAG.include?(id)
      buddy_id = ACTOR_TAG[id]
    elsif ACTOR_TAG.has_value?(id)
      buddy_id = ACTOR_TAG.index(id)
    else
      return nil
    end
    # Find buddy position
    for i in 0 ... $game_party.reserved_actors.size
      if $game_party.reserved_actors[i].id == buddy_id
        return $game_party.reserved_actors[i]
      end
    end # end for
    # Not found, initialize a new one
    return Game_Actor.new(buddy_id)
  end
end

If something doesn't work, tell me and I'll fix it.
 
O_o Really weird (but only minor) bug.

The very first time (per new game) I use the skill, it doesn't show the animation. But after that it works fine.

I haven't tried it yet, but I think this bug would be easy to get around by forcing the action shortly after acquiring the skill and manually animating it just that one time. So unless I prove myself wrong (which I doubt I will), don't worry about it unless you want to.

Thanks again! :thumb:
 

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