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.

[SOLVED][XP] Help with Atoa's Caterpillar Script

Hey all,
I installed Atoa's translated Caterpillar script, and it's giving me a bunch of syntax errors...could someone take a look at this and try to help?

Original:
Code:
#=============================================================================

# Atoa Caterpillar

# Por Atoa

#==============================================================================

# Este script permite vizualizar os membros no mapa, eles irão seguir o herói

# Um pouco diferente dos outros caterpillar, neste os personagens

# Só se movimentam caso necessário (portanto eles não ficam igual "barata tonta"

# se você ficar indo e voltando.

#

# Ele também conta com corrida e movimento em diagonal (ambos podendo ser

# desativados caso não deseje estes efeitos).

#

# A corrida e movimento diagonal também conta com animação diferenciada para.

# Você precisará dos gráficos das animações diferenciadas:

# 1 - Grafico para corrida: um gráfico com o mesmo nome do grafico do charset + Run

# 2 - Grafico para movimento diagonal: um gráfico com o mesmo nome do grafico do charset + Diag

# 3 - Grafico para movimento diagonal com corrida: um gráfico com o mesmo nome do grafico do

# charset + DiagRun

#

# Se o gráfico não for encontrado, o gráfico normal será usado.

#

# Você pode controlar o movimento dos personagens da fila atravéz

# de comandos de evento, usando o comando chamar script.

#

# $game_player.caterpillar[0].x = posição X no mapa

# $game_player.caterpillar[0].y = posição Y no mapa

#

# Para juntar os personagens use o comando: $game_player.caterpillar_gather

#

# Lembre-se de não permitir movimento do personagem se o grupo estiver separado

# Portanto use o comando de reunir o após este tipo de eventos.

#

#==============================================================================

 

module Atoa

 

  # Numero máximos de personagens seguindo o herói na tela

  Max_Caterpillar_Actor = 3

 

  # ID do switch que esconde a vizualização dos personagens quando ativado

  Caterpillar_Hide_Switch = 1

 

  # Ocultar membros do grupo que estejam mortos

  Hide_Dead = false

 

  # Permitir alterar ordem do grupo apertando-se as teclas Q ou W?

  Allow_Reorder = true

   

  # Permitir movimento em diagonal?

  Diagonal_Movement = true

 

  # Ativar ajuste de velocidade quando se está andando em diagonal?

  Diagonal_Speed_Adjust = true

 

  # Distancia máxima entre os personagens do grupo (valor em pixel)

  # Deixe 0 para desativar

  Max_Distance = 0

 

  # ID da Switch que habilita a corrida, se esta switch estiver off

  # o personagem não conseguirá correr

  Run_Switch = 2

 

  # ID da Switch que habilita corrida sem a necessidade de se pressionar

  # uma tecla. Enquanto ela estiver ligada, o personagem irá sempre correr.

  Running_Switch = 3

 

  # Tecla que pressionada permite que o personagem corra.

  Run_Key = Input::C

  # Input::A >> Teclado:Z

  # Input::B >> Teclado:X

  # Input::C >> Teclado:C

  # Input::X >> Teclado:A

  # Input::Y >> Teclado:S

  # Input::Z >> Teclado:D

  # Input::L >> Teclado:Q

  # Input::R >> Teclado:W

end

 

#==============================================================================

# ■ Sprite_Character

#==============================================================================

class Sprite_Character

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_update update

  def update

    atoa_caterpillar_update

    if @character.is_a?(Game_Player) or @character.is_a?(Atoa_Catterpillar)

      a = ''

      a += 'Diag' if @character.diagonal

      a += 'Run' if @character.running

      begin

        self.bitmap = RPG::Cache.character(@character.character_name + a, @character.character_hue)

      rescue

        self.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue)

      end

      @cw = bitmap.width / 4

      @ch = bitmap.height / 4

      self.ox = @cw / 2

      self.oy = @ch

      sx = @character.pattern * @cw

      sy = (@character.direction - 2) / 2 * @ch

      self.src_rect.set(sx, sy, @cw, @ch)

    end

  end

end

 

#==============================================================================

# ■ Game_Character

#==============================================================================

class Game_Character

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  attr_accessor(:direction, :diagonal, :running)

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_initialize_gamechar initialize if !method_defined?(:atoa_caterpillar_initialize_gamechar)

  def initialize

    atoa_caterpillar_initialize_gamechar

    @diagonal = @running  = false

    @base_speed = @move_speed

  end

  #--------------------------------------------------------------------------

  alias move_type_custom_diagrun_gamechar move_type_custom

  def move_type_custom

    move_type_custom_diagrun_gamechar

    @base_speed = [[@move_speed, 1].max, 6].min

  end

end

 

#==============================================================================

# ■ Game_Player

#==============================================================================

