Charge Turn Battle (CTB) System (Final Fantasy X / Tactics style)

Hello ! your script it's working like a charm, i am really happy with this combat sytsem, is there a way to make it compatible with this script ? https://forum.chaos-project.com/index.php/topic,12640.0.html
I took a look at that script, and I think I can make a patch to make them compatible (if XP was more like Ace, they probably would've been compatible out of the box). If I have time this weekend, I'll make it and let you know.


i watched the video, and it look like the Persona 3/4/5 turn battle mechanic.
you know where in Persona 3/4/5 when its your turn, you take an action IMMEDIATELY.
and after you took an action, the next battler does an action when its their turn.
and when a battler has the highest Agility Stat (A.K.A. Speed Stat)
that certain battler goes first at Turn 0/1.
I've never played the Persona games so I'll have to take your word for it lol 😀🤣
@MobiusXVI
its ok, its just that in the Persona 3/4/5 Turn Battle Mechanic
where you strike an enemy's weakness (or land a critical hit),
they get knocked down (not dead) and you get a "1 More",
but you can't get that "1 More" again
when the enemy is ALREADY knocked down.
(and also the same "1 More" mechanic applies to the enemies as well.)
@Fred_than_dead I think this will work for you. I haven't tested it though so let me know if you encounter any bugs.
Spoiler
Ruby:
#===============================================================================
# Mobius' Charge Turn Battle System + Target Anyone Scope PATCH
# Author: Mobius XVI (CTB) + KK20 (TAS)
# Version: 1.0
# Date: 14 NOV 2020
#===============================================================================
#
# Introduction:
#
#   This is a patch script to make KK20's TAS script compatible with Mobius's
#   CTB script.
#
# Instructions:
#
#  - Place this script below all the default scripts but above main.
#  - The order of scripts should be:
#   Default scripts
#   TAS
#   CTB
#   PATCH
#   Main
#
#  Credits/Thanks:
#    - Mobius XVI, author
#    - KK20, TAS script: https://forum.chaos-project.com/index.php/topic,12640.0.html
#
#  License
#    This script is licensed under the MIT license, so you can use it for
#    both commercial and non-commercial games.
#
#==============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : skill selection)
  #--------------------------------------------------------------------------
  def update_phase3_skill_select
    # Make skill window visible
    @skill_window.visible = true
    # Update skill window
    @skill_window.update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End skill selection
      end_skill_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the skill window
      @skill = @skill_window.skill
      # If it can't be used
      if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.skill_id = @skill.id
      # Make skill window invisible
      @skill_window.visible = false
            
            ### PATCHING IN ANY TARGET ###
            
            # If effect scope is single enemy or single ally and can target anyone
      if @skill.element_set.include?($data_system.elements.index(TARGET_ANYONE_TAG)) and
      (@skill.scope == 1 or @skill.scope == 3)
        # Define starting position of the arrow
        @orig_scope = @skill.scope
        @any_target = true
            end
            
            ### END PATCH ###
            
      # If effect scope is single enemy
      if @skill.scope == 1
        # Start enemy selection
        start_enemy_select
      # If effect scope is all enemy - Mobius
      elsif @skill.scope == 2
        # Start all enemy selection
        start_all_enemy_select
      # If effect scope is single ally
      elsif @skill.scope == 3 or @skill.scope == 5
        # Start actor selection
        start_actor_select
      # If effect scope is all ally - Mobius
      elsif @skill.scope == 4 or @skill.scope == 6
        # Start all actor selection
        start_all_actor_select
      # If effect scope is not single
      else
        # End skill selection
        end_skill_select
        # Go to command input for next actor
        start_phase4
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : item selection)
  #--------------------------------------------------------------------------
  def update_phase3_item_select
    # Make item window visible
    @item_window.visible = true
    # Update item window
    @item_window.update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End item selection
      end_item_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @item_window.item
      # If it can't be used
      unless $game_party.item_can_use?(@item.id)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.item_id = @item.id
      # Make item window invisible
      @item_window.visible = false
            
            ### PATCHING IN ANY TARGET ###
            
            # If effect scope is single enemy or single ally and can target anyone
      if @item.element_set.include?($data_system.elements.index(TARGET_ANYONE_TAG)) and
      (@item.scope == 1 or @item.scope == 3)
        # Define starting position of the arrow
        @orig_scope = @item.scope
        @any_target = true
            end
            
            ### END PATCH ###
            
      # If effect scope is single enemy
      if @item.scope == 1
        # Start enemy selection
        start_enemy_select
      # If effect scope is all enemy - Mobius
      elsif @item.scope == 2
        # Start all enemy selection
        start_all_enemy_select
      # If effect scope is single ally
      elsif @item.scope == 3 or @item.scope == 5
        # Start actor selection
        start_actor_select
      # If effect scope is all ally - Mobius
      elsif @item.scope == 4 or @item.scope == 6
        # Start all actor selection
        start_all_actor_select
      # If effect scope is not single
      else
        # End item selection
        end_item_select
        # Go to command input for next actor
        start_phase4
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : enemy selection)
  #--------------------------------------------------------------------------
  def update_phase3_enemy_select
    # Update enemy arrow
    @enemy_arrow.update
        # If Beastiary is added
        if Mobius::Charge_Turn_Battle::BEASTIARY
            # If Beastiary access button is pressed
            if Input.trigger?(Input::BEASTIARY_BATTLE_ACCESS_BUTTON)
                # Set enemy
                enemy = @enemy_arrow.enemy
                # If enemy has been scanned -- Mobius added
                if enemy.state?(Mobius::Charge_Turn_Battle::SCAN_STATE_ID)
                # Play decision SE
                $game_system.se_play($data_system.decision_se)
                # Start turn order window
                start_enemy_detail_window(enemy)
                return
                else
                # Play buzzer SE
                $game_system.se_play($data_system.buzzer_se)
                end
            end
        end
    # If this skill/item can target anyone
    if @any_target == true
      # If player pressed the key to change targets
      if Input.trigger?(Input::DOWN)
        # Play decision SE
        $game_system.se_play($data_system.cursor_se)
        # Initialize actor select, end enemy select
        end_enemy_select
        start_actor_select
        @active_battler.changed_scope = !@active_battler.changed_scope
        # Stop processing
        return
      end
    end
        # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End enemy selection
      end_enemy_select
            @active_battler.changed_scope = false     
      @any_target = false
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.target_index = @enemy_arrow.index
      # End enemy selection
      end_enemy_select
      # If skill window is showing
      if @skill_window != nil
        # End skill selection
        end_skill_select
      end
      # If item window is showing
      if @item_window != nil
        # End item selection
        end_item_select
      end
      # Go to command input for next actor
      start_phase4
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : actor selection)
  #--------------------------------------------------------------------------
  def update_phase3_actor_select
    # Update actor arrow
    @actor_arrow.update
        # If this skill/item can target anyone
    if @any_target == true
      # If player pressed the key to change targets
      if Input.trigger?(Input::UP)
        # Play decision SE
        $game_system.se_play($data_system.cursor_se)
        # Initialize actor select, end enemy select
        end_actor_select
        start_enemy_select
        @active_battler.changed_scope = !@active_battler.changed_scope
        # Stop processing
        return
      end
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End actor selection
      end_actor_select
            @active_battler.changed_scope = false     
      @any_target = false
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.target_index = @actor_arrow.index
      # End actor selection
      end_actor_select
      # If skill window is showing
      if @skill_window != nil
        # End skill selection
        end_skill_select
      end
      # If item window is showing
      if @item_window != nil
        # End item selection
        end_item_select
      end
      # Go to command input for next actor
      start_phase4
    end
  end
 
