Feature Conditions

featureConditions1

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.

Download

Script: download here

Installation

Place this script below Materials and above Main

Usage

To add 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.

Important Note on Formulas

Features are accessed during actor initialization. This means that if your condition references an actor, it will be thrown into a recursive loop and your game will crash.

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>

You may also like...

20 Responses

  1. WCouillard says:

    Hey there, I’m looking to activate features based on the condition that the actor has a certain weapon, or armor TYPE equipped (i.e. a lance, a sword, heavy armor, etc.). Earlier in the thread, the same question was asked and answered, but the code provided causes a SystemStack error. ( a.equip_wtype_ok?(WTYPE_ID) )

    That seems like a method that is simply looking to see if the actor CAN equip a certain type of weapon, not if they actually ARE equipped with a weapon of that type, based on the description of the method in Game_BattlerBase. What would be the proper syntax to look for a specific gear type (weapon or armor) and check is item(s) of those types are actually equipped on the actor?

  2. vitortk says:

    i am a noob at ruby so this may be a silly question but how can i use in game variable as the condtion?
    i tried calling it v.V[0001] == 1, but it didn’t work out

  3. Sughayyer says:

    Hi Hime. I know your script evals the conditions for the features. I created a simple snippet to check if someone is in the battle party (and also alive). Obviously I had to create a snippet for that (it just wouldn’t fit the notebox). The check itself works fine, I put it under Game_Interpreter. But when the game runs, I get a NoMethod error. If I don’t add the feature condition and call it from the script call, the script does run. I know it’s because the snippet I made is out of scope, that’s why the NoMethod error, but how can I fix it?

    Sorry for the extra long post, I don’t even know if that’s the right place for it.

    Thanks!

    • Hime says:

      You should be able to put it in the note-box, even if you put it on multiple lines.

      Formulas are executed in the context of the feature, which is kind of useless.
      For your purposes, you may consider putting it inside Game_Battler and then calling it via

      a.in_my_party?(other_ID)
      

      Now you can define the method for both Game_Actor and Game_Enemy and you suddenly have a feature condition that works for both actors and enemies.

  4. Juan says:

    I have put in… (without the spaces after <)

    < feature condition: 1>
    a.mp =1
    < /feature condition>

    < feature condition: 1,2>
    a.mp =2
    < /feature condition>

    < feature condition: 1,2,3>
    a.mp =3
    < /feature condition>

    but it doesnt work as I think it ought to. Instead, as soon as you get 1 mana, you get all features. I want to make it so that the more mana (1,2,3 etc) you currently have, the more features you get. Any help?

    • Hime says:

      Checking for equality is ==, not =. See if using == solves the problem.

      • Juan says:

        Negative, Ghost Rider.
        It is weird too, when I reverse it (mp==3,==2,==1) it results in something else. I think, I will make permstates, each seperate with its own Feature Condition. Clean fix without causing too much issue, lol. Thanks for the response.

  5. Matthew says:

    Question: how do i get a specific feature to show up if the actor/class has a certain ‘weapon type’ equipped? I don’t mean specific weapons, i mean like swords, axes, guns, bows, staves, etc.

    • Hime says:

      Look up the ID of the weapon type in your Terms database and then plug that into this formula:

      a.equip_wtype_ok?(WTYPE_ID)

  6. Sainthell says:

    Sorry about bothering you yet again, but i have a question. How should i make switch conditions? Thanks!

  7. Caveras says:

    Hello there,

    awesome script! Makes a lot of duplicating redundant and as such is always welcome!

    A little contradiction to your writeup, what I found in my project: When tagging multiple features in the way you described (feature condition: x, y, z, …), in my case with a state, it doesn't work and always applies the latest set of features on the state.

    lHowever, when I tag the features alone feature per feature (feature condition: x, then another tag with feature condition: y, etc) it works just fine.

    Of course, could be a minor compatibility issue since I didn't test it on an empty project, but I just thought I'd mention it. Thanks for the sweet script in any case!

    • Hime says:

      Oops, you're right, I wrote it down because I was going to implement it, but I guess I only implemented it in my thoughts.
      I've updated it so that it actually parses multiple ID's.

  8. parafusion says:

    This is a pretty sick function actually. The amount of possibility this brings to the game is immense. I will begin testing it shortly. Thanks!

  1. August 1, 2014

    […] update has been made to the Feature Conditions script. First, I have created a preview image as an attempt to demonstrate what the script does […]

Leave a Reply to Caveras Cancel reply

Your email address will not be published. Required fields are marked *