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.

A little help I need

Ark

Member

Hya!


Okay. So I have a script which is working very good and very fast the only thing I have is a little problem, which - I think - is not that hard to do with some scripting knowledge.

Here is the script...

Code:
#============================================================
#------------------------------------------------------------------------------------------------------------------------
#   Battle ATB
#------------------------------------------------------------------------------------------------------------------------
#  By unknown
#------------------------------------------------------------------------------------------------------------------------
#============================================================

class Scene_Battle
DATA_SYSTEM_COMMAND_UP_SE = ""
CP_COST_BASIC_ACTIONS =     0 
CP_COST_SKILL_ACTION  = 65535 
CP_COST_ITEM_ACTION   = 65535
CP_COST_BASIC_ATTACK  = 65535
CP_COST_BASIC_GUARD   = 32768 
CP_COST_BASIC_NOTHING = 65535 
CP_COST_BASIC_ESCAPE  = 65535
end
class Scene_Battle_CP
BATTLE_SPEED = 0.85
START_CP_PERCENT = 100
end
#==============================================================================
class Scene_Battle_CP
#--------------------------------------------------------------------------
attr_accessor   :stop  
#----------------------------------------------------------------------------
def initialize
  @battlers = []
  @cancel = false
  @stop = false
  @agi_total = 0
  count_battlers = []
  for enemy in $game_troop.enemies
    count_battlers.push(enemy)
  end
  for actor in $game_party.actors
    count_battlers.push(actor)
  end
  for battler in count_battlers
    @agi_total += battler.agi
  end
  for battler in count_battlers
    battler.cp = [[65535 * START_CP_PERCENT * (rand(15) + 85) * 4 * battler.agi / @agi_total / 10000, 0].max, 65535].min
  end
end
#----------------------------------------------------------------------------
def update
  return if @stop
  for battler in $game_party.actors + $game_troop.enemies
    if battler.dead? == true
      battler.cp = 0
      next
    end
    battler.cp = [[battler.cp + BATTLE_SPEED * 4096 * battler.agi / @agi_total, 0].max, 65535].min
  end
end
#----------------------------------------------------------------------------
def stop
  @cancel = true
  if @cp_thread != nil then
    @cp_thread.join
    @cp_thread = nil
  end
end
end
#==============================================================================
class Game_Battler
attr_accessor :now_guarding 
attr_accessor :cp               
attr_accessor :slip_state_update_ban   
#--------------------------------------------------------------------------
alias xrxs_bp1_inputable? inputable?
def inputable?
  bool = xrxs_bp1_inputable?
  return (bool and (@cp >= 65535))
end
#--------------------------------------------------------------------------
alias xrxs_bp1_slip_damage? slip_damage?
def slip_damage?
  return false if @slip_state_update_ban
  return xrxs_bp1_slip_damage?
end
#--------------------------------------------------------------------------
alias xrxs_bp1_remove_states_auto remove_states_auto
def remove_states_auto
  return if @slip_state_update_ban
  xrxs_bp1_remove_states_auto
end
end
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
alias xrxs_bp1_setup setup
def setup(actor_id)
  xrxs_bp1_setup(actor_id)
  @hate = 100 
  @cp = 0
  @now_guarding = false
  @slip_state_update_ban = false
end
end
#==============================================================================
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
alias xrxs_bp1_initialize initialize
def initialize(troop_id, member_index)
  xrxs_bp1_initialize(troop_id, member_index)
  @hate = 100  # init-value is 100
  @cp = 0
  @now_guarding = false
  @slip_state_update_ban = false
end
end
#==============================================================================
class Window_BattleStatus < Window_Base
#--------------------------------------------------------------------------
attr_accessor   :update_cp_only 
#--------------------------------------------------------------------------
alias xrxs_bp1_initialize initialize
def initialize
  @update_cp_only = false
  xrxs_bp1_initialize
end
#--------------------------------------------------------------------------
alias xrxs_bp1_refresh refresh
def refresh
  unless @update_cp_only
    xrxs_bp1_refresh
  end
  for i in 0...$game_party.actors.size
    actor = $game_party.actors[i]
    actors_size = [$game_party.actors.size, 4].max
    max_width = [600 / (actors_size + 1), 80].max
    x_shift = max_width + (600 - max_width*actors_size)/(actors_size - 1)
    actor_x = i * x_shift + 4
    draw_actor_cp_meter(actor, actor_x, 96, max_width, 0)
  end
