Save-Point
KEnemyStates XP - 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 XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: KEnemyStates XP (/thread-10793.html)



KEnemyStates XP - kyonides - 10-31-2024

KEnemyStates XP

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 XP * #
#   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_btl_end :battle_end
  def battle_end(result)
    kyon_enemy_state_btl_end(result)
    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