Tiny ABS
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Hey, I'm new here.

As my introduction to this forum, I present to you, a small but potentially useful script - a bare-bones, but working ABS, weighing in at 122 lines of code. Enjoy.

Code:
class ABS

  def setup
    @enemies = []
    for event in $game_map.events.values
      for monster in $data_enemies.compact
        if event.event.name == monster.name
          @enemies.push(ABS_Enemy.new(monster, event))
          break
        end
      end
    end
    @cooldown = 0
  end

  def update
    for enemy in @enemies
      if ($game_player.abs_in_range?(enemy.event, 1) and @cooldown <= 0 and
          $game_player.abs_facing?(enemy.event) and Input.trigger?(Input::C))
        enemy.attack_effect($game_party.actors[0])
        enemy.engage
        $game_player.animation_id = $game_party.actors[0].animation1_id
        enemy.event.animation_id = $game_party.actors[0].animation2_id
        @cooldown = 20
        if enemy.dead?
          @enemies.delete(enemy)
          enemy.event.erase
        end
      end
      enemy.update
    end
    @cooldown -= 1 if @cooldown > 0
  end
end

class ABS_Enemy < Game_Enemy

  attr_reader :event

  def initialize(monster, event)
    abs_initialize
    @enemy_id = monster.id
    @hp = maxhp
    @sp = maxsp
    @monster = monster
    @event = event
    @cooldown = 0
  end

  def update
    if @engaged
      if (@event.abs_in_range?($game_player, 1) and @cooldown <= 0 and
          @event.abs_facing?($game_player) and not @event.moving?)
        $game_party.actors[0].attack_effect(self)
        $game_temp.gameover = $game_party.actors[0].dead?
        $game_map.events[@event.id].animation_id = animation1_id
        $game_player.animation_id = animation2_id
        @cooldown = 75
      end
    elsif (@event.abs_in_range?($game_player) and
           @event.abs_facing?($game_player))
      engage
    end
    @cooldown -= 1 if @cooldown > 0
  end
  
  def engage
    @engaged = true
    @event.move_type = 2
  end
end

$abs = ABS.new

class Scene_Map
  alias abs_update update
  def update
    abs_update
    $abs.update
  end
end

class Game_Map
  alias abs_setup setup
  def setup(map_id)
    abs_setup(map_id)
    $abs.setup
  end
end

class Game_Battler
  alias abs_initialize initialize
  def initialize
    abs_initialize
  end
end

class Game_Character

  attr_accessor :move_type, :move_frequency, :move_speed, :character_name
  attr_reader :event

  def abs_facing?(event)
    case self.direction
    when 2
      return true if event.y > self.y
    when 4
      return true if event.x < self.x
    when 6
      return true if event.x > self.x
    when 8
      return true if event.y < self.y
    end
    return false
  end

  def abs_in_range?(event, range = 5)
    x = (self.x - event.x).abs
    y = (self.y - event.y).abs
    return x + y <= range
  end
end
}


Messages In This Thread
Tiny ABS - by Anon - 11-28-2005, 01:00 PM



Users browsing this thread: 1 Guest(s)