class Game_Player < Game_Character

  #--------------------------------------------------------------------------

  attr_accessor(:caterpillar, :move_speed, :running, :alive_actors)

  #--------------------------------------------------------------------------

  def run_mode

    @running = true

    for cat in @caterpillar

      cat.running = true

    end

  end

  #--------------------------------------------------------------------------

  def walk_mode

    @running = false

    for cat in @caterpillar

      cat.running = false

    end

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_refresh refresh  if !method_defined?(:atoa_caterpillar_refresh)

  def refresh

    caterpillar_update

    atoa_caterpillar_refresh

  end

  #--------------------------------------------------------------------------

  def caterpillar_update

    if @caterpillar == nil

      @caterpillar = []

      for i in 1...(Max_Caterpillar_Actor + 1)

        @caterpillar << Atoa_Catterpillar.new(i)

      end

    end

    for cat in @caterpillar

      cat.refresh

    end

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_update update if !method_defined?(:atoa_caterpillar_update)

  def update

    for cat in @caterpillar

      cat.update

    end

    last_moving = moving?

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      input = Diagonal_Movement ? Input.dir8 : Input.dir4

      case input

      when 2

        move_down

      when 4

        move_left

      when 6

        move_right

      when 8

        move_up

      when 1

        move_lower_left

      when 3

        move_lower_right

      when 7

        move_upper_left

      when 9

        move_upper_right

      end

    end

    @move_speed = @base_speed

    @move_speed += 1 if @running and moving?

    @move_speed -= 1 if @diagonal and Diagonal_Speed_Adjust and not $game_system.map_interpreter.running?

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if last_moving

        result = check_event_trigger_here([1,2])

        if result == false

          unless $DEBUG and Input.press?(Input::CTRL)

            @encounter_count -= 1 if @encounter_count > 0

          end

        end

      end

      if Input.trigger?(Input::C)

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

  #--------------------------------------------------------------------------

  def turn_down

    unless @direction_fix

      @diagonal = false

      @direction = 2

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_left

    unless @direction_fix

      @diagonal = false

      @direction = 4

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_right

    unless @direction_fix

      @diagonal = false

      @direction = 6

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_up

    unless @direction_fix

      @diagonal = false

      @direction = 8

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_lower_left

    unless @direction_fix

      @diagonal = true

      @direction = 2

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_lower_right

    unless @direction_fix

      @diagonal = true

      @direction = 6

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_upper_left

    unless @direction_fix

      @diagonal = true

      @direction = 4

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_upper_right

    unless @direction_fix

      @diagonal = true

      @direction = 8

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_moveto moveto if !method_defined?(:atoa_caterpillar_moveto)

  def moveto(x, y)

    atoa_caterpillar_moveto(x, y)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    for i in [email=0...@caterpillar.size]0...@caterpillar.size[/email]

      @caterpillar[i].moveto(x, y)

    end

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_move_down move_down if !method_defined?(:atoa_caterpillar_move_down)

  def move_down

    passable = passable?(@x, @y, 2)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_down

    add_move_update('move_down') if passable

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_move_left move_left if !method_defined?(:atoa_caterpillar_move_left)

  def move_left

    passable = passable?(@x, @y, 4)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_left

    add_move_update('move_left') if passable

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_move_right move_right if !method_defined?(:atoa_caterpillar_move_right)

  def move_right

    passable = passable?(@x, @y, 6)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_right

    add_move_update('move_right') if passable

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_move_up move_up if !method_defined?(:atoa_caterpillar_move_up)

  def move_up

    passable = passable?(@x, @y, 8)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_up

    add_move_update('move_up') if passable

  end

  #--------------------------------------------------------------------------

  def move_lower_left(turn_enabled = true)

    passable = (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    if passable

      @x -= 1

      @y += 1

      increase_steps

    end

    turn_lower_left if turn_enabled

    add_move_update('move_lower_left') if passable

  end

  #--------------------------------------------------------------------------

  def move_lower_right(turn_enabled = true)

    passable = (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    if passable

      @x += 1

      @y += 1

      increase_steps

    end

    turn_lower_right if turn_enabled

    add_move_update('move_lower_right') if passable

  end

  #--------------------------------------------------------------------------

  def move_upper_left(turn_enabled = true)

    passable = (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    if passable

      @x -= 1

      @y -= 1

      increase_steps

    end

    turn_upper_left if turn_enabled

    add_move_update('move_upper_left') if passable

  end

  #--------------------------------------------------------------------------

  def move_upper_right(turn_enabled = true)

    passable = (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    if passable

      @x += 1

      @y -= 1

      increase_steps

    end

    turn_upper_right if turn_enabled

    add_move_update('move_upper_right') if passable

  end

  #--------------------------------------------------------------------------

  def caterpillar_gather

    for i in [email=0...@caterpillar.size]0...@caterpillar.size[/email]  

      @caterpillar[i].gather_party

    end

  end

  #--------------------------------------------------------------------------

  def add_move_update(move)

    if @caterpillar[0] != nil

      @caterpillar[0].move_update << move

    end

  end

  #--------------------------------------------------------------------------

  def set_alive_actors

    @alive_actors = []

    for actor in $game_party.actors

      @alive_actors << actor unless actor.dead?

    end

  end

end

 

#==============================================================================

# ■ Atoa_Catterpillar

#==============================================================================

class Atoa_Catterpillar < Game_Character

  #--------------------------------------------------------------------------

  attr_accessor(:move_update, :member, :next_x, :next_y, :x, :y, :move_speed, :running)

  #--------------------------------------------------------------------------

  def initialize(member)

    super()

    @move_update = []

    @member = member

    moveto($game_player.x, $game_player.y)

    @running = false

    @through = true

    refresh

    @next_x = @x

    @next_y = @y

  end

  #--------------------------------------------------------------------------

  def moveto(x, y)

    super(x, y)

    @move_update.clear

  end

  #--------------------------------------------------------------------------

  def refresh

    $game_player.set_alive_actors

    party = Hide_Dead ? $game_player.alive_actors.dup : $game_party.actors

    if party.size < @member

      @character_name = ""

      @character_hue = 0

      return

    end

    actor = party[@member]

    if actor == nil

      @character_name = ""

      @character_hue = 0

      return

    end

    @character_name = actor.character_name

    @character_hue = actor.character_hue

    @opacity = 255

    @blend_type = 0

  end

  #--------------------------------------------------------------------------

  def screen_z(height = 0)

    if $game_player.x == @x and $game_player.y == @y

      return $game_player.screen_z - 1

    end

    super(height)

  end

  #--------------------------------------------------------------------------

  def check_event_trigger_here(triggers)

    return false

  end

  #--------------------------------------------------------------------------

  def check_event_trigger_there(triggers)

    return false

  end

  #--------------------------------------------------------------------------

  def check_event_trigger_touch(x, y)

    return false

  end

  #--------------------------------------------------------------------------

  def update

    member = @member == 1 ? $game_player : $game_player.caterpillar[@member - 2]

    diff = (player_distance(member) >= (Max_Distance + 1)) ? 0 : 1

    @move_speed = [$game_player.move_speed.to_f - diff, 1].max

    move_player(member)

    super

    @transparent = $game_player.transparent

    @transparent = @transparent ? @transparent : $game_switches[Caterpillar_Hide_Switch]

  end

  #--------------------------------------------------------------------------

  def player_distance(member)

    dist_x = (member.screen_x - self.screen_x).abs

    dist_y = (member.screen_y - self.screen_y).abs

    return dist_x if dist_x >= dist_y

    return dist_y if dist_y >= dist_x

    return 0

  end

  #--------------------------------------------------------------------------

  def move_player(member)

    refresh

    @move_update.clear if member.x == @x and member.y == @y

    return if moving?

    return unless need_update(member)

    move = @move_update.shift

    eval(move) if move != nil

  end

  #--------------------------------------------------------------------------

  def need_update(member)

    return false if member.x == @x and member.y == @y

    return false if @move_update.empty?

    if @move_update[0] == 'move_left'

      return false if (member.x + 1 == @x and member.y == @y)

    elsif @move_update[0] == 'move_right'

      return false if (member.x - 1 == @x and member.y == @y)

    elsif @move_update[0] == 'move_up'

      return false if (member.y + 1 == @y and member.x == @x)

    elsif @move_update[0] == 'move_down'

      return false if (member.y - 1 == @y and member.x == @x)

    elsif @move_update[0] == 'move_upper_left'

      return false if (member.x + 1 == @x and member.y + 1 == @y)

    elsif @move_update[0] == 'move_upper_right'

      return false if (member.x - 1 == @x and member.y + 1 == @y)

   elsif @move_update[0] == 'move_lower_left'

      return false if (member.x + 1 == @x and member.y - 1 == @y)

    elsif @move_update[0] == 'move_lower_right'

      return false if (member.x - 1 == @x and member.y - 1 == @y)

    end

    return true

  end

  #--------------------------------------------------------------------------

  def add_move_update(move)

    member = $game_player.caterpillar[@member]

    if member != nil

      member.move_update << move

    end

  end

  #--------------------------------------------------------------------------

  def gather_party

    for i in 0...$game_party.actors.size

      move_toward_player

    end

    @x = $game_player.x

    @y = $game_player.y

    @move_update.clear

  end

  #--------------------------------------------------------------------------

  def turn_down

    unless @direction_fix

      @diagonal = false

      @direction = 2

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_left

    unless @direction_fix

      @diagonal = false

      @direction = 4

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_right

    unless @direction_fix

      @diagonal = false

      @direction = 6

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_up

    unless @direction_fix

      @diagonal = false

      @direction = 8

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_lower_left

    unless @direction_fix

      @diagonal = true

      @direction = 2

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_lower_right

    unless @direction_fix

      @diagonal = true

      @direction = 6

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_upper_left

    unless @direction_fix

      @diagonal = true

      @direction = 4

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def turn_upper_right

    unless @direction_fix

      @diagonal = true

      @direction = 8

      @stop_count = 0

    end

  end

  #--------------------------------------------------------------------------

  def move_down(turn_enabled = true)

    @y += 1 if passable?(@x, @y, 2)

    turn_down if turn_enabled

    add_move_update('move_down')

  end

  #--------------------------------------------------------------------------

  def move_left(turn_enabled = true)

    @x -= 1 if passable?(@x, @y, 4)

    turn_left  if turn_enabled

    add_move_update('move_left')

  end

  #--------------------------------------------------------------------------

  def move_right(turn_enabled = true)

    @x += 1 if passable?(@x, @y, 6)

    turn_right if turn_enabled

    add_move_update('move_right')

  end

  #--------------------------------------------------------------------------

  def move_up(turn_enabled = true)

    @y -= 1 if passable?(@x, @y, 8)

    turn_up if turn_enabled

    add_move_update('move_up')

  end

  #--------------------------------------------------------------------------

  def move_lower_left(turn_enabled = true)

    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or

       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))

      @x -= 1

      @y += 1

    end

    turn_lower_left if turn_enabled

    add_move_update('move_lower_left')

  end

  #--------------------------------------------------------------------------

  def move_lower_right(turn_enabled = true)

    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or

       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))

      @x += 1

      @y += 1

    end

    turn_lower_right if turn_enabled

    add_move_update('move_lower_right')

  end

  #--------------------------------------------------------------------------

  def move_upper_left(turn_enabled = true)

    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or

       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))

      @x -= 1

      @y -= 1

    end

    turn_upper_left if turn_enabled

    add_move_update('move_upper_left')

  end

  #--------------------------------------------------------------------------

  def move_upper_right(turn_enabled = true)

    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or

       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))

      @x += 1

      @y -= 1

    end

    turn_upper_right if turn_enabled

    add_move_update('move_upper_right')

  end