end
@MobiusXVI I tested it out a bit and it seems to work perfectly, thank you so mutch dude !
Hello! I've just seen this. First of all I want to thank you, it works brilliantly.

I'm trying to make a few adjustments to a game using this battle system and I have a quick question.

Is there a more optimal way of using the SKILL_SPEED_FACTORS (or any of the specific ones) when I have multiple SKILLS that have the same CT? I was thinking of something like {[1,2,3] => 10} instead of setting it individually like {1 => 10, 2 => 10, 3 => 10}.

Thanks again!
Is there a more optimal way of using the SKILL_SPEED_FACTORS (or any of the specific ones) when I have multiple SKILLS that have the same CT? I was thinking of something like {[1,2,3] => 10} instead of setting it individually like {1 => 10, 2 => 10, 3 => 10}.

Yea, since this is ultimately just more Ruby code we can use a little bit of coding to do something like that. So for your example, you could do:
Spoiler
Ruby:
# SKILL_SPEED_FACTORS is identical in set up to WEAPON_SPEED_FACTORS but for skills.
SKILL_SPEED_FACTORS = {}
SKILL_SPEED_FACTORS.default = 0
# New section to add multiple skills at once
for skill_id in [1,2,3] # Here you can put all the skill IDs that have the same speed
    SKILL_SPEED_FACTORS[skill_id] = 10 # Here you can put what that same speed is
