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.

caldaron ABS

Urborg

Member

hi there
i have some poblem using caldaron ABS
i usually try and learn how to use things alone by trying but i didn't find a way to use spells

i set spell's range ,ok that i can do but than no button seem to make them work and they don't work from the menu as well (apart heals and things that afffect my party)

and 2nd, all weapons hit everything in rage, is there a way to make them hit only 1 monster at once?

thanks for every relply that will come

sorry for my not perfect english but is not my first language

thanks
 

Urborg

Member

yes you are right ,wrong section
btw

that's the abs
if SDK.state("Caldaron's Battle")
 
class ABS
  attr_accessor :actor
  attr_accessor :enemies
  attr_accessor :events
  attr_accessor :event_triggers
  attr_accessor :active
  attr_accessor :actor_battle
  attr_accessor :e_animations
  attr_accessor :p_animations
  attr_accessor :portrait

  def initialize
    @portrait = false
    @p_animations = false
    @p_animations = false
    @actor = $game_party.actors[0]
    @actor_battle = false
    @enemies = {}
    @events = {} # Hash of Dead Events
    @event_triggers = {} # Hash of the Triggers of Dead Events
    $game_player.move_speed = 3
  end
 
  def setup_enemies(events)
    @enemies = {}
    for event in events.values
      settings = SDK.event_comment_input(event, 5, 'ABS Enemy')
      next unless settings
      enemy_setup    = settings[0].to_s.split
      behaviour_setup = settings[1].to_s.split
      range_setup    = settings[2].to_s.split
      coward_setup    = settings[3].to_s.split
      trigger_setup  = settings[4].to_s.split
     
      id = enemy_setup[0].to_i
      troop = enemy_setup[1]
      immortal = eval(enemy_setup[2]) # true/false
     
      alignment = behaviour_setup[0].to_i
      # 0 = attack none
      # 1 = attack evil
      # 2 = attack player and good
      # 3 = attack player
      # 4 = attack player and evil
      # 5 = attack good
      # 6 = attack all
      reaction = behaviour_setup[1].to_i
      # 0 = attack none
      # 1 = attack attacker
      # 2 = attack attacker and evil
      # 3 = attack attacker and good
      # 4 = attack all
      allied = eval(behaviour_setup[2])

      find_range = range_setup[0].to_i
      attack_range = range_setup[1].to_f
     
      help = eval(coward_setup[0]) # calls troop for help (true/false)
      run = coward_setup[1].to_i # runs away when hp is run %
     
      trigger_type = trigger_setup[0]
      trigger = trigger_setup[1]
      for enemy in $data_enemies
        next unless enemy
        if id == enemy.id
          @enemies[event.id] = ABS::Enemy.new(enemy.id)
          @enemies[event.id].event_id = event.id
          @enemies[event.id].troop = "ABS #{event.id}"
          @enemies[event.id].troop = troop.upcase unless troop == nil
          @enemies[event.id].find_range = find_range
          @enemies[event.id].attack_range = attack_range
          @enemies[event.id].help = help
          @enemies[event.id].run = run/100.00
          @enemies[event.id].alignment = alignment
          @enemies[event.id].allied = allied
          @enemies[event.id].reaction = reaction
          @enemies[event.id].immortal = immortal
          @enemies[event.id].trigger_type = trigger_type
          @enemies[event.id].trigger = trigger
          @agi = @enemies[event.id].agi/$game_party.actors[0].agi
          if @agi < 0.75
            @agi = 1
          elsif @agi < 1
            @agi = 2
          elsif @agi < 1.25
            @agi = 3
          elsif @agi < 1.5
            @agi = 4
          else
            @agi = 5
          end
          event.move_speed = @agi
          break
        end
      end
    end
  end
 
  def update
    update_actor if @actor_battle
    for enemy in @enemies.values
      update_enemy(enemy)
    end
    update_status
    update_hud
  end
 
  def update_actor
    @actor = $game_party.actors[0]
    @actor.abs.chill
  end
 
  def update_enemy(enemy)
    enemy.find_alignment
    if enemy.engaged
      enemy.guarding = false # Resets guarding
      enemy.chill if enemy.cooldown != 0 # Decrease cooldown
      if enemy.cooldown == 0
        enemy.reset if enemy.check_ai # Reset timers
        enemy.cooldown /= 2 if enemy.guarding
      end
      enemy.path_find # Pathfind to the player
    end
    if enemy.dead?
      for sprite in $scene.spriteset.character_sprites
        sprite.animation($data_animations[3],true) if sprite.character == $game_map.events[enemy.event_id]
      end
      collect_spoils(enemy) if enemy.attackers.include?($ABS.actor)
      remove(enemy)# Remove enemy based on its triggers
    end
  end
  #----------------------------------------------------------------------
  def update_status
    if @actor.dead?
      $game_temp.gameover = true  # End game if dead.
    end 
  end
  #----------------------------------------------------------------------
  def update_hud
    #hud shit goes here
  end
  #----------------------------------------------------------------------
  # * ABS Functions
  #----------------------------------------------------------------------
  # Handles anything regarding the ABS best done outside of other classes
  #----------------------------------------------------------------------
 
  def collect_spoils(enemy)
    exp = enemy.exp # Set to the enemy's EXP amount
    exp = Integer(exp/enemy.attackers.size * 1.00)
    gold = enemy.gold # Set to the enemy's GOLD amount
    gold = Integer(gold/enemy.attackers.size * 1.00)
    if rand(100) < enemy.treasure_prob # Random Probability of SPOIL
      if enemy.item_id > 0 # If its an ITEM
        treasure = $data_items[enemy.item_id]
      end
      if enemy.weapon_id > 0 # If its a WEAPON
        treasure = $data_weapons[enemy.weapon_id]
      end
      if enemy.armor_id > 0 # If its an ARMOR
        treasure = $data_armors[enemy.armor_id]
      end
    end
    @actor.exp += exp unless @actor.cant_get_exp? # Add Appropriate EXP
    $game_party.gain_gold(gold) # Add Appropriate GOLD
    case treasure
    when RPG::Item
      $game_party.gain_item(treasure.id, 1) # Add ITEM
    when RPG::Weapon
      $game_party.gain_weapon(treasure.id, 1) # Add WEAPON
    when RPG::Armor
      $game_party.gain_armor(treasure.id, 1) # Add ARMOR
    end
  end
  #----------------------------------------------------------------------
  def remove(enemy)
    for attacker in @enemies.values
      attacker.attackers.delete(enemy)
    end
    @enemies.delete(enemy.event_id) # Remove dead enemy from hash
    case enemy.trigger_type.upcase
    when 'LOCAL' # If trigger is a local switch
      case enemy.trigger.upcase
      when 'A','B','C','D' # If the trigger is a valid trigger
        event = $game_map.events[enemy.event_id]
        key = [event.map_id, event.id, enemy.trigger.upcase]
        $game_self_switches[key] = true
        @events[event.id] = event
        @event_triggers[event.id] = enemy.trigger.upcase
        event.refresh
        return
      end
    when 'SELF' # If trigger is a local switch
      case enemy.trigger.upcase
      when 'A','B','C','D' # If the trigger is a valid trigger
        event = $game_map.events[enemy.event_id]
        key = [event.map_id, event.id, enemy.trigger.upcase]
        $game_self_switches[key] = true
        @events[event.id] = event
        @event_triggers[event.id] = enemy.trigger_type.upcase
        event.refresh
        return
      end
    when 'SWITCH' # If the trigger is a switch
      if enemy.trigger.to_i > 0 # If the trigger is a valid switch
        $game_switches[enemy.trigger.to_i] = true
        event.refresh
        return
      end
    when 'CHEST'
      event = $game_map.events[enemy.event_id]
      key = [event.map_id, event.id, 'A']
      $game_self_switches[key] = true
      @events[event.id] = event
      @event_triggers[event.id] = enemy.trigger_type.upcase
      event.refresh
      return
    end
    # Else just remove the event lickity split.
    $game_map.events[enemy.event_id].character_name = ''
    $game_map.events[enemy.event_id].erase
  end
  #----------------------------------------------------------------------
  # * Calculation Functions
  #----------------------------------------------------------------------
  # Handles range and direction checks
  #----------------------------------------------------------------------
  def check_range(element, object, range = 0)
    element = $game_map.events[element.event_id] if element.is_a?(ABS::Enemy)
    object = $game_map.events[object.event_id] if object.is_a?(ABS::Enemy)
    x = (object.x - element.x)
    y = (object.y - element.y)
    if (x*x+y*y) <= (range * range)
      return true
    end
    return false
  end
  #----------------------------------------------------------------------
  def find_range(element, object)
    element = $game_map.events[element.event_id] if element.is_a?(ABS::Enemy)
    object = $game_map.events[object.event_id] if object.is_a?(ABS::Enemy)
    x = (object.x - element.x) * (object.x - element.x)
    y = (object.y - element.y) * (object.y - element.y)
    return (x + y)
  end
  #----------------------------------------------------------------------
  def check_facing(element, object, magic = 0)
    return true if element == object
    element = $game_map.events[element.event_id] if element.is_a?(ABS::Enemy)
    object = $game_map.events[object.event_id] if object.is_a?(ABS::Enemy)
    case magic
    when 2, 4
      return true
    when 1, 3
      if element.direction == 2
        return true if object.y >= element.y
      end
      if element.direction == 4
        return true if object.x <= element.x
      end
      if element.direction == 6
        return true if object.x >= element.x
      end
      if element.direction == 8
        return true if object.y <= element.y
      end
    when 0
      if element.direction == 2
        return true if object.y > element.y
      end
      if element.direction == 4
        return true if object.x < element.x
      end
      if element.direction == 6
        return true if object.x > element.x
      end
      if element.direction == 8
        return true if object.y < element.y
      end
    end
    return false
  end
  #----------------------------------------------------------------------
  # * ABS Animation Engine Functions
  #----------------------------------------------------------------------
  # Handles animating map sprites for a wide variety of uses
  #----------------------------------------------------------------------
  def animate(object, animation_name, position, wait = 8, frames = 0, repeat = 0)
    if object != nil
      object.animate(animation_name, position, frames, wait, repeat)
    end
  end
