EkuipFeatures ACE

EkuipFeatures ACE

by Kyonides
​

Introduction

This simple scriptlet will allow you to add or remove Equip Types to any given Actor during gameplay at will.
Warning: It uses a couple of script calls to accomplish that.

The Script - Stable Version

Ruby:
# * EkuipFeatures ACE * #
#   Scripter : Kyonides Arkanthes
#   2023-05-10

# This scriptlet will allow you to add or remove Equip Types to
# any given Actor during gameplay at will.

# * Script Calls * #

# - Find an Actor - 2 Methods:
# actor = $game_party.members[Index]
# actor = $game_actors[ActorID]

# - Learn a New Equip Type
# actor.learn_weapon_type(EquipTypeIndex)
# actor.learn_armor_type(EquipTypeIndex)

# - Forget a given Equip Type
# actor.forget_weapon_type(EquipTypeIndex)
# actor.forget_armor_type(EquipTypeIndex)

module Ekuip
  class FeaturesContainer
    attr_reader :features
    def initialize
      @features = []
    end

    def add(type_code, type_id)
      @features << RPG::BaseItem::Feature.new(type_code, type_id)
      @features = @features.uniq{|f| f.data_id }
    end

    def remove(type_code, type_id)
      @features.delete_if{|f| f.same_data?(type_code, type_id) }
    end
  end
end

class RPG::BaseItem::Feature
  def same_data?(type_code, type_id)
    @code == type_code and @data_id == type_id
  end
end

class Game_Actor
  alias :kyon_learn_ekuip_types_gm_act_init :initialize
  alias :kyon_learn_ekuip_types_gm_act_feat_obj :feature_objects
  def initialize(actor_id)
    @weapon_features = Ekuip::FeaturesContainer.new
    @armor_features = Ekuip::FeaturesContainer.new
    kyon_learn_ekuip_types_gm_act_init(actor_id)
  end

  def equip_features
    [@weapon_features] + [@armor_features]
  end

  def feature_objects
    kyon_learn_ekuip_types_gm_act_feat_obj + equip_features
  end

  def learn_weapon_type(type_id)
    @weapon_features.add(FEATURE_EQUIP_WTYPE, type_id)
  end

  def learn_armor_type(type_id)
    @armor_features.add(FEATURE_EQUIP_ATYPE, type_id)
  end

  def forget_weapon_type(type_id)
    @weapon_features.remove(FEATURE_EQUIP_WTYPE, type_id)
  end

  def forget_armor_type(type_id)
    @armor_features.remove(FEATURE_EQUIP_ATYPE, type_id)
  end
end

Warning for Newcomers:

If you only need to make a single call to learn a type, then do this:

Ruby:
$game_actors[10].learn_weapon_type(2)

Terms & Conditions

Free for use in any game.
Include my name in your game credits.
That's it!
Didn't quite work?
Error.PNG
Maintenance Update​

I forgot to turn every feature container into an Array so it could be properly added to the feature_objects list.

Thanks for reporting the bug, @Zahawk. I've been busy as of late and I guess I need to get some sleep as well. XD
Not sure how this script broke a core engine script but
Error.PNG
Second Maintenance Update​

Well, it seems that it was the order those two new instance variables that hold the new features was incorrect. Basically, they should have been loaded BEFORE the original initialize method could be interpreted. The latest installment of my script takes care of that.
Calling the script ingame,

$game_actors[001]
actor.learn_weapon_type(02)

Resulted in this
"
1683700245888.png
Read the instructions In Order. They clearly state that you first create an actor variable. Only then you can use it in the next script calls.

If you only need to make a single call to learn a type, then do this:

Ruby:
$game_actors[10].learn_weapon_type(2)

Of course, make sure any Actor ID exists or it will soon throw an error, crashing the game. 😉

I also added this warning to the main post as a preventive measure.
I found a bug, when "_switch 2_" is activated, "_switch 1_" is activated as well.
What are you talking about? :eswt:
Why do you think my script has anything to do with switches? Or strings like "_switch Number_" at all...
Why aren't you using 2 numbers per call like the previous forumer?

Really, think it through before answering my questions. And don't say you found a bug when the problem might be related to not fully understanding how the script works. 🙁

Original thread: https://forums.rpgmakerweb.com/threads/ekuipfeatures-ace.157392/