Save-Point
KEnemyStates VX + ACE - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker VX/VXAce (RGSS2/3) Engines (https://www.save-point.org/forum-117.html)
+---- Thread: KEnemyStates VX + ACE (/thread-10794.html)



KEnemyStates VX + ACE - kyonides - 10-31-2024

KEnemyStates VX + ACE

by Kyonides

Introduction

This scriptlet simply lets you set a given state to any enemy by passing the enemy position and a state ID or name to the KEnemy.set_state method.

The Script

Code:
# * KEnemyStates VX + ACE * #
#   Scripter : Kyonides
#   v0.3.0 - 2024-10-30

# * Script Call * #

# - Set a State, Requires an Index (1 through MAX) & a State ID or Name
# KEnemy.set_state(EnemyIndex, State ID or Name)

module KEnemy
  extend self
  attr_reader :states
  def set_state(enemy_pos, id_or_name)
    id_or_name = get_state_id(id_or_name) if id_or_name.is_a?(String)
    @states[enemy_pos - 1] = id_or_name if id_or_name
  end

  def get_state_id(name)
    regex = /#{name.downcase}/i
    state = $data_states.find {|state| state.name[regex] }
    state ? state.id : nil
  end

  def clear_states
    @states = {}
  end
  clear_states
end

class Game_Temp
  alias :kyon_enemy_state_gm_tmp_init :initialize
  def initialize
    kyon_enemy_state_gm_tmp_init
    $data_states[0] ||= RPG::State.new
  end
end

class Game_Troop
  alias :kyon_enemy_state_gm_trp_setup :setup
  def setup(troop_id)
    kyon_enemy_state_gm_trp_setup(troop_id)
    KEnemy.states.each {|pos, sid| @enemies[pos].add_state(sid) }
  end
end

class Scene_Battle
  alias :kyon_enemy_state_scn_btl_term :terminate
  def terminate
    kyon_enemy_state_scn_btl_term
    KEnemy.clear_states
  end
end


Terms & Conditions

Free for non commercial games.
Due credit is mandatory.
Mention this forum as well.
That's it! Tongue sticking out