Jump to content
_Tim_

Making an armour ineffective with high hp

Recommended Posts

Hey, so i would like to make an accessory that boost your defense but only when you have low hp.

I would like the item to have high stats, but those stats would only be active while having low hp, when the user's hp are not let's say below 25% the accessory doesn't provide any stats bonuses.

How would i go about that?

 

Share this post


Link to post
Share on other sites

Well, I think this script is one of the most useful scripts I know of for doing stuff like that. It works using states so you couldn't exactly give items conditional stats that way, but you can have a state that boosts defense by 200% or something. I am not sure if there are any existing scripts that might be more suited to directly fiddling with an item's stats based on a condition.

Share this post


Link to post
Share on other sites

I would recommend Hime Feature Conditions.

Add a feature that raises defense and attack. Set the condition to something like

   <feature condition: 2, 3>
      $game_actors[@actor_id].hp <= (0.25 * $game_actors[@actor_id].mhp)
   </feature condition>

 

Not sure if that formula is good or not. try it out

Share this post


Link to post
Share on other sites

True, the features for equipment does not allow for specific stats, only percentages. 

The only way I see around this is either use passive skills linked to the armor, and use common events to add on the stats, or

Ask to have a script made that will convert the % bonus to + values.

 

*edit - I'm looking at Hime Feature conditions add param script. It almost does what we need.

I wonder if an addon can be made for it that will check the feature -> save the value -> remove the feature -> add the stat by value

 

*edit 2

This thread needs to be moved as well. It is not a script.

 

I found that Hime Feature conditions work with the add param addon.

I was just not able to get it to understand mhp.

I was able to set a formula like so...

<cond_ft: add_param "a.hp <= a.mp" atk 5>

I could also use values

<cond_ft: add_param "a.hp <= 200" atk 5>

but if I tried

<cond_ft: add_param "a.hp <= a.mhp" atk 5>

 

It would give me a stack level too deep error.

 

So this may work for the OP but I don't know what ruby expression can be used to specify 25% of mhp.

 

It changed the atk on the fly in battle as well.

 

*Edit 3

So it works with a variable. I set a autorun to gather the actors mhp.

Then used the variable in the formula

<cond_ft: add_param "a.hp <= v[37] * 0.75" atk 5>

 

Works. but you would have to use variables for each actor and a new line for each variable in the note box.

Edited by roninator2

Share this post


Link to post
Share on other sites

Thanks a lot.

I think using a different variable for each actor would be way to tedious for me,

also, i've tried understanding the script a bit and i have very poor attention,

so going quickly i don't get why you can't just do:

 

<feature condition>
    a.hp <= a.mhp * 0.25
<\feature condition>

 

Edit: i've made i chart of how i think it works

image.png.438bf34649deb7a0a1076321c9e6cb4e.png

It's in french but i think you get the idea

Edited by _Tim_

Share this post


Link to post
Share on other sites

okay!

I've tried to toy around with the notebox so here's what i came up with:

 

<feature condition>
a.hp <= 300
</feature condition>

 

i've tried to use a flat number just to test it out.

So now the issue is that the conditions applies when the combat starts, but the features won't update when the conditions are met

Edited by _Tim_
typo

Share this post


Link to post
Share on other sites

YES! Finally i've got it to work!

so here's the notetag:

 

<feature condition: 1>
a.hp <= (a.mhp * 0.25)
</feature condition>

 

The first Top feature is a defense boost.

 

1487384673_Sanstitre-3.png.fa39e59cdede307a07e61b797eea9420.png

 

YOU'LL NEED THIS SCRIPT:

=begin
#===============================================================================
 Title: Feature Conditions
 Author: Hime
 Date: Nov 22, 2014
--------------------------------------------------------------------------------
 ** Change log
 Nov 22, 2014
   - fixed bug where conditions were always false
 Nov 14, 2014
   - added checks to prevent recursive calls
 Jul 10, 2014
   - added support for tagging multiple features in one note-tag
 Jul 9, 2014
   - added support for individual features
 Jul 16, 2013
   - Initial release
--------------------------------------------------------------------------------   
 ** Terms of Use
 * Free to use in non-commercial projects
 * Contact me for commercial use
 * No real support. The script is provided as-is
 * Will do bug fixes, but no compatibility patches
 * Features may be requested but no guarantees, especially if it is non-trivial
 * Credits to Hime Works in your project
 * Preserve this header
--------------------------------------------------------------------------------
 ** Description
 
 This script allows you to add "feature conditions" to any objects that hold
 features. These conditions are used to control whether the features from an
 object are applied to your actor or not.
 
 For example, suppose you have shield equips that have special elemental
 immunities when the "guard" state is applied. You can add these features to
 the shield and then use feature conditions to indicate that the "guard" state
 must be applied before the features are transferred.
 
 Feature conditions can be applied at the object level, which means all
 conditions must be met for any features to be applied.
 
 Feature conditions can also be applied at the feature level, which provides
 finer control over when specific features can be applied.

