# ╔═══════════════════════════════════════════════╦════════════════════╗
# ║ Title: Actor/Class Feature Lock ║ Version: 1.00 ║
# ║ Author: Roninator2 ║ ║
# ╠═══════════════════════════════════════════════╬════════════════════╣
# ║ Function: ║ Date Created ║
# ║ ╠════════════════════╣
# ║ Alter feature control with conditions ║ 16 Jun 2025 ║
# ╚═══════════════════════════════════════════════╩════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Requires: nil ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Brief Description: ║
# ║ Prevent locked features from applying ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Instructions: ║
# ║ ║
# ║ Put note tag on class note box in order to block ║
# ║ a feature unless the condition is true ║
# ║ <feature restrict: feature_id,method,value,condition> ║
# ║ example ║
# ║ <class feature restrict: 2,st,15> ║
# ║ <class feature restrict: 4,sw,50> ║
# ║ <class feature restrict: 5,v,21,gt,5> ║
# ║ <class feature restrict: 5,v,21,lt,5> ║
# ║ Feature lists starts at 0 ║
# ║ ║
# ║ Available conditions: ║
# ║ st - state (state must be inflicted) ║
# ║ sw - switch (switch must be on) ║
# ║ v - variable (gt = greater than, lt = less than) ║
# ║ ║
# ║ Numbers: ║
# ║ st,15 - state 15 is inflicted ║
# ║ sw,50 - switch 50 is true ║
# ║ v,21,gt,5 - variable 21 is equal to or greater than 5 ║
# ║ ║
# ║ The effect: ║
# ║ All features on the actor will not work ║
# ║ Only features not in the notetag will be available ║
# ║ Features that are referenced in the note tag ║
# ║ will be used or added to the actor when the ║
# ║ condition is true. ║
# ║ ║
# ║ Same options are availablefor the Actor as well ║
# ║ <actor feature restrict: 2,st,15> ║
# ║ <actor feature restrict: 4,sw,50> ║
# ║ <actor feature restrict: 5,v,21,gt,5> ║
# ║ <actor feature restrict: 5,v,21,lt,5> ║
# ║ Put note tag on actor note box in order to block ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Updates: ║
# ║ 1.00 - 22 Jul 2022 - Created script with help from Tsukihime code ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Credits and Thanks: ║
# ║ Roninator2 ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Terms of use: ║
# ║ Follow the original Authors terms of use where applicable ║
# ║ - When not made by me (Roninator2) ║
# ║ Free for all uses in RPG Maker except nudity ║
# ║ Anyone using this script in their project before these terms ║
# ║ were changed are allowed to use this script even if it conflicts ║
# ║ with these new terms. New terms effective 03 Apr 2024 ║
# ║ No part of this code can be used with AI programs or tools ║
# ║ Credit must be given ║
# ╚════════════════════════════════════════════════════════════════════╝
module R2_Class_Feature_Adjust
Lock_Actor_Feature = /<actor[ _-]feature[ _-]restrict:[ ](\w+(?:\s*,\s*\w+)*)>/i
Lock_Class_Feature = /<class[ _-]feature[ _-]restrict:[ ](\w+(?:\s*,\s*\w+)*)>/i
end
module DataManager
class <<self
alias load_database_original_r2_class_feature_cond_restrict load_database
end
def self.load_database
load_database_original_r2_class_feature_cond_restrict
load_class_restrict_feature_cond
load_actor_restrict_feature_cond
end
def self.load_class_restrict_feature_cond
for obj in $data_classes
next if obj.nil?
obj.load_class_restrict_feature_cond
end
end
def self.load_actor_restrict_feature_cond
for obj in $data_actors
next if obj.nil?
obj.load_actor_restrict_feature_cond
end
end
end
class RPG::Class
attr_accessor :class_feature_restrict
#--------------------------------------------------------------------------
# * Load Class Feature Restrictions
#--------------------------------------------------------------------------
def load_class_restrict_feature_cond
@class_feature_restrict = []
results = self.note.scan(R2_Class_Feature_Adjust::Lock_Class_Feature)
results.each do |res|
data = res[0]
restrict = []
for x in data.split(",")
restrict.push(x)
end
@class_feature_restrict << restrict
end
end
end
class RPG::Actor
attr_accessor :actor_feature_restrict
#--------------------------------------------------------------------------
# * Load Actor Feature Restrictions
#--------------------------------------------------------------------------
def load_actor_restrict_feature_cond
@actor_feature_restrict = []
results = self.note.scan(R2_Class_Feature_Adjust::Lock_Actor_Feature)
results.each do |res|
data = res[0]
restrict = []
for x in data.split(",")
restrict.push(x)
end
@actor_feature_restrict << restrict
end
end
end
class Game_Actor
#--------------------------------------------------------------------------
# * overwrite class features
#--------------------------------------------------------------------------
def feature_objects
super + [process_actor_feature_conditions] + [process_class_feature_conditions] + equips.compact
end
#--------------------------------------------------------------------------
# * New Process Actor Conditions
#--------------------------------------------------------------------------
def process_actor_feature_conditions
@actor_saved_features = []
@actor_original_features = [] if @actor_original_features.nil?
orig = actor
@actor_original_features = orig.features if @actor_original_features.empty?
orig.features = @actor_original_features
@actor_deleted_features = []
@actor_removed_features = []
@actor_removed_features = check_actor_feature_restrict(orig)
@actor_removed_features.each do |ft|
@actor_deleted_features << @actor_original_features[ft]
end
@actor_original_features.each do |ef|
next if ef.nil?
@same = false
code_o = ef.code
data_o = ef.data_id
value_o = ef.value
@actor_deleted_features.each do |df|
next if df.nil?
code_d = df.code
data_d = df.data_id
value_d = df.value
if (code_d == code_o) && (data_o == data_d) && (value_o == value_d)
@same = true
end
end
@actor_saved_features << ef if @same == false
end
orig.features = @actor_saved_features
return orig
end
#--------------------------------------------------------------------------
# * New Check Actor feature restrictions
#--------------------------------------------------------------------------
def check_actor_feature_restrict(orig)
restrict_features = get_feature_restrict(orig.actor_feature_restrict)
return restrict_features
end
#--------------------------------------------------------------------------
# * New Process Class Conditions
#--------------------------------------------------------------------------
def process_class_feature_conditions
@class_saved_features = []
@class_original_features = [] if @class_original_features.nil?
orig = self.class
@class_original_features = orig.features if @class_original_features.empty?
orig.features = @class_original_features
@class_deleted_features = []
@class_removed_features = []
@class_removed_features = check_class_feature_restrict(orig)
@class_removed_features.each do |ft|
@class_deleted_features << @class_original_features[ft]
end
@class_original_features.each do |ef|
next if ef.nil?
@same = false
code_o = ef.code
data_o = ef.data_id
value_o = ef.value
@class_deleted_features.each do |df|
next if df.nil?
code_d = df.code
data_d = df.data_id
value_d = df.value
if (code_d == code_o) && (data_o == data_d) && (value_o == value_d)
@same = true
end
end
@class_saved_features << ef if @same == false
end
orig.features = @class_saved_features
return orig
end
#--------------------------------------------------------------------------
# * New Check Class feature restrictions
#--------------------------------------------------------------------------
def check_class_feature_restrict(orig)
restrict_features = get_feature_restrict(orig.class_feature_restrict)
return restrict_features
end
#--------------------------------------------------------------------------
# * New Get feature restrictions
#--------------------------------------------------------------------------
def get_feature_restrict(value)
ft_remove = []
value.each do |ftr|
ft = ftr[0].to_i
mt = ftr[1].to_s.downcase
vl = ftr[2].to_i
eq = ftr[3].to_s.downcase
cd = ftr[4].to_i
case mt
when "st", " st"
ft_remove.push(ft) if !state?(vl)
when "sw", " sw"
if $game_switches[vl] == false
ft_remove.push(ft)
end
when "v", " v"
if eq == "gt"
if $game_variables[vl] < cd
ft_remove.push(ft)
end
else
if $game_variables[vl] > cd
ft_remove.push(ft)
end
end
end
end
return ft_remove
end
end