Não sei como continuar meu script e-e

3 Respostas   136 Visualizações

0 Membros e 1 Visitante estão vendo este tópico.

Nunnu

  • *
  • Posts: 39
  • Ouros: 2
  • cala boca
Tópico criado em: 21/12/2016 às 08:07 - Última modificação por Skyloftian em 21/12/2016 às 13:24

Oi à todos, eu quero barrar de alguma forma um erro do meu script, basicamente meu script funciona como uma formação dos personagens.

Mas quando eles encostam em algum objeto de colisão do mapa, os personagens se juntam, pois não há uma colisão entre eles, e eu quero criá-la para apenas ativar no momento que encostar em algo.




Script até agora:
Código: [Selecionar]
class Game_Followers

  alias prev_initialize initialize
  def initialize(leader)
    prev_initialize(leader)
    @switch_one = false
    @switch_two = false
  end

  alias prev_update update
  def update
    prev_update
    if Input.trigger?(:X)
      @switch_two = false
      gather
      @switch_one = true
    end

    if !moving? && !gathering? && @switch_one
      triangle_formation
    end
  end

  def move
    if @switch_two == false
      reverse_each {|follower| follower.chase_preceding_character }
    elsif @switch_two == true
      reverse_each {|follower| self.triangle_formation_follow }
    end
  end
 
  def triangle_formation_follow
    unless moving?
      each do |follower|
        follower.move_straight(Input.dir4) if Input.dir4 > 0
      end
    end
  end
 
  def triangle_formation
    case $game_player.direction
    when 2
      self[0].move_straight(4)
      self[0].set_direction(2)

      self[1].move_straight(6)
      self[1].set_direction(2)
     
      self[2].move_straight(2)
      self[2].set_direction(2)
     
    when 4
      self[0].move_straight(8)
      self[0].set_direction(4)
     
      self[1].move_straight(2)
      self[1].set_direction(4)
     
      self[2].move_straight(4)
      self[2].set_direction(4)

    when 6
      self[0].move_straight(8)
      self[0].set_direction(6)
     
      self[1].move_straight(2)
      self[1].set_direction(6)
     
      self[2].move_straight(6)
      self[2].set_direction(6)
     
    when 8
      self[0].move_straight(4)
      self[0].set_direction(8)
     
      self[1].move_straight(6)
      self[1].set_direction(8)

      self[2].move_straight(8)
      self[2].set_direction(8)
    end
   
    @switch_one = false; @switch_two = true

  end
end

É isso pessoal, se puderem me ajudar ficaria grato, obrigado pela atenção.
Feito por:   King Gerar          ManecBR3
                   
                   (um gato)            (outro gato)

Resque

Resposta 1: 21/12/2016 às 11:08

Bom dia, tudo bem?

Vou ajustar para você.

Nunnu

  • *
  • Posts: 39
  • Ouros: 2
  • cala boca
Resposta 2: 21/12/2016 às 13:04

@Resque

Bom dia! E muito obrigado.
Feito por:   King Gerar          ManecBR3
                   
                   (um gato)            (outro gato)

Resque

Resposta 3: 31/12/2016 às 17:58 - Última modificação por Resque em 31/12/2016 às 18:13

Nunnu, boa tarde.

Terminei o seu script.

Para realizar o seu desejo, tive que fazer algumas melhorias na estrutura do código, espero que não se importe.

Além de colocar o bloqueio, foi incluído a reorganização automática caso algum seguidor encoste em um objeto.

Segue o vídeo e o script abaixo.

Caso tenha alguma duvida em relação as modificações, ou encontre algum tipo de problema, favor me informar.

Feliz ano novo  :ok:


Código: [Selecionar]
# Autor: Nunnu

# Modificações Resque :
#    E-mail: rogessonb@gmail.com
#    Bloqueio de passabilidade dos seguidores
#    Reagrupamento automático


#################################################
#                  SCRIPT                       #
#################################################


# Configuracao do Triângulo
module TriangleFormation
  DOWN  = [:left, :right, :up]
  LEFT  = [:up, :down , :right]
  RIGHT = [:up, :down, :left]
  UP    = [:right, :left, :down]
end

module Directions
  def self.position
    {
      up:     8,
      right:  6,
      left:   4,
      down:   2
    }
  end

  def self.get_direction(direction_number)
    self::position.key(direction_number)
  end
end

class Game_Followers
  alias prev_initialize initialize
  def initialize(leader)
    prev_initialize(leader)
    @switch_one = false
    @switch_two = false

    # Não Mudar o nome das variáveis abaixo, ou eu puxarei o seu pé de noite.
    @down_list  = TriangleFormation::DOWN
    @left_list  = TriangleFormation::LEFT
    @right_list = TriangleFormation::RIGHT
    @up_list    = TriangleFormation::UP
  end

  alias prev_update update
  def update
    prev_update
    if Input.trigger?(:X)
      @switch_two = false
      gather
      @switch_one = true
    end

    if !moving? && !gathering? && @switch_one
      triangle_formation
    end
  end

  def move
    if @switch_two == false
      reverse_each {|follower| follower.chase_preceding_character }
    elsif @switch_two == true
      reverse_each {|follower| self.triangle_formation_follow }
    end
  end

  def triangle_formation_follow
    unless moving?
      each do |follower|
        follower.move_straight(Input.dir4) if Input.dir4 > 0
      end
    end
  end

  def reorganize(player)
    each do |follower|
      3.times { follower.move_toward_player }
    end

    triangle_formation
  end

  def is_passable?(d)
    passable_list = []

    each { |follower| passable_list << follower.is_passable?(d) }

    !passable_list.include?(false)
  end

  def triangle_formation
    triangle(Directions::get_direction($game_player.direction))

    @switch_one = false
    @switch_two = true
  end

  private

  def triangle(pos)
    @data.each_with_index do |follower, index|
      set_triangle(follower, pos, index)
    end
  end

  def set_triangle(follower, position, index)
    pos = eval_variable_list("@#{position.to_s}_list")

    follower.move_straight(Directions::position[pos[index]])
    follower.set_direction(Directions::position[position])
  end

  def eval_variable_list(instance_var_name)
    instance_variable_get(instance_var_name)
  end
end

class Game_Player < Game_Character
  def move_by_input
    return if !movable? || $game_map.interpreter.running?
    if Input.dir4 > 0
      move_straight(Input.dir4)
    end
  end

  def move_straight(d, turn_ok = true)
    @followers.move if passable?(@x, @y, d)
    super
  end

  def movable?
    return false if moving?
    return false if @move_route_forcing || @followers.gathering?
    return false if @vehicle_getting_on || @vehicle_getting_off
    return false if $game_message.busy? || $game_message.visible
    return false if vehicle && !vehicle.movable?

    passable_followers?

    return true
  end

  def passable_followers?
    @followers.reorganize(self) if !@followers.is_passable?(Input.dir4)
  end
end

class Game_Follower < Game_Character
  def initialize(member_index, preceding_character)
    super()
    @member_index = member_index
    @preceding_character = preceding_character
    @transparent = $data_system.opt_transparent
    @through = false
  end

  def is_passable?(d)
   passable?(@x, @y, d)
  end
end