end
That's a good workaround, works perfectly. Thanks!
Honestly, this is why I do case statements for my configurations, especially when it comes to numbers.
Code:
case skill_id
when 1 then 10
when 2,5,10 then 20
when 20..50 then 50
else
  30
end
Honestly, this is why I do case statements for my configurations, especially when it comes to numbers.

It's an interesting idea, but I tend to view my configs as data rather than code hence why I use a hash (which is used to store data) rather than a case statement (which is used for coding logic). I will say one advantage to the hash is that it's easier to manipulate at runtime, meaning that you could take in configs from an end-user via hash and do some post-processing on the entered values, which is something I've had to do before.
I'm not saying case statements work all the time; I'm just saying in this particular instance it works better. It's also easier for people who don't know a lick of programming to config because it reads in English.

Hashes are bulky and slow, which is why I tend to avoid their use whenever I can. You'll have to tell me when you had to do post-processing though--sounds extremely niche.
Well, you might be surprised by Ruby hashes. In general, their lookup times are actually quite a bit faster than arrays especially when you're doing lookups by the key (see: Hashes vs Array). Basically, they do a sort of internal indexing in order to speed up retrieval. This makes them slower to add new elements, so you wouldn't want to use them for anything where you're constantly adding and removing elements, but for mostly static retrieval they offer excellent performance.

As for the post-processing, it really wasn't that odd. For my quest journal script, I take in a large amount of text for the quests. Because the text isn't formatted to fit neatly within the display box, I do line length calculations in order to split the text into appropriate line lengths. It's a slow operation, so I only do it once (the first time the configs are loaded) and then store the result for later display, which makes it much faster to open and display the journal while the player is actually playing.
Can this do _______?​
A. Maybe! Leave a post on the forum, and I might just add the feature if it can't already do it.

So, first of all, thank you very much for this script and for still taking time to answer questions here.

I really like your script and I think it could be what I need for my project, but it would need a little customization. I was wondering if you could help me or, at least, point me in the right direction.

What I want to do is give the player the ability to set up the turn order of his party anyway they want before the battle. It doesnt matter speed or any other parameter. The player will have a screen where they could choose: "Now I want the Warrior first, then the Cleric, then the Thief and then the Mage".