end

class Game_Battler
  def skill_can_use?(skill_id)
    if $data_skills[skill_id].sp_cost > self.sp and self.maxsp > 0
      return false
    end
    if dead?
      return false
    end
    if $data_skills[skill_id].atk_f == 0 and self.restriction == 1
      return false
    end
    occasion = $data_skills[skill_id].occasion
    if $scene.is_a?(Scene_Map)
      return (occasion == 0 or occasion == 1)
    else
      return (occasion == 0 or occasion == 2)
    end
  end
end


#-----------------------------------------------------------------------------#
# â–º Game_Event
#-----------------------------------------------------------------------------#
class Game_Event
  attr_reader :page
  attr_reader :map_id
  def name
    return @event.name
  end
end

#-----------------------------------------------------------------------------#
# â–º Game_Map
#-----------------------------------------------------------------------------#
class Game_Map
  alias prexus_abs_g_map_setup setup
  def setup(map_id)
    prexus_abs_g_map_setup(map_id)
    $ABS = ABS.new if !$ABS
    $ABS.setup_enemies(@events)
  end
end

#-----------------------------------------------------------------------------#
# â–º Spriteset_Map
#-----------------------------------------------------------------------------#
class Spriteset_Map
  attr_accessor :character_sprites
  attr_accessor :viewport4
  alias prex_abs_sset_map_init_viewports init_viewports
  def init_viewports
    prex_abs_sset_map_init_viewports
    @viewport4 = Viewport.new(0, 0, 640, 480)
    @viewport4.z = 6000
  end
  alias prex_abs_sset_map_update update
  def update
    prex_abs_sset_map_update
    @viewport4.update
  end