end

 

#==============================================================================

# ■ Spriteset_Map

#==============================================================================

class Spriteset_Map

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_initialize initialize if !method_defined?(:atoa_caterpillar_initialize)

  def initialize

    atoa_caterpillar_initialize

    for caterpillar in $game_player.caterpillar.reverse

      sprite = Sprite_Character.new(@viewport1, caterpillar)

      @character_sprites.push(sprite)

    end

  end

end

 

#==============================================================================

# ■ Scene_Map

#==============================================================================

class Scene_Map

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_main main

  def main

    $game_player.refresh

    atoa_caterpillar_main

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_update update if !method_defined?(:atoa_caterpillar_update)

  def update

    if (Input.press?(Run_Key) and $game_switches[Run_Switch]) or

       $game_switches[Running_Switch]

      $game_player.run_mode

    else

      $game_player.walk_mode

    end

    atoa_caterpillar_update

    if Input.trigger?(Input::L) and Allow_Reorder

      $game_system.se_play($data_system.decision_se)

      reorder_party(true)

    end

    if Input.trigger?(Input::R) and Allow_Reorder

      $game_system.se_play($data_system.decision_se)

      reorder_party(false)

    end

    if $game_party.actors[0].dead?

      reorder_party(true)

    end

    $game_player.refresh if Graphics.frame_count % 5 == 0

  end

  #--------------------------------------------------------------------------

  def reorder_party(order)

    if order

      loop do

        party = $game_party.actors.shift

        $game_party.actors << party

        break if $game_party.all_dead? or not $game_party.actors[0].dead?

      end

    else

      loop do

        party = $game_party.actors.pop

        $game_party.actors.unshift(party)

        break  if $game_party.all_dead? or not $game_party.actors[0].dead?

      end

    end

  end