end
#--------------------------------------------------------------------------
def draw_actor_cp_meter(actor, x, y, width = 156, type = 0)
  self.contents.font.color = system_color
  self.contents.fill_rect(x-1, y+27, width+2,6, Color.new(0, 0, 0, 255))
  if actor.cp == nil
    actor.cp = 0
  end
  w = width * [actor.cp,65535].min / 65535
  self.contents.fill_rect(x, y+28, w,1, Color.new(255, 255, 128, 255))
  self.contents.fill_rect(x, y+29, w,1, Color.new(255, 255, 0, 255))
  self.contents.fill_rect(x, y+30, w,1, Color.new(192, 192, 0, 255))
  self.contents.fill_rect(x, y+31, w,1, Color.new(128, 128, 0, 255))
end
end
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
alias xrxs_bp1_update update
def update
  xrxs_bp1_update
  @cp_thread.update
end
#--------------------------------------------------------------------------
alias xrxs_bp1_battle_end battle_end
def battle_end(result)
  @cp_thread.stop
  xrxs_bp1_battle_end(result)
end
#--------------------------------------------------------------------------
alias xrxs_bp1_start_phase1 start_phase1
def start_phase1
  @agi_total = 0
  @cp_thread = Scene_Battle_CP.new
  s1 = $data_system.words.attack
  s2 = $data_system.words.skill
  s3 = $data_system.words.guard
  s4 = $data_system.words.item
  @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, "Escape"])
  @actor_command_window.y = 128
  @actor_command_window.back_opacity = 160
  @actor_command_window.active = false
  @actor_command_window.visible = false
  @actor_command_window.draw_item(4, $game_temp.battle_can_escape ? @actor_command_window.normal_color : @actor_command_window.disabled_color)
  xrxs_bp1_start_phase1
end
#--------------------------------------------------------------------------
alias xrxs_bp1_start_phase2 start_phase2
def start_phase2
  xrxs_bp1_start_phase2
  @party_command_window.active = false
  @party_command_window.visible = false
  start_phase3
end
#--------------------------------------------------------------------------
alias xrxs_bp1_phase3_setup_command_window phase3_setup_command_window
def phase3_setup_command_window
  @cp_thread.stop = true
  @active_battler.now_guarding = false
  Audio.se_play(DATA_SYSTEM_COMMAND_UP_SE) if DATA_SYSTEM_COMMAND_UP_SE != ""
  xrxs_bp1_phase3_setup_command_window
end
#--------------------------------------------------------------------------
alias xrxs_bsp1_update_phase3_basic_command update_phase3_basic_command
def update_phase3_basic_command
  if Input.trigger?(Input::C)
    case @actor_command_window.index
    when 4
      if $game_temp.battle_can_escape
        $game_system.se_play($data_system.decision_se)
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 4
        phase3_next_actor
      else
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end
  end
  xrxs_bsp1_update_phase3_basic_command
end
#--------------------------------------------------------------------------
alias xrxs_bp1_start_phase4 start_phase4
def start_phase4
  xrxs_bp1_start_phase4
  @cp_thread.stop = false
end
#--------------------------------------------------------------------------
alias xrxs_bp1_make_action_orders make_action_orders
def make_action_orders
  xrxs_bp1_make_action_orders
  exclude_battler = []
  for battler in @action_battlers
    if battler.cp < 65535
      exclude_battler.push(battler)
    end
  end
  @action_battlers -= exclude_battler
end
#--------------------------------------------------------------------------
alias xrxs_bp1_update_phase4_step1 update_phase4_step1
def update_phase4_step1
  @phase4_act_continuation = 0
  if judge
    @cp_thread.stop
    return
  end
  @active_battler = @action_battlers[0]
  @status_window.update_cp_only = true
  @active_battler.slip_state_update_ban = true if @active_battler != nil
  xrxs_bp1_update_phase4_step1
  if @phase4_step != 2
    @status_window.refresh
    Graphics.frame_reset
  end
  @status_window.update_cp_only = false
  @active_battler.slip_state_update_ban = false if @active_battler != nil