end

#-----------------------------------------------------------------------------#
# â–º Window_Skill
#-----------------------------------------------------------------------------#
class Window_Skill < Window_Selectable
  def draw_item(index)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      if $ABS.actor.abs.hot_key.include?(skill.id)
        self.contents.font.color = Color.new(0, 225, 0, 255)
      else
        self.contents.font.color = normal_color
      end
    else
      if $ABS.actor.abs.hot_key.include?(skill.id)
        self.contents.font.color = Color.new(0, 225, 0, 160)
      else
        self.contents.font.color = disabled_color
      end
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
    self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
  end
end

#-----------------------------------------------------------------------------#
# â–º Interpreter
#-----------------------------------------------------------------------------#
class Interpreter
  def event
    return $game_map.events[@event_id]
  end
end

#-----------------------------------------------------------------------------#
# â–º Scene_Title
#-----------------------------------------------------------------------------#
class Scene_Title
  alias prexus_abs_s_title_main_database main_database
  def main_database
    prexus_abs_s_title_main_database
    $ABS = nil
    $data_skills.each {|s| s.set_range if s}
    $data_weapons.each {|s| s.set_range if s}
    for i in 1...$data_animations.size
      i = $data_animations.frames
      for j in 0...i.size
        for k in 0...i[j].cell_max
          i[j].cell_data[k, 1] /= 3
          i[j].cell_data[k, 2] /= 3
          i[j].cell_data[k, 3] /= 3
        end
      end
    end
     
  end
end
module RPG
  class Animation
    class Frame
      attr_accessor :cell_data
    end
  end
end