end

Translated:
Code:
#================================================= ============================

# Atoa Caterpillar

# For Atoa

#================================================= =============================

# This script allows you to visualize the members on the map, they will follow the hero

# A little different from other caterpillar, to the characters

# Only move if necessary (so they are not equal "cheap dizzy"

# If you bounce back and forth.

#

# It also has a race and move diagonally (both can be

# Disabled if you do not want these).

#

# The race and diagonal movement also has animation differentiated.

# You need the graphics of different animations:

# 1 - Chart for race: a graph with the same name as the pick of the charset + Run

# 2 - Chart for diagonal movement: a graph with the same name as the pick of the charset + Diag

# 3 - Chart for diagonal movement with race: a graph with the same name as the graphic

# Charset + DiagRun

#

# If the graphic is not found, the normal graph is used.

#

# You can control the movement of the characters of the queue creeping

# Command event using the call script command.

#

# $ Game_player.caterpillar [0]. X = X position on the map

# $ Game_player.caterpillar [0]. Y = Y position on the map

#

# To join the characters use the command: $ game_player.caterpillar_gather

#

• Remember not to allow movement of the character if the group is separated

# So use the command to gather after such events.

#

#================================================= =============================

 

module Atoa

 

   # Maximum Number of characters following the hero on screen

   Max_Caterpillar_Actor = 3

 

   # ID of the switch that hides the visualization of the characters when activated

   Caterpillar_Hide_Switch = 1

 

   # Hide group members who are dead

   Hide_Dead = false

 

   Change Order # Allow group is pressing the keys Q, W?

   Allow_Reorder = true

   

   # Allow diagonal movement?

   Diagonal_Movement = true

 

   # Enable setting of speed when you're walking on diagonal?

   Diagonal_Speed_Adjust = true

 

   # Maximum distance between the characters of the group (pixel value)

   Let # 0 to disable

   Max_Distance = 0

 

   ID # Switch that enables the race, if this switch is off

   # Character can not run

   Run_Switch = 2

 

   ID # Switch that enables race without the need to press

   # A button. While she is on, the character will always run.

   Running_Switch = 3

 

   # Key pressed which allows the character run.

   Run_Key = Input:: C

   # Input:: A>> Keyboard: Z

   # Input:: B>> Keyboard: X

   # Input:: C>> Keyboard: C

   # Input:: X>> Keyboard: A

   # Input:: Y>> Keyboard: S

   # Input:: Z>> Keyboard: D

   # Input:: L>> Keyboard: Q

   # Input:: R>> Keyboard: W