--------------------------------------------------------------------------------
 ** Installation
 
 Place this script below Materials and above Main

--------------------------------------------------------------------------------
 ** Usage 
 
 To add a feature conditions, use the notetag for any objects with features,
 such as Actors, Classes, Weapons, Armors, Enemies, or States. If you are using
 the Feature Manager, then it will be applied to skills and items as well.
 
 == Object-level feature conditions ==
 
 For object-level conditions, use the note-tag of the form
 
   <feature condition>
      FORMULA
   </feature condition>
   
 For any valid ruby formula that returns true or false.
 Three variables are available for your convenience:
 
   a - subject the feature applies to
   s - game switches
   v - game variables
   
 By "subject" I refer to "actor" or "enemy". For example, a state can be applied
 to both actors or enemies, so if the enemy has the state, then that enemy is
 the subject. If the actor has the state, then that actor is the subject. Be
 careful when writing your formulas.
 
 == Feature-level conditions ==
 
 Applying conditions to individual features is the same as object-level
 conditions, except in the note-tag you specify which feature it applies to
 
   <feature condition: x>
     FORMULA
   </feature condition>
  
   <feature condition: x, y, ... >
     FORMULA
   </feature condition>
   
 Where x and y are the ID's of the features. The ID of the feature is based on
 its position in the list, so the feature at the top of the list has ID 1, the
 next one has ID 2, and so on.
 
 You can specify multiple ID's by separating them with commas.
   
--------------------------------------------------------------------------------
 ** Examples
 
 Here are some quick examples of some conditions you might have
 
 * Feature 2 and 3 are applied only if the party has more than 5000 gold
 
   <feature condition: 2,3 >
     $game_party.gold > 5000
   </feature condition>
     
 * Features of the object are only applied if state 23 is applied
 
   <feature condition>
     a.state?(23)
   </feature condition>
  
#===============================================================================
=end
$imported = {} if $imported.nil?
$imported["TH_FeatureConditions"] = true
#===============================================================================
# ** Configuration
#===============================================================================
module TH
  module Feature_Conditions
    Regex = /<feature[-_ ]condition>(.*?)<\/feature[-_ ]condition>/im
    Ft_Regex = /<feature[-_ ]condition:\s*(.*?)\s*>(.*?)<\/feature[-_ ]condition>/im
  end
end
#===============================================================================
# ** Rest of Script
#===============================================================================
module RPG
  class BaseItem
    def feature_conditions_met?(subject)
      load_notetag_feature_conditions unless @feature_conditions_loaded
      return eval_feature_conditions(subject)
    end
    
    def load_notetag_feature_conditions
      @feature_conditions_loaded = true
      conditions = "true"
      res = self.note.scan(TH::Feature_Conditions::Regex)
      res.each_with_index do |cond, i|
        conditions << " && " if i > 0
        conditions << cond[0]
      end
      build_condition_method(conditions.empty? ? "true" : conditions)      
      load_notetag_individual_feature_conditions
    end
    
    def load_notetag_individual_feature_conditions
      results = self.note.scan(TH::Feature_Conditions::Ft_Regex)
      results.each do |res|
        ids = res[0].strip.split(",")
        ids.each do |id|
          id = id.to_i - 1
          @features[id].feature_condition = res[1]
        end
      end
    end
    
    #---------------------------------------------------------------------------
    # Builds the condition-checking method. This is done for performance
    # reasons since features are checked several hundred times very frequently.
    # It assumes the conditions do not change dynamically once they have been
    # loaded.
    #---------------------------------------------------------------------------
    def build_condition_method(conditions)
      eval(
        "def eval_feature_conditions(a, v=$game_variables, s=$game_switches)
           #{conditions}
         end"
      )
    end
  end
  
  class BaseItem::Feature
    attr_accessor :feature_condition
    
    def feature_condition_met?(subject)
      return true unless @feature_condition
      eval_feature_condition(subject)
    end
    
    def eval_feature_condition(a, v=$game_variables, s=$game_switches)
      eval(@feature_condition)
    end
  end
end

class Game_BattlerBase
  
  def feature_conditions_met?(obj, subject)
    obj.feature_conditions_met?(subject)
  end
  
  alias :th_feature_conditions_all_features :all_features
  def all_features    
    return [] if @feature_eval_checking
    @feature_eval_checking = true
    fts = th_feature_conditions_all_features.select {|ft| ft.feature_condition_met?(self)}
    @feature_eval_checking = false
    return fts
  end
end

class Game_Actor < Game_Battler
  
  alias :th_feature_conditions_feature_objects :feature_objects
  def feature_objects
    fts = th_feature_conditions_feature_objects.select {|obj|
      feature_conditions_met?(obj, self)
    }
    return fts
  end
end

class Game_Enemy < Game_Battler
  
  alias :th_feature_conditions_feature_objects :feature_objects
  def feature_objects
    fts = th_feature_conditions_feature_objects.select {|obj|
      feature_conditions_met?(obj, self)
    }
    return fts    
  end
end

I'm documenting as much as possible for people like me who don't understand everything that well.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×