#-----------------------------------------------------------------------------#
# â–º Scene_Map
#-----------------------------------------------------------------------------#
class Scene_Map
  attr_accessor :spriteset
  alias prexus_abs_s_map_update update
  def update
    if Input.trigger?(Input::ALT)
      $ABS.actor_battle = $ABS.actor_battle == true ? false : true
    end
    $ABS.update
    if !$ABS.actor.abs.acted and !$game_party.actors[0].guarding? and $ABS.actor_battle
      $ABS.actor.abs.attack if Input.trigger?(Input::C)
      $ABS.actor.abs.cast($ABS.actor.abs.hot_key[0]) if  Input.trigger?(Input::X)
      $ABS.actor.abs.cast($ABS.actor.abs.hot_key[1]) if  Input.trigger?(Input::Y)
      $ABS.actor.abs.cast($ABS.actor.abs.hot_key[2]) if  Input.trigger?(Input::Z)
    elsif !$ABS.actor_battle
      if $ABS.actor.abs.hot_key[0]
        skill1 = $data_skills[$ABS.actor.abs.hot_key[0]]
        $ABS.actor.abs.cast($ABS.actor.abs.hot_key[0]) if  Input.trigger?(Input::X) and [3, 4, 7].include?(skill1.scope) and (skill1.power < 1 or skill1.minus_state_set.size > 0)
      end
      if $ABS.actor.abs.hot_key[1]
        skill2 = $data_skills[$ABS.actor.abs.hot_key[1]]
        $ABS.actor.abs.cast($ABS.actor.abs.hot_key[1]) if  Input.trigger?(Input::Y) and [3, 4, 7].include?(skill2.scope) and (skill2.power < 1 or skill2.minus_state_set.size > 0)
      end
      if $ABS.actor.abs.hot_key[2]
        skill3 = $data_skills[$ABS.actor.abs.hot_key[2]]
        $ABS.actor.abs.cast($ABS.actor.abs.hot_key[2]) if  Input.trigger?(Input::Z) and [3, 4, 7].include?(skill3.scope) and (skill3.power < 1 or skill3.minus_state_set.size > 0)
      end
    end
    prexus_abs_s_map_update
  end
  alias prex_abs_s_map_transfer_player transfer_player
  def transfer_player
    for i in 0..$game_map.events.size
      event = $ABS.events
      trigger = $ABS.event_triggers
      next unless event and trigger
      next if trigger.upcase == 'SELF'
      if ['A', 'B', 'C', 'D'].include?(trigger.upcase)
        key = [event.map_id, event.id, trigger]
        $game_self_switches[key] = false
        $ABS.events.delete(event)
        $ABS.event_triggers.delete(trigger)
        next
      end
      if trigger.upcase == 'CHEST'
        key = [event.map_id, event.id, 'A']
        $game_self_switches[key] = false
        key = [event.map_id, event.id, 'B']
        $game_self_switches[key] = false
        key = [event.map_id, event.id, 'C']
        $game_self_switches[key] = false
        key = [event.map_id, event.id, 'D']
        $game_self_switches[key] = false
        $ABS.events.delete(event)
        $ABS.event_triggers.delete(trigger)
        next
      end
    end
    prex_abs_s_map_transfer_player
  end
end

#-----------------------------------------------------------------------------#
# â–º Scene_Skill
#-----------------------------------------------------------------------------#
class Scene_Skill
  alias prexus_abs_s_skill_update update
  def update
    if Input.trigger?(Input::X)
      skill = @skill_window.skill
      unless $ABS.actor.abs.hot_key[0] or
            $ABS.actor.abs.hot_key.include?(skill.id)
        $ABS.actor.abs.hot_key[0] = skill.id
      $game_system.se_play($data_system.decision_se)
      end
      @skill_window.refresh
      return
    end
    if Input.trigger?(Input::Y)
      skill = @skill_window.skill
      unless $ABS.actor.abs.hot_key[1] or
            $ABS.actor.abs.hot_key.include?(skill.id)
        $ABS.actor.abs.hot_key[1] = skill.id
      $game_system.se_play($data_system.decision_se)
      end
      @skill_window.refresh
      return
    end
    if Input.trigger?(Input::Z)
      skill = @skill_window.skill
      unless $ABS.actor.abs.hot_key[2] or
            $ABS.actor.abs.hot_key.include?(skill.id)
        $ABS.actor.abs.hot_key[2] = skill.id
      $game_system.se_play($data_system.decision_se)
      end
      @skill_window.refresh
      return
    end
    prexus_abs_s_skill_update
  end
end

#-----------------------------------------------------------------------------#
# â–º Scene_Save
#-----------------------------------------------------------------------------#
class Scene_Save < Scene_File
  alias prex_abs_s_save_write_data write_data
  def write_data(file)
    prex_abs_s_save_write_data(file)
    Marshal.dump($ABS, file)
  end
end

#-----------------------------------------------------------------------------#
# â–º Scene_Load
#-----------------------------------------------------------------------------#
class Scene_Load < Scene_File
  alias prex_abs_s_load_read_data read_data
  def read_data(file)
    prex_abs_s_load_read_data(file)
    $ABS = Marshal.load(file)
  end
end