end

 

#================================================= =============================

# ■ Sprite_Character

#================================================= =============================

Sprite_Character class

   #------------------------------------------------- -------------------------

   include Atoa

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_update update

   def update

     atoa_caterpillar_update

     if@character.is_a? (Game_Player) [email=or@character.is]or@character.is[/email]_a? (Atoa_Catterpillar)

       a =''

       a + = 'Diag' [email=if@character.diagonal]if@character.diagonal[/email]

       a + = 'Run' [email=if@character.running]if@character.running[/email]

       begin

         self.bitmap = RPG:: Cache.character (@ character.character_name + a, @ character.character_hue)

       rescue

         self.bitmap = RPG:: Cache.character (@ character.character_name, @ character.character_hue)

       end

       @ cw = bitmap.width / 4

       @ ch = bitmap.height / 4

       self.ox = @ cw / 2

       self.oy = @ ch

       character.pattern sx = @ * @ cw

       sy = (@ character.direction - 2) / 2 * @ ch

       self.src_rect.set (sx, sy, @ cw, @ ch)

     end

   end

end

 

#================================================= =============================

# ■ Game_Character

#================================================= =============================

Game_Character class

   #------------------------------------------------- -------------------------

   include Atoa

   #------------------------------------------------- -------------------------

   attr_accessor (: direction, diagonal,: running)

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_initialize_gamechar initialize if! method_defined (: atoa_caterpillar_initialize_gamechar)

   def initialize

     atoa_caterpillar_initialize_gamechar

     diagonal = @ @ running = false

     base_speed = @ @ move_speed

   end

   #------------------------------------------------- -------------------------

   alias move_type_custom_diagrun_gamechar move_type_custom

   def move_type_custom

     move_type_custom_diagrun_gamechar

     @ base_speed = [[@ move_speed, 1]. max, 6]. min

   end

end

 

#================================================= =============================

# ■ Game_Player

#================================================= =============================