end
#--------------------------------------------------------------------------
alias xrxs_bp1_update_phase4_step2 update_phase4_step2
def update_phase4_step2
  unless @active_battler.current_action.forcing
    if @active_battler.restriction == 2 or @active_battler.restriction == 3
      @active_battler.current_action.kind = 0
      @active_battler.current_action.basic = 0
    end
    if @active_battler.restriction == 4
      $game_temp.forcing_battler = nil
      if @phase4_act_continuation == 0 and @active_battler.cp >= 65535
        @active_battler.remove_states_auto
        @active_battler.cp = [(@active_battler.cp - 65535),0].max
        @status_window.refresh
      end
      @phase4_step = 1
      return
    end
  end
  case @active_battler.current_action.kind
  when 0
    @active_battler.cp -= CP_COST_BASIC_ACTIONS if @phase4_act_continuation == 0
  when 1
    @active_battler.cp -= CP_COST_SKILL_ACTION if @phase4_act_continuation == 0
  when 2
    @active_battler.cp -= CP_COST_ITEM_ACTION if @phase4_act_continuation == 0
  end
  @cp_thread.stop = true
  @active_battler.remove_states_auto
  xrxs_bp1_update_phase4_step2
end
#--------------------------------------------------------------------------
alias xrxs_bp1_make_basic_action_result make_basic_action_result
def make_basic_action_result
  if @active_battler.current_action.basic == 0 and @phase4_act_continuation == 0
    @active_battler.cp -= CP_COST_BASIC_ATTACK
  end
  if @active_battler.current_action.basic == 1 and @phase4_act_continuation == 0
    @active_battler.cp -= CP_COST_BASIC_GUARD
  end
  if @active_battler.is_a?(Game_Enemy) and
     @active_battler.current_action.basic == 2 and @phase4_act_continuation == 0
    @active_battler.cp -= CP_COST_BASIC_ESCAPE
  end
  if @active_battler.current_action.basic == 3 and @phase4_act_continuation == 0
    @active_battler.cp -= CP_COST_BASIC_NOTHING
  end
  if @active_battler.current_action.basic == 4 and @phase4_act_continuation == 0
    @active_battler.cp -= CP_COST_BASIC_ESCAPE 
    if $game_temp.battle_can_escape == false
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    $game_system.se_play($data_system.decision_se)
    update_phase2_escape
    return
  end
  xrxs_bp1_make_basic_action_result
end
#--------------------------------------------------------------------------
alias xrxs_bp1_update_phase4_step3 update_phase4_step3
def update_phase4_step3
  xrxs_bp1_update_phase4_step3
end
#--------------------------------------------------------------------------
alias xrxs_bp1_update_phase4_step5 update_phase4_step5
def update_phase4_step5
  if @active_battler.hp > 0 and @active_battler.slip_damage?
    @active_battler.slip_damage_effect
    @active_battler.damage_pop = true
  end
  xrxs_bp1_update_phase4_step5
end
#--------------------------------------------------------------------------
def update_phase4_step7
  @cp_thread.stop = false
  @help_window.visible = false
end
end

What the script does...

It makes the basic battle system to be round based and based on actors agility. It also creates a bar to show when the player will be able to act.

I call it ATB bar.

So the problem is...

It works just fine if you have 4 players in party. (When the battle starts the bars are starting to fill and the most agile player (which is Basil if you are using the basic actors) can act first.

BUT

If you are alone you only have one player you can act in the start of the battle, and I think (not for sure) after you acted other actors (you are alone so I'm speaking about the monsters)can act too, even if their agility is much lower. After the second round of the battle it's working fine. But what about the first? The bar sucks because it's not filled in the start of the battle. You can act, and after that it changes its graphic to maximum fill, (no filling time) and you can act again, and only after that it gets to refill itself. OKay. It's working fine then, but only from the third round.

So I need someone who undertood that thing (because my english isn't that good), and want to help...

I need this script modified, so even if you are alone (i mean there is only one player in the party), it should start the battle by the bar filling up...

Please help. I have everything in my script base so I could start to create my game, the only thing I don't have is this.

PS.: Oh, and I do not use SDK...
 

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