#-----------------------------------------------------------------------------#
# â–º RPG::Sprite
#-----------------------------------------------------------------------------#
module RPG
  class Sprite < ::Sprite
    def damage(value, critical)
      dispose_damage
      if value.is_a?(Numeric)
        damage_string = value.abs.to_s
      else
        damage_string = value.to_s
      end
      bitmap = Bitmap.new(160, 48)
      bitmap.font.name = $fontface
      bitmap.font.size = 18
      if value.is_a?(Numeric) and value < 0
        bitmap.font.color.set(0, 96, 0)
      elsif value.is_a?(Numeric) and value > 0
        bitmap.font.color.set(96, 0, 0)
      else
        bitmap.font.color.set(0, 0, 96)
      end
      bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
      bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
      if value.is_a?(Numeric) and value < 0
        bitmap.font.color.set(0, 255, 0)
      elsif value.is_a?(Numeric) and value > 0
        bitmap.font.color.set(255, 0, 0)
      else
        bitmap.font.color.set(0, 0, 255)
      end
      bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
      if critical
        bitmap.font.color.set(96, 96, 0)
        bitmap.draw_text(-1, -1, 160, 20, "Nice!", 1)
        bitmap.draw_text(+1, -1, 160, 20, "Nice!", 1)
        bitmap.draw_text(-1, +1, 160, 20, "Nice!", 1)
        bitmap.draw_text(+1, +1, 160, 20, "Nice!", 1)
        bitmap.font.color.set(255, 255, 0)
        bitmap.draw_text(0, 0, 160, 20, "Nice!", 1)
      end
      @_damage_sprite = ::Sprite.new($scene.spriteset.viewport4)
      @_damage_sprite.bitmap = bitmap
      @_damage_sprite.ox = 80
      @_damage_sprite.oy = 20
      @_damage_sprite.x = x
      @_damage_sprite.y = y - oy / 2
      @_damage_sprite.z = 3000
      @_damage_duration = 40
    end
  end
end

#-----------------------------------------------------------------------------#
# â–º RPG::Skill
#-----------------------------------------------------------------------------#
module RPG
  class Skill
    attr_accessor :range
    attr_accessor :slip_damage
    #--------------------------------------------------------------------
    # * Instructions:
    #    Add new spells and their ranges by adding these lines:
    # when "SpellName"
    #  @range = valueforrange
    #--------------------------------------------------------------------
    #    For Example:
    # when "Cross Cut"
    #  @range = 2
    #--------------------------------------------------------------------
    def set_range
      @range = 1
      case self.id
      # Add New Lines Here:
      when 57
        @range = 40
      when 1, 4, 7, 25, 28, 45
        @range = 6
      when 3, 5, 27, 30, 46
        @range = 4
      when 61
        @range = 2
      end
    end
  end
  #--------------------------------------------------------------------
  class Weapon
    attr_accessor :range
    def set_range
      @range = 1
      case self.id
      when 4..8
        @range = Math.sqrt(2)
      when 1
        @range = 6
      when 2
        @range = 4
      when 3
        @range = 6
        end
    end
  end
end

class Game_Player < Game_Character
  #--------------------------------------------------------------------
  alias caldaron_abs_game_player_update_action_trigger update_action_trigger
  #--------------------------------------------------------------------
  def update_action_trigger
    caldaron_abs_game_player_update_action_trigger unless $ABS.actor_battle
  end
=begin
  #--------------------------------------------------------------------
  alias caldaron_abs_game_player_trigger_touch check_event_trigger_touch
  #--------------------------------------------------------------------
  def
end
check_event_trigger_touch(x, y)
    caldaron_abs_game_player_trigger_touch(x, y) unless $ABS.actor_battle
  end
  #--------------------------------------------------------------------
end

class Game_Event < Game_Character
  #--------------------------------------------------------------------
  alias caldaron_abs_game_event_trigger_touch check_event_trigger_touch
  #--------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    caldaron_abs_game_event_trigger_touch(x, y) unless $ABS.actor_battle
  end
  #--------------------------------------------------------------------
=end
end





than there is actor

class Game_Actor
  attr_accessor :abs
  #------------------------------------------------------------------------
  alias caldaron_abs_actor_setup setup
  #------------------------------------------------------------------------
  def setup(actor_id)
    caldaron_abs_actor_setup(actor_id)
    @abs = Game_Actor::ABS.new
  end
  #------------------------------------------------------------------------
  def guarding?
    return true if Input.press?(Input::B)
    return false
  end
  #--------------------------------------------------------------------------
  alias caldaron_abs_game_actor_base_atk base_atk
  #--------------------------------------------------------------------------
  def base_atk
    return caldaron_abs_game_actor_base_atk > 0 ? caldaron_abs_game_actor_base_atk : 1
  end
  #--------------------------------------------------------------------------
  alias caldaron_abs_game_actor_base_pdef base_pdef
  #--------------------------------------------------------------------------
  def base_pdef
    return caldaron_abs_game_actor_base_pdef > 0 ? caldaron_abs_game_actor_base_pdef : 0
  end
  #--------------------------------------------------------------------------
  alias caldaron_abs_game_actor_base_mdef base_mdef
  #--------------------------------------------------------------------------
  def base_mdef
    return caldaron_abs_game_actor_base_mdef > 0 ? caldaron_abs_game_actor_base_mdef : 0
  end
end