class Game_Player <Game_Character

   #------------------------------------------------- -------------------------

   attr_accessor (: caterpillar,: move_speed,: running,: alive_actors)

   #------------------------------------------------- -------------------------

   def run_mode

     @ running = true

     for cat in @ caterpillar

       cat.running = true

     end

   end

   #------------------------------------------------- -------------------------

   def walk_mode

     @ running = false

     for cat in @ caterpillar

       cat.running = false

     end

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_refresh refresh if! method_defined (: atoa_caterpillar_refresh)

   def refresh

     caterpillar_update

     atoa_caterpillar_refresh

   end

   #------------------------------------------------- -------------------------

   def caterpillar_update

     if @ caterpillar == nil

       caterpillar @ = []

       for i in 1 ... (Max_Caterpillar_Actor + 1)

         @ caterpillar <<Atoa_Catterpillar.new (i)

       end

     end

     for cat in @ caterpillar

       cat.refresh

     end

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_update update if! method_defined (: atoa_caterpillar_update)

   def update

     for cat in @ caterpillar

       cat.update

     end

     last_moving = moving?

     unless moving? or $ game_system.map_interpreter.running? or

            @ move_route_forcing or $ game_temp.message_window_showing

       input = Diagonal_Movement? Input.dir8: Input.dir4

       case input

       when 2

         Move_down

       when 4

         move_left

       when 6

         move_right

       when 8

         Move_up

       when 1

         move_lower_left

       when 3

         move_lower_right

       when 7

         move_upper_left

       when 9

         move_upper_right

       end

     end

     move_speed = @ @ base_speed

     move_speed @ + = 1 if @ running and moving?

     move_speed @ -= 1 if @ diagonal and Diagonal_Speed_Adjust and not $ game_system.map_interpreter.running?

     last_real_x = @ real_x

     last_real_y = @ real_y

     super

     if @ real_y> last_real_y and @ real_y - $ game_map.display_y> CENTER_Y

       $ game_map.scroll_down (@ real_y - last_real_y)

     end

     if @ real_x <last_real_x and @ real_x - $ game_map.display_x <CENTER_X

       $ game_map.scroll_left (last_real_x - @ real_x)

     end

     if @ real_x> last_real_x and @ real_x - $ game_map.display_x> CENTER_X

       $ game_map.scroll_right (@ real_x - last_real_x)

     end

     if @ real_y <last_real_y and @ real_y - $ game_map.display_y <CENTER_Y

       $ game_map.scroll_up (last_real_y - @ real_y)

     end

     unless moving?

       if last_moving

         check_event_trigger_here result = ([1,2])

         if result == false

           unless $ DEBUG and Input.press? (Input:: CTRL)

             encounter_count @ -= 1 if @ encounter_count> 0

           end

         end

       end

       if Input.trigger? (Input:: C)

         check_event_trigger_here ([0])

         check_event_trigger_there ([0,1,2])

       end

     end

   end

   #------------------------------------------------- -------------------------

   def turn_down

     unless @ direction_fix

       @ diagonal = false

       @ direction = 2

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_left

     unless @ direction_fix

       @ diagonal = false

       @ direction = 4

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_right

     unless @ direction_fix

       @ diagonal = false

       @ direction = 6

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_up

     unless @ direction_fix

       @ diagonal = false

       @ direction = 8

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_lower_left

     unless @ direction_fix

       @ diagonal = true

       @ direction = 2

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_lower_right

     unless @ direction_fix

       @ diagonal = true

       @ direction = 6

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_upper_left

     unless @ direction_fix

       @ diagonal = true

       @ direction = 4

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_upper_right

     unless @ direction_fix

       @ diagonal = true

       @ direction = 8

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_moveto moveto if! method_defined (: atoa_caterpillar_moveto)

   def moveto (x, y)

     atoa_caterpillar_moveto (x, y)

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     for i in 0 ... @ caterpillar.size

       @ caterpillar [i]. moveto (x, y)

     end

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_move_down Move_down if! method_defined (: atoa_caterpillar_move_down)

   def Move_down

     = passable passable? (@ x, @ y, 2)

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     atoa_caterpillar_move_down

     add_move_update ( 'Move_down') if passable

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_move_left move_left if! method_defined (: atoa_caterpillar_move_left)

   def move_left

     = passable passable? (@ x, @ y, 4)

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     atoa_caterpillar_move_left

     add_move_update ( 'move_left') if passable

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_move_right move_right if! method_defined (: atoa_caterpillar_move_right)

   def move_right

     = passable passable? (@ x, @ y, 6)

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     atoa_caterpillar_move_right

     add_move_update ( 'move_right') if passable

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_move_up Move_up if! method_defined (: atoa_caterpillar_move_up)

   def Move_up

     = passable passable? (@ x, @ y, 8)

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     atoa_caterpillar_move_up

     add_move_update ( 'Move_up') if passable

   end

   #------------------------------------------------- -------------------------

   def move_lower_left (turn_enabled = true)

     passable = (passable? (@ x, @ y, 2) and passable? (@ x, @ y + 1, 4)) or (passable? (@ x, @ y, 4) and passable? (@ x - 1 , @ y, 2))

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     if passable

       @ x -= 1

       @ y + = 1

       increase_steps

     end

     turn_lower_left if turn_enabled

     add_move_update ( 'move_lower_left') if passable

   end

   #------------------------------------------------- -------------------------

   def move_lower_right (turn_enabled = true)

     passable = (passable? (@ x, @ y, 2) and passable? (@ x, @ y + 1, 6)) or (passable? (@ x, @ y, 6) and passable? (@ x + 1 , @ y, 2))

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     if passable

       @ x + = 1

       @ y + = 1

       increase_steps

     end

     turn_lower_right if turn_enabled

     add_move_update ( 'move_lower_right') if passable

   end

   #------------------------------------------------- -------------------------

   def move_upper_left (turn_enabled = true)

     passable = (passable? (@ x, @ y, 8) and passable? (@ x, @ y - 1, 4)) or (passable? (@ x, @ y, 4) and passable? (@ x - 1 , @ y, 8))

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     if passable

       @ x -= 1

       @ y -= 1

       increase_steps

     end

     turn_upper_left if turn_enabled

     add_move_update ( 'move_upper_left') if passable

   end

   #------------------------------------------------- -------------------------

   def move_upper_right (turn_enabled = true)

     passable = (passable? (@ x, @ y, 8) and passable? (@ x, @ y - 1, 6)) or (passable? (@ x, @ y, 6) and passable? (@ x + 1 , @ y, 8))

     caterpillar_update [email=if@caterpillar.nil]if@caterpillar.nil[/email]? or@move_update.nil?

     if passable

       @ x + = 1

       @ y -= 1

       increase_steps

     end

     turn_upper_right if turn_enabled

     add_move_update ( 'move_upper_right') if passable

   end

   #------------------------------------------------- -------------------------

   def caterpillar_gather

     for i in 0 ... @ caterpillar.size

       @ caterpillar [i]. gather_party

     end

   end

   #------------------------------------------------- -------------------------

   def add_move_update (move)

     if @ caterpillar [0]! = nil

       @ caterpillar [0]. move_update <<move

     end

   end

   #------------------------------------------------- -------------------------

   def set_alive_actors

     @ alive_actors = []

     for actor in $ game_party.actors

       @ alive_actors <<actor unless actor.dead?

     end

   end