The idea is to create some strategies and combos by setting up a right order of attack. For instance, lets say the party are in an area with a lot of monsters with Fire weakness, but they all use Reflect as default, so they have this Magic Shield that stop the Mage to cause Fire damage. So, the player could put the Warrior first, so he could use his skill Shield Breaker and clean the path to Mage use his Fireball.
A little later in the game, we change to fight some enemies with strong Magical Defense, but really weak Physical Defense. So the player change the party order to Cleric First (to buff Warrior's Attack), then Warrior with a Physical Area Attack, then Thief at Support with itens to recover MP, if needed.

Do you think your script could be tweaked to work like that? Thanks in advance!
What I want to do is give the player the ability to set up the turn order of his party anyway they want before the battle. It doesnt matter speed or any other parameter. The player will have a screen where they could choose: "Now I want the Warrior first, then the Cleric, then the Thief and then the Mage".

Do you think your script could be tweaked to work like that? Thanks in advance!
Hey, thanks for checking out my script! So the short answer is no, but I'll explain why. Being able to choose directly goes against the core design of the script. It's built around the idea that character builds matter, for example a character with high speed should always get to go first (often before enemies). Basically, it would require an overhaul of the core computations of the script plus it would require an additional screen to be created to allow the player to choose the order. That all being said, what you want isn't impossible; it's just not something I'm going to make a part of this script. However, my script can be freely changed so if you find someone willing to make the changes they can.

Alternatively, there are some things you could do to sort of get what you want without making any actual changes to the script. There's a lot of customization options, so you could set up special skills or weapons that allow the player (while they're in a battle) to adjust the turn order. For example, suppose you made a skill called 'fast skip'. You could set it up so that when an actor uses it they 'skip' their turn but then get another turn very quickly so that they could go after another party member. It's not exactly what you're trying to do, but it's an option for you.
Hey, thanks for checking out my script! So the short answer is no, but I'll explain why. Being able to choose directly goes against the core design of the script. It's built around the idea that character builds matter, for example a character with high speed should always get to go first (often before enemies). Basically, it would require an overhaul of the core computations of the script plus it would require an additional screen to be created to allow the player to choose the order. That all being said, what you want isn't impossible; it's just not something I'm going to make a part of this script. However, my script can be freely changed so if you find someone willing to make the changes they can.

Alternatively, there are some things you could do to sort of get what you want without making any actual changes to the script. There's a lot of customization options, so you could set up special skills or weapons that allow the player (while they're in a battle) to adjust the turn order. For example, suppose you made a skill called 'fast skip'. You could set it up so that when an actor uses it they 'skip' their turn but then get another turn very quickly so that they could go after another party member. It's not exactly what you're trying to do, but it's an option for you.

Thanks for the response, MobiusXVI. I'll test some options to see if I can make it work or if I need to change something via RGSS. Thanks again!
v1.5 Patch Notes
  • In battle beastiary window was re-worked
    • While the previous design was functional, I felt that it was clunky from a user perspective and was a bit of information overload. I decided to change it so that it provides more information "at a glance" and more ultimately useful information to the player. This comes at the cost of being less thorough but the player can always view full information outside of battle in the main beastiary.
    • Window no longer scrolls
    • Window displays all stats
    • Window displays the top 3 elements that the enemy is strong against
      • If two elements have the same rank, then the higher ID wins
    • Window displays the bottom 3 elements that the enemy is weak against
    • Window displays the top 3 states that the enemy is strong against
      • If two states have the same rank, then the higher rating wins
    • Window displays the bottom 3 states that the enemy is weak against
  • Main beastiary scene was re-worked
    • The previous design relied heavily on the in-battle display which meant it couldn't take advantage of the full screen space. This led to (among other problems) the sprites being limited to 200x200 pixels. Navigating the beastiary was also rather clunky as it involved switching inputs between two windows. The new displays simplifies input and makes more use of the available screen space.
  • You can customize whether the beastiary exits to the menu or map
  • You can adjust the names of the beastiary's new pages
  • You can choose whether to display an ID for each enemy in the beastiary
  • You can hide enemies that should never show in the beastiary
    • All enemies start unknown until the party scans them but you might have enemies that you don't want to appear in the beastiary even if the party does scan them (or maybe they don't appear in game)
  • You can hide elements that shouldn't display in the beastiary
    • If you use elements for other purposes, then you can exclude them from showing
    • Or if you just don't want to tell players about certain element types
  • You can hide states that shouldn't display in the beastiary
    • If you use states for other purposes, then you can exclude them from showing
    • Or if you just don't want to tell players about certain states
  • You can add biographies for enemies
    • Details on how to are in the customization section
    • Biographies can be up to 7 lines where each line is approximately 40 characters long
i watched the video, and it look like the Persona 3/4/5 turn battle mechanic.
you know where in Persona 3/4/5 when its your turn, you take an action IMMEDIATELY.
and after you took an action, the next battler does an action when its their turn.
and when a battler has the highest Agility Stat (A.K.A. Speed Stat)
that certain battler goes first at Turn 0/1.
I don't know if you downloaded it, but is it possible to make the scripts work similarly to the Persona battle system?

Original thread: https://forums.rpgmakerweb.com/threads/charge-turn-battle-ctb-system-final-fantasy-x-tactics-style.37195/