#-----------------------------------------------------------------------------#
# â–º Game_Actor::ABS
#-----------------------------------------------------------------------------#
class Game_Actor
  class ABS
    attr_accessor :cooldown
    attr_accessor :acted
    attr_accessor :hot_key
    #----------------------------------------------------------------------
    def initialize
      @cooldown = 0 # Attacking/casting cooldown
      @acted = false # Flag for whether or not you've acted recently
      @hot_key = [nil, nil, nil] # Hot key array
    end
    #----------------------------------------------------------------------
    # * Cooldown/input methods
    #----------------------------------------------------------------------
    def chill
      @cooldown -= 1 unless @cooldown == 0
      if @cooldown == 0
        @acted = false
        reset
      end
    end
    #----------------------------------------------------------------------
    def reset
      @cooldown = Integer((Graphics.frame_rate * ((500 + (999 / $game_party.actors[0].agi)*1.2) / 500)) * 1.5).floor / 2
    end
    #----------------------------------------------------------------------
    # * Attacking/Spell Casting Methods
    #----------------------------------------------------------------------
    def attack
      @weapon_range = $game_party.actors[0].weapon_id > 0 ? $data_weapons[$game_party.actors[0].weapon_id].range : 1
      @animation2_id = $game_party.actors[0].weapon_id > 0 ? $data_weapons[$game_party.actors[0].weapon_id].animation2_id : 4
      # Animate Actor:
      $ABS.animate($game_player, $game_player.character_name + '-atk',
        $game_player.direction/2, 4, 3) if $ABS.p_animations
      $game_player.animation_id = $ABS.actor.animation1_id unless $ABS.p_animations
      for enemy in $ABS.enemies.values
        next if enemy.immortal
        next if enemy.allied
        next if !$ABS.check_range($game_player, enemy, @weapon_range) # If enemy is in range
        next if !$ABS.check_facing($game_player, enemy) # and not behind
        enemy.attack_effect($ABS.actor) # hit the enemy
        enemy.change_alignment($ABS.actor) if enemy.alignment == 0
        enemy.attackers.push($ABS.actor) unless enemy.attackers.include?($ABS.actor)
        event = $game_map.events[enemy.event_id]
        sprite = nil
        for spr in $scene.spriteset.character_sprites
          sprite = spr if spr.character == event
        end
        sprite.damage(enemy.damage, enemy.critical) if sprite # show damage
        if enemy.damage != 'Miss' and enemy.damage != 0 # if the attack hit
          # Animate Enemy:
          $ABS.animate(event, event.page.graphic.character_name + '-hit',
            event.direction/2, 4, 3, 0) if $ABS.e_animations
          event.animation_id = @animation2_id
        end
        @acted = true # Yes you've recently attacked!
      end
    end
    #----------------------------------------------------------------------
    def cast(skill_id)
      return if skill_id == nil
      skill = $data_skills[skill_id]
      return if !$ABS.actor.skill_can_use?(skill.id)
      return if $ABS.actor.sp < skill.sp_cost
      targets = []
      heal = skill.power < 0
      case skill.scope
      when 0
        return
      when 1
        enemy = get_nearest_enemy
        targets.push(enemy) if enemy != nil
      when 2
        targets = get_enemies
      when 3
        friend = get_nearest_friend
        friend = $ABS.actor if !friend
        friend = friend.hp/friend.maxhp*1.00 < $ABS.actor.hp/$ABS.actor.maxhp*1.00 ? friend : $ABS.actor if heal and !friend
        friend = $ABS.actor if !friend
        targets.push(friend)
      when 4
        targets = get_friends
        targets.push($ABS.actor)
      when 7
        targets.push($ABS.actor)
      end     
      for target in targets
        target_event = target == $ABS.actor ? $game_player : $game_map.events[target.event_id]
        targets.delete(target) if !$ABS.check_range($game_player, target_event, skill.range)
        targets.delete(target) if !$ABS.check_facing($game_player, target_event, skill.scope)
      end
      return if targets == []
      $ABS.actor.sp -= skill.sp_cost
      for target in targets
        target.skill_effect($ABS.actor, skill)
        target_event = target == $ABS.actor ? $game_player : $game_map.events[target.event_id]
        $ABS.animate($game_player, event.page.graphic.character_name + '-cast',
          event.direction/2, 4, 3, 0) if $ABS.e_animations
        sprite = nil
        for spr in $scene.spriteset.character_sprites
          sprite = spr if spr.character == target_event
        end
        sprite.damage(target.damage, target.critical) if sprite
        successful_hit($ABS.actor, [target], skill)
        if target != $ABS.actor and [1, 2].include?(skill.scope)
          target.change_alignment($ABS.actor) if target.alignment == 0
          target.attackers.push($ABS.actor) unless target.attackers.include?($ABS.actor)
        end
      end
      return
    end
    #----------------------------------------------------------------------
    # * Target Finding Methods
    #----------------------------------------------------------------------
    def successful_hit(object = $game_party.actors[0], target = [], skill = nil)
      anim1 = 0; anim2 = 0
      if skill == nil
        anim1 = animation1_id if !$ABS.p_animations
        anim2 = animation2_id
      else
        anim1 = skill.animation1_id if !$ABS.p_animations
        anim2 = skill.animation2_id
      end
      if object.is_a?(Game_Actor)
        $game_player.animation_id = anim1 if !$ABS.p_animations
      else
        event = $game_map.events[object.event_id]
        event.animation_id = anim1 if !$ABS.e_animations
      end
      return if !target
      for tar in target
        next if !tar
        if tar.is_a?(Game_Actor)
          $game_player.animation_id = anim2
          $ABS.animate($game_player, $game_player.character_name + '-hit',
            $game_player.direction/2, 4, 3) if $ABS.p_animations
        else
          event = $game_map.events[tar.event_id]
          event.animation_id = anim2
          $ABS.animate(event, event.page.graphic.character_name + '-hit',
            event.direction/2, 4, 3, 0) if $ABS.e_animations
        end
      end
    end
    #------------------------------------------------------------------------
    def get_friends
      targets = []
      friend = []
      for target in $ABS.enemies.values
        next if targets.include?(target)
        next if target.attackers.include?($ABS.actor)
        next unless [2,3,4,6].include?(target.alignment)
        targets.push(target)
      end
      return targets
    end
    #------------------------------------------------------------------------
    def get_nearest_friend
      distance = []
      targets = []
      targets = get_friends
      for target in targets
        target_event = target == $ABS.actor ? $game_player : $game_map.events[target.event_id]
        x_dis = (target_event.x - $game_player.x).abs
        y_dis = (target_event.y - $game_player.y).abs
        dis = x_dis > y_dis ? x_dis : y_dis
        distance.push(dis)
      end
      for i in 0...distance.size
        if dis == nil
          dis = distance
          target = targets
        end
        if distance < dis
          target = targets
          dis = distance
        end
      end
      return target
    end
    #------------------------------------------------------------------------
    def get_enemies
      targets = []
      # 0 = attack none
      # 1 = attack evil
      # 2 = attack player and good
      # 3 = attack player
      # 4 = attack player and evil
      # 5 = attack good
      # 6 = attack all
      # 7 = attack attacker
      for enemy in $ABS.enemies.values
        next if targets.include?(enemy)
        next if enemy.immortal
        next if enemy.allied
        targets.push(enemy)
      end
      return targets
    end
    #------------------------------------------------------------------------
    def get_nearest_enemy
      distance = []
      targets = []
      targets = get_enemies
      dis = nil
      for target in targets
        target_event = $game_map.events[target.event_id]
        x = (target_event.x - $game_player.x)
        y = (target_event.y - $game_player.y)
        distance.push(x*x+y*y)
      end
      for i in 0...distance.size
        if dis == nil
          dis = distance
          target = targets
        end
        if distance < dis
          target = targets
          dis = distance
        end
      end
      return target
    end
  end
end



enemy
class ABS
  class Enemy < Game_Battler
    attr_accessor :event_id
    attr_accessor :engaged
    attr_accessor :trigger_type
    attr_accessor :trigger
    attr_accessor :cooldown
    attr_accessor :dis_cooldown
    attr_accessor :guarding
    attr_accessor :troop
    attr_accessor :find_range
    attr_accessor :attack_range
    attr_accessor :help
    attr_accessor :run
    attr_accessor :alignment
    attr_accessor :reaction
    attr_accessor :allied
    attr_accessor :attackers
    #--------------------------------------------------------------------
    # * Initialize Handlers
    #--------------------------------------------------------------------
    # Handles setting up all the stats and information needed by the ABS
    #--------------------------------------------------------------------
    def initialize(monster_id)
      super()
      @event_id = 0
      @enemy_id = monster_id
      @trigger_type = nil
      @trigger = nil
      @engaged = false
      @guarding = false
      @cooldown = 0
      @dis_cooldown = 0
      @move_type = 0
      @move_frequency = 0
      @move_speed = 0
      @hp = maxhp
      @sp = maxsp
      @troop = nil
      @find_range = 7
      @attack_range = 1
      @help = false
      @run = 0
      @alignment = 0
      @reaction = 1
      @target = nil
      @allied = false
      @target_event = nil
      @attackers = []
    end
    #--------------------------------------------------------------------
    # * Enemy Artificial Intelligence
    #--------------------------------------------------------------------
    # Handles the enemy's decision making and priorities.
    #--------------------------------------------------------------------
    def check_ai
      return false if @cooldown != 0
      get_new_target unless $ABS.enemies.values.include?(@target)
      disengage if !@target
      engage_troops if @help
      return true if check_states
      return false unless @engaged
      action = choose_action
      if action.kind == 0
        case action.basic
        when 0
          return true if check_melee_attack
        when 1
          @guarding = true
          return true
        when 2
          return false
        when 3
          return true
        end
      else
        return true if check_cast_spell(action.skill_id)
      end
      return false
    end
    #--------------------------------------------------------------------
    def choose_action
      rating = 0
      actions = []
      for action in $data_enemies[@enemy_id].actions
        if action.kind == 1
          next unless skill_can_use?(action.skill_id)
          next if [3,4].include?($data_skills[action.skill_id].scope) and $data_skills[action.skill_id].plus_state_set == []
        end
        rating += action.rating
        actions.push(action)
      end
      for action in actions
        if action.rating >= rand(rating)
          return action
        else
          rating -= action.rating
        end
      end
      return
    end
    #--------------------------------------------------------------------
    def set_skills
      skills = []
      for action in $data_enemies[@enemy_id].actions
        next if action.kind == 0
        skill = $data_skills[action.skill_id]
        next unless skill_can_use?(skill.id)
        skills.push(skill) if (skill.power < 0 or (skill.power == 0 and skill.minus_state_set.size > 0)) and [3, 4, 7].include?(skill.scope)
      end
      return skills
    end
    #--------------------------------------------------------------------
    def check_states
      skills = set_skills
      targets = get_friends
      use_heal = false
      current = nil
      heal = false
      heal_hp = 0
      heal_one = false
      usable_skills = []
      usable_targets = []
      final_targets = []
      states_healed = []
      return false if skills.size == 0
      return false if targets.size == 0
      for target in targets
        if target.hp <= target.maxhp * 0.25
          heal_hp += target.hp/target.maxhp * 1.00
          usable_targets.push(target)
          use_heal = true
          next
        end
        heal_hp /= usable_targets.size if usable_targets.size > 0
        if target.states.size > 0 and not use_heal
          for skill in skills
            next if skill.power < 0
            next if skill.minus_state_set.size == 0
            for minus_state in skill.minus_state_set
              next unless target.state?(minus_state)
              usable_targets.push(target)
            end
          end
        end
      end
      return false if usable_targets.size == 0
      if use_heal
        if usable_targets.size == 1
          if usable_targets == [self]
            for skill in skills
              next if skill.power == 0
              if skill.scope == 7
                usable_skills.push(skill)
                heal = true
              end
            end
          end
          unless heal
            for skill in skills
              next if skill.power == 0
              if skill.scope == 3
                usable_skills.push(skill)
                heal = true
              end
            end
          end
        end
        unless heal
          for skill in skills
            next if skill.power == 0
            if skill.scope == 4
              usable_skills.push(skill)
              heal = true
            end
          end
        end
        unless heal
          for skill in skills
            next if skill.power == 0
            if skill.scope == 3
              usable_skills.push(skill)
              heal_one = true
            end
          end
        end
      else
        if usable_targets.size == 1
          if usable_targets.size == [self]
            for skill in skills
              next unless skill.power == 0
              if skill.scope == 7
                usable_skills.push(skill)
                heal = true
              end
            end
          end
          unless heal
            for skill in skills
              next unless skill.power == 0
              if skill.scope == 3
                usable_skills.push(skill)
                heal = true
              end
            end
          end
        end
        unless heal
          for skill in skills
            next unless skill.power == 0
            if skill.scope == 4
              usable_skills.push(skill)
              heal = true
            end
          end
        end
        unless heal
          for skill in skills
            next unless skill.power == 0
            if skill.scope == 3
              usable_skills.push(skill)
              heal_one = true
            end
          end
        end
      end
      return false if usable_skills.size == 0
      usable_targets = out_of_range(usable_skills, usable_targets)
      return false if usable_targets.size == 0
      if use_heal
        if heal_one
          if usable_targets.include?(self)
            usable_targets = [self]
          else
            target_hp = 99999
            chosen = nil
            for skill in usable_skills
              next if skill.power == 0
              for target in usable_targets
                if target.hp < target_hp
                  chosen = target
                  target_hp = chosen.hp
                end
              end
            end
            heal_hp = chosen.hp/chosen.maxhp*1.00
            usable_targets = [chosen]
          end
        end
        heal_hp *= 4
        for skill in usable_skills
          current = skill if current == nil or ((skill.power.abs * skill.int_f > current.power.abs * current.int_f and heal_hp < 50) or (skill.power.abs * skill.int_f < current.power.abs * current.int_f and heal_hp >= 50))
        end
      else
        if heal_one
          if usable_targets.include?(self)
            usable_targets = [self]
          end
        end
        i =
 
Your last code got cut off because of the character limit.

Maybe make a demo with the script and upload it somewhere? Or post a link to the complete script, where you got it from.
 

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