end

 

#================================================= =============================

# ■ Atoa_Catterpillar

#================================================= =============================

class Atoa_Catterpillar <Game_Character

   #------------------------------------------------- -------------------------

   attr_accessor (: move_update,: member,: next_x,: NEXT_YEAR,: x,: y,: move_speed,: running)

   #------------------------------------------------- -------------------------

   def initialize (member)

     super ()

     @ move_update = []

     @ member = member

     moveto ($ game_player.x, $ game_player.y)

     @ running = false

     @ through = true

     refresh

     next_x @ = @ x

     NEXT_YEAR @ = @ y

   end

   #------------------------------------------------- -------------------------

   def moveto (x, y)

     super (x, y)

     @ move_update.clear

   end

   #------------------------------------------------- -------------------------

   def refresh

     $ game_player.set_alive_actors

     party = Hide_Dead? $ game_player.alive_actors.dup: $ game_party.actors

     if party.size <@ member

       character_name @ = ""

       @ character_hue = 0

       return

     end

     actor = party [@ member]

     if actor == nil

       character_name @ = ""

       @ character_hue = 0

       return

     end

     @ = character_name actor.character_name

     @ = character_hue actor.character_hue

     @ opacity = 255

     @ blend_type = 0

   end

   #------------------------------------------------- -------------------------

   def screen_z (height = 0)

     game_player.x if $ == @ x and $ game_player.y == @ y

       return $ game_player.screen_z - 1

     end

     super (height)

   end

   #------------------------------------------------- -------------------------

   def check_event_trigger_here (triggers)

     return false

   end

   #------------------------------------------------- -------------------------

   def check_event_trigger_there (triggers)

     return false

   end

   #------------------------------------------------- -------------------------

   def check_event_trigger_touch (x, y)

     return false

   end

   #------------------------------------------------- -------------------------

   def update

     member = member @ == 1? $ Game_Player: $ game_player.caterpillar [@ member - 2]

     diff = (player_distance (member)> = (Max_Distance + 1))? 0: 1

     move_speed @ = [$ game_player.move_speed.to_f - diff, 1]. max

     move_player (member)

     super

     @ transparent = $ game_player.transparent

     @ @ transparent = transparent? @ transparent: $ game_switches [Caterpillar_Hide_Switch]

   end

   #------------------------------------------------- -------------------------

   def player_distance (member)

     dist_x = (member.screen_x - self.screen_x). abs

     dist_y = (member.screen_y - self.screen_y). abs

     return dist_x if dist_x> = dist_y

     return dist_y if dist_y> = dist_x

     return 0

   end

   #------------------------------------------------- -------------------------

   def move_player (member)

     refresh

     @ move_update.clear if member.x == @ x and @ y == member.y

     return if moving?

     need_update return unless (member)

     move = @ move_update.shift

     eval (move) if move! = nil

   end

   #------------------------------------------------- -------------------------

   def need_update (member)

     return false if member.x == @ x and @ y == member.y

     return false if@move_update.empty?

     if @ move_update [0] == 'move_left'

       return false if (member.x + 1 == @ x and @ y == member.y)

     elsif @ move_update [0] == 'move_right'

       return false if (member.x - 1 == @ x and @ y == member.y)

     elsif @ move_update [0] == 'Move_up'

       return false if (member.y + 1 == @ y and member.x == @ x)

     elsif @ move_update [0] == 'Move_down'

       return false if (member.y - 1 == @ y and member.x == @ x)

     elsif @ move_update [0] == 'move_upper_left'

       return false if (member.x + 1 == @ x and member.y + 1 == @ y)

     elsif @ move_update [0] == 'move_upper_right'

       return false if (member.x - 1 == @ x and member.y + 1 == @ y)

    elsif @ move_update [0] == 'move_lower_left'

       return false if (member.x + 1 == @ x and member.y - 1 == @ y)

     elsif @ move_update [0] == 'move_lower_right'

       return false if (member.x - 1 == @ x and member.y - 1 == @ y)

     end

     return true

   end

   #------------------------------------------------- -------------------------

   def add_move_update (move)

     member = $ game_player.caterpillar [@ member]

     if member! = nil

       member.move_update <<move

     end

   end

   #------------------------------------------------- -------------------------

   def gather_party

     for i in 0 ... $ game_party.actors.size

       move_toward_player

     end

     @ x = $ game_player.x

     @ y = $ game_player.y

     @ move_update.clear

   end

   #------------------------------------------------- -------------------------

   def turn_down

     unless @ direction_fix

       @ diagonal = false

       @ direction = 2

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_left

     unless @ direction_fix

       @ diagonal = false

       @ direction = 4

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_right

     unless @ direction_fix

       @ diagonal = false

       @ direction = 6

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_up

     unless @ direction_fix

       @ diagonal = false

       @ direction = 8

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_lower_left

     unless @ direction_fix

       @ diagonal = true

       @ direction = 2

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_lower_right

     unless @ direction_fix

       @ diagonal = true

       @ direction = 6

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_upper_left

     unless @ direction_fix

       @ diagonal = true

       @ direction = 4

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def turn_upper_right

     unless @ direction_fix

       @ diagonal = true

       @ direction = 8

       @ stop_count = 0

     end

   end

   #------------------------------------------------- -------------------------

   def Move_down (turn_enabled = true)

     @ y + = 1 if passable? (@ x, @ y, 2)

     turn_down if turn_enabled

     add_move_update ( 'Move_down')

   end

   #------------------------------------------------- -------------------------

   def move_left (turn_enabled = true)

     @ x -= 1 if passable? (@ x, @ y, 4)

     turn_left if turn_enabled

     add_move_update ( 'move_left')

   end

   #------------------------------------------------- -------------------------

   def move_right (turn_enabled = true)

     @ x + = 1 if passable? (@ x, @ y, 6)

     turn_right if turn_enabled

     add_move_update ( 'move_right')

   end

   #------------------------------------------------- -------------------------

   def Move_up (turn_enabled = true)

     @ y -= 1 if passable? (@ x, @ y, 8)

     turn_up if turn_enabled

     add_move_update ( 'Move_up')

   end

   #------------------------------------------------- -------------------------

   def move_lower_left (turn_enabled = true)

     if (passable? (@ x, @ y, 2) and passable? (@ x, @ y + 1, 4)) or

        (passable? (@ x, @ y, 4) and passable? (@ x - 1, @ y, 2))

       @ x -= 1

       @ y + = 1

     end

     turn_lower_left if turn_enabled

     add_move_update ( 'move_lower_left')

   end

   #------------------------------------------------- -------------------------

   def move_lower_right (turn_enabled = true)

     if (passable? (@ x, @ y, 2) and passable? (@ x, @ y + 1, 6)) or

        (passable? (@ x, @ y, 6) and passable? (@ x + 1, @ y, 2))

       @ x + = 1

       @ y + = 1

     end

     turn_lower_right if turn_enabled

     add_move_update ( 'move_lower_right')

   end

   #------------------------------------------------- -------------------------

   def move_upper_left (turn_enabled = true)

     if (passable? (@ x, @ y, 8) and passable? (@ x, @ y - 1, 4)) or

        (passable? (@ x, @ y, 4) and passable? (@ x - 1, @ y, 8))

       @ x -= 1

       @ y -= 1

     end

     turn_upper_left if turn_enabled

     add_move_update ( 'move_upper_left')

   end

   #------------------------------------------------- -------------------------

   def move_upper_right (turn_enabled = true)

     if (passable? (@ x, @ y, 8) and passable? (@ x, @ y - 1, 6)) or

        (passable? (@ x, @ y, 6) and passable? (@ x + 1, @ y, 8))

       @ x + = 1

       @ y -= 1

     end

     turn_upper_right if turn_enabled

     add_move_update ( 'move_upper_right')

   end

