Read more about advertising your project here
Hexyz Force Encounter System

0 Members and 1 Guest are viewing this topic.

*****
Rep:
Level 82
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Hexyz Force Encounter System
Version: 1.0
Author: cozziekuns
Date: July 11, 2010

Version History


  • <Version 1.0> 07.11.2010 - Original Release

Planned Future Versions

  • None so far, maybe one that reduces the need to event some methods.

Description


Allows you to set up encounters like the ones in Hexyz Force. This means that you can choose to have a severly weakened enemy if you attack them from the back, a normal enemy if you attack them from the front, and an aggro'd enemy if they run into you. It also makes a (sloppy) swing animation that can be called with the keyboard button S by default.

Features

  • Pre-made swing animation. You don't have to go make your own!
  • The ability to set battles for when you attack the enemy in the back, when you swing at them normally, and when they run into you.
  • Allows you to disable some features.
  • Won't affect regular events! So that treasure chest of yours won't spawn a monster(unless it's a Mimic).

Instructions

See header.

Script


Code: [Select]
#===============================================================================
#
# Hexyz Force Encounter System
# Last Date Updated: 7/11/2010
#
# Allows you to set up encounters like the ones in Hexyz Force. This means that
# you can choose to have a severly weakened enemy if you attack them from the
# back, a normal enemy if you attack them from the front, and an aggro'd enemy
# if they run into you. It also makes a (sloppy) swing animation that can be
# called with the keyboard button S by default.
#
#===============================================================================
# Updates
# -----------------------------------------------------------------------------
# o 07/11/10 Started Script.
#===============================================================================
# What's to come?
# -----------------------------------------------------------------------------
# o Nothing! Suggest something.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ? Materials but above ? Main. Remember to save. The
# default button to swing your sword is S.
#
# To make an event, that when hit from any side other than from behind initiates
# a battle with the troop ID of 1, make a comment with:
#
# \enemy_id[1]
#
# To make an event, that when hit behind initiates a battle with the troop ID of
# 2, make a comment with:
#
# \back_enemy_id[2]
#
# To make an event, that when killed activates it's self switch A, make a
# comment with:
#
# \cont_self_switch[A]
#
# When you run into an enemy, a battle does not automatically start (unlike
# in Hexyz Force). Therefore, you will have to event your own method. Where x
# and y represent any number, and z represents any letter from A - D, the event
# template that I use is:
#
# Trigger: Player Touch
#
# @> Comment: \enemy_id[x]
# @> Comment: \back_enemy_id[y]
# @> Comment: \cont_self_switch[z]
# @> Battle Processing: Monster
#    : If Win
#      @> Control Self Switch: z =ON
#    : If Escape
#     
#   @> Branch End
# @>
#
#===============================================================================

$imported = {} if $imported == nil
$imported["HexyzForcEncntSys"] = true

module COZZIEKUNS
  module HFES
    SWING_BUTTON = Input::Y # The button that starts the swing animation
    NO_HIT_SWITCH_ID = 2 # Turn this switch on if you don't want the swing animation to be played when Y is pressed.
  end
end

#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  This class deals with events. It handles functions including event page
# switching via condition determinants, and running parallel process events.
# It's used within the Game_Map class.
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :can_hit
  attr_accessor :was_hit
  attr_accessor :battler_id
  attr_accessor :back_battler_id
  attr_accessor :self_switch_after_kill
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  alias coz_carbs_ge_setup_ipwqu setup
  def setup(new_page)
    coz_carbs_ge_setup_ipwqu(new_page)
    if @page == nil
      @can_hit = false
    else
      i = 0
      comment = ''
      while [108].include?(@page.list[i].code)
        comment += @page.list[i].parameters[0]
        i += 1
      end
      if comment[/\\ENCOUNT_ID\[(\d+)]/i] != nil
        @battler_id = $1.to_i
        @can_hit = true
      end
      if comment[/\\BACK_ENCOUNT_ID\[(\d+)]/i] != nil
        @back_battler_id = $1.to_i
        @can_hit = true
      end
      if comment[/\\CONT_SELF_SWITCH\[(\D)]/i] != nil
        @self_switch_after_kill = $1.to_s
      end
    end
  end
end

#==============================================================================
# ** Sprite_BattleIcon
#------------------------------------------------------------------------------
#  This sprite is a very wasteful piece of code used to display an icon. Yes,
# one icon. It grabs it's ox and oy from the player, and is deemed invisible.
#==============================================================================

class Sprite_BattleIcon < Sprite_Base 
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :actor
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     viewport : viewport
  #--------------------------------------------------------------------------
  def initialize(viewport)
    super(viewport)
    @actor = $game_party.members[0]
    @weapon_icon = $data_weapons[@actor.weapon_id].icon_index
    @weapon_animation = $data_weapons[@actor.weapon_id].animation_id
    @animation_playing = false
    update
    self.visible = false
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    self.bitmap = draw_icon(@weapon_icon)
    self.x = $game_player.screen_x - 14
    self.y = $game_player.screen_y - 24
    self.z = 1000
    case $game_player.direction
    when 2
      if self.visible
        self.x += 32
        self.y += 16
        if self.angle != 92
          self.angle -= 10
          self.ox += 1
          self.oy += 2
        end
      else
        self.angle = 272
        self.ox = 0
        self.oy = 0
        @animation_playing = false
      end
    when 4
      if self.visible
        self.x += 9
        self.y += 27
        if self.angle != -2
          self.angle -= 10
          self.ox += 1
          self.oy += 2
        end
      else
        self.angle = 178
        self.ox = 0
        self.oy = 0
        @animation_playing = false
      end
    when 6
      if self.visible
        self.x += 10
        if self.angle != -182
          self.angle -= 10
          self.ox += 1
          self.oy += 2
        end
      else
        self.angle = -2
        self.ox = 0
        self.oy = 0
        @animation_playing = false
      end
    when 8
      if self.visible
        self.z = 100
        if self.angle != -92
          self.angle -= 10
          self.ox += 1
          self.oy += 2
        end
      else
        self.angle = 88
        self.ox = 0
        self.oy = 0
        @animation_playing = false
      end
    end
    if self.visible
      case $game_player.direction
      when 2
        for i in $game_map.events.keys.sort
          if $game_map.events[i].x == $game_player.x and $game_map.events[i].y == $game_player.y + 1 and @animation_playing == false
            if $game_map.events[i].can_hit
              $game_map.events[i].animation_id = @weapon_animation
              $game_map.events[i].was_hit = true
              @animation_playing = true
            end
          end
        end
      when 4
        for i in $game_map.events.keys.sort
          if $game_map.events[i].x == $game_player.x - 1 and $game_map.events[i].y == $game_player.y and @animation_playing == false
            if $game_map.events[i].can_hit
              $game_map.events[i].animation_id = @weapon_animation
              $game_map.events[i].was_hit = true
              @animation_playing = true
            end
          end
        end
      when 6
        for i in $game_map.events.keys.sort
          if $game_map.events[i].x == $game_player.x + 1 and $game_map.events[i].y == $game_player.y and @animation_playing == false
            if $game_map.events[i].can_hit
              $game_map.events[i].animation_id = @weapon_animation
              $game_map.events[i].was_hit = true
              @animation_playing = true
            end
          end
        end
      when 8
        for i in $game_map.events.keys.sort
          if $game_map.events[i].x == $game_player.x and $game_map.events[i].y == $game_player.y - 1 and @animation_playing == false
            if $game_map.events[i].can_hit
              $game_map.events[i].animation_id = @weapon_animation
              $game_map.events[i].was_hit = true
              @animation_playing = true
            end
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Icon
  #     icon_index : Icon number
  #--------------------------------------------------------------------------
  def draw_icon(icon_index)
    bitmap = Bitmap.new(24, 24)
    cache = Cache.system("Iconset")
    rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
    bitmap.blt(0, 0, cache, rect, 255)
    return bitmap
  end
end

#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
#  This class brings together map screen sprites, tilemaps, etc. It's used
# within the Scene_Map class.
#==============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :attack_icon_visible         
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias coz_hfes_sm_initialize initialize
  def initialize
    @attack_icon_visible = false
    create_viewports
    create_tilemap
    create_parallax
    create_characters
    create_shadow
    create_weather
    create_pictures
    create_timer
    @attack_icon = Sprite_BattleIcon.new(@viewport1)
    update
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  alias coz_hfes_sm_dispose dispose
  def dispose
    coz_hfes_sm_dispose
    @attack_icon.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias coz_hfes_sm_update update
  def update
    coz_hfes_sm_update
    update_attack_icon
  end
  #--------------------------------------------------------------------------
  # * Update Attack Icon
  #--------------------------------------------------------------------------
  def update_attack_icon
    @actor = $game_party.members[0]
    @attack_icon.actor = @actor
    @attack_icon.visible = @attack_icon_visible
    @attack_icon.update
  end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Wait a set amount of time
  #     duration : Wait time (number of frames)
  #     no_fast  : Fast forward disabled
  #    A method for inserting a wait during scene class update processing.
  #    As a rule, update is called once for each frame, but during maps it
  #    can be difficult to grasp the processing flow, so this method is used
  #    as an exception.
  #--------------------------------------------------------------------------
  def wait(duration, no_fast = false)
    for i in 0...duration
      update_basic
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias coz_carbs_sm_update_90was update
  def update
    coz_carbs_sm_update_90was
    unless $game_switches[COZZIEKUNS::HFES::NO_HIT_SWITCH_ID]
      if Input.trigger?(COZZIEKUNS::HFES::SWING_BUTTON)
        @spriteset.attack_icon_visible = true
        wait(30)
        @spriteset.attack_icon_visible = false
        for i in $game_map.events.keys.sort
          if $game_map.events[i].can_hit
            case $game_player.direction
            when 2
              if $game_map.events[i].was_hit
                if $game_map.events[i].direction == 2
                  troop_id = $game_map.events[i].back_battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                else
                  troop_id = $game_map.events[i].battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                end
              end
            when 4
              if $game_map.events[i].was_hit
                if $game_map.events[i].direction == 4
                  troop_id = $game_map.events[i].back_battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                else
                  troop_id = $game_map.events[i].battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                end
              end
            when 6
              if $game_map.events[i].was_hit
                if $game_map.events[i].direction == 6
                  troop_id = $game_map.events[i].back_battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                else
                  troop_id = $game_map.events[i].battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                end
              end
            when 8
              if $game_map.events[i].was_hit
                if $game_map.events[i].direction == 8
                  troop_id = $game_map.events[i].back_battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                else
                  troop_id = $game_map.events[i].battler_id
                  if $data_troops[troop_id] != nil
                    $game_troop.setup(troop_id)
                    $game_troop.can_escape = true
                    $game_temp.battle_proc = Proc.new{}
                    $game_temp.next_scene = "battle"
                  end
                  if i > 0
                    key = [$game_map.map_id, i, $game_map.events[i].self_switch_after_kill]
                    $game_self_switches[key] = true
                  end
                  $game_map.need_refresh = true
                end
              end
            end
          end
        end
      end
    end
  end
end

Credit


  • cozziekuns

Thanks

  • Valdred/Modern Algebra, for a certain trick with event comments.
  • Zeriab, for his Regular Expressions in RGSS tutorial.

Support


Just post down below.

Known Compatibility Issues

None so far.

Demo


See attached.

Author's Notes


To all Americans: Did you get your free slurpee today?

Restrictions

:ccbyncsa:
« Last Edit: July 21, 2010, 02:44:41 AM by cozziekuns »

*
Rep:
Level 95
2012 Favorite Staff Member2012 Most Mature Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best RPG Maker User (Scripting)2011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best Use of Avatar and Signature Space2010 Favourite Staff Member2010 Most Mature Member2010 Best RPG Maker User (Scripting)2010 Best Use Of Avatar And Signature Space
Cool. Why did you lock it?

*****
Rep:
Level 82
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
It was locked?

EDIT: Lol woops.