end

 

#================================================= =============================

# ■ Spriteset_Map

#================================================= =============================

Spriteset_Map class

   #------------------------------------------------- -------------------------

   include Atoa

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_initialize initialize if! method_defined (: atoa_caterpillar_initialize)

   def initialize

     atoa_caterpillar_initialize

     caterpillar is in $ game_player.caterpillar.reverse

       sprite = Sprite_Character.new (@ viewport1, caterpillar)

       @ character_sprites.push (sprite)

     end

   end

end

 

#================================================= =============================

# ■ Scene_Map

#================================================= =============================

Scene_Map class

   #------------------------------------------------- -------------------------

   include Atoa

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_main main

   def main

     $ game_player.refresh

     atoa_caterpillar_main

   end

   #------------------------------------------------- -------------------------

   alias atoa_caterpillar_update update if! method_defined (: atoa_caterpillar_update)

   def update

     if (Input.press? (Run_Key) and $ game_switches [Run_Switch]) or

        $ game_switches [Running_Switch]

       $ game_player.run_mode

     else

       $ game_player.walk_mode

     end

     atoa_caterpillar_update

     if Input.trigger? (Input:: L) and Allow_Reorder

       $ game_system.se_play ($ data_system.decision_se)

       reorder_party (true)

     end

     if Input.trigger? (Input:: R) and Allow_Reorder

       $ game_system.se_play ($ data_system.decision_se)

       reorder_party (false)

     end

     if $ game_party.actors [0]. dead?

       reorder_party (true)

     end

     $ game_player.refresh if Graphics.frame_count% 5 == 0

   end

   #------------------------------------------------- -------------------------

   def reorder_party (order)

     if order

       loop

         party = $ game_party.actors.shift

         $ game_party.actors <<party

         break if $ game_party.all_dead? or not $ game_party.actors [0]. dead?

       end

     else

       loop

         party = $ game_party.actors.pop

         $ game_party.actors.unshift (party)

         break if $ game_party.all_dead? or not $ game_party.actors [0]. dead?

       end

     end

   end

end

Thanks in advance,
~Steven a.k.a. ShinyToyGuns~

Edit: Me = Stoopid... :blush:

The translator messed with the script, therefore rendering it useless -_-
 

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