Scope Conditions

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

This script allows you to specify a scope condition for your items and skills.

A scope condition is a formula that is used to determine whether a skill
or item has an effect on a target or not. If it has no effect on a target then
the action does not do anything to that target.

scopeConditions1

Download

Script: download here

Installation

Place this script below Materials and above Main

Usage

Note-tag skills/items with

<scope condition: formula />

Where the formula is some valid ruby statement.
The following variables are available for your formula

a - current attacker
b - target
f - friends unit
o - opponents unit
v - game variables
s - game switches

The target is all of the targets that the skill/item can affect. For example,
if a skill affects all enemies, then b will be replaced with each enemy
during action execution.

The f and o variables depend on who the current attacker is.
If the attacker is an actor, then the friends unit is the game party.

Examples

Some example scope conditions

<scope condition: b.level % 5 == 0 />
   -targets with levels that are multiples of 5

<scope condition: b.state.include?(23) />
   -targets with state 23 applied

<scope condition: b.name =~ /slime/i />
   -targets with the word "e" in their name (case-insensitive)

<scope condition: b.hp > (b.mhp / 2) />
   -targets with more than 50% of their max HP
Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

You may also like...

39 Responses

  1. Aggron says:

    Say I have a skill that normally hits only one target. I would like to set it up so that the same skill will instead hit all enemies if the user has a specific state (let’s say Poison, or State ID 2 by default). Is such a thing possible with this script? If so, what would the scope condition look like?

    • Hime says:

      Unfortunately, the conditions only apply to the targets based on the scope of the skill. It doesn’t allow you to change the actual scope of the skill.

  2. Wavelength says:

    Hi Hime – wanted to report a bug in this script.

    Using the right-carat character ” > ” in a condition seems to end the tag early, often resulting in a TRUE evaluation where it’s not intended. For instance, your “greater than half HP” example above ( [scope condition: b.hp > (b.mhp / 2)] ) does not work and will always evaluate to TRUE in my tests.

    This can be worked around by using < and ! in its place; for example [scope condition: !(b.hp <= (b.mhp / 2))] so it’s not a critical issue – but I think this should at least be documented in the instructions.

    Thanks for the great script!

    (Replaced all > < carats with ] [ brackets so the post doesn’t become faulty.)

    • Hime says:

      I’ve updated the script so that you close the note-tag with /> instead of just >

      • Wavelength says:

        Just did a simple test with the new version and it’s working well – thank you for the fix!

        • Hime says:

          It is still not foolproof in the sense that if you had the string /> anywhere in your formula, it would still cut it off prematurely. This could appear in regular expressions for example if you wanted to match on something that starts with > symbol.

          Alternatively, I could provide a note-tag that looks like this
          <scope condition>
          FORMULA HERE
          </scope condition>

          Which would then reduce the possiblity that it will be cut off prematurely.

  3. Juan says:

    How would I have it affect all enemies with the same name as the target?
    Target a slime only slimes affected, but if I target a goblin, only goblins affected? Any ideas if thats possible?

  4. Juan says:

    I read (mostly) the comments left and didnt see what I was looking for. How would I use this to target any enemy and all enemies that are named the same as that enemy. So, I target a slime and all other slimes are targeted as well. I would be willing to give each creature type a state so that the are labeled, if that helps. I need a skill that only chains to the target and other creatures of the same name… thoughts?

    • Hime says:

      b.name gives the target’s name. b.original_name gives the name without the extra letter appended. The problem here is that the scope condition checks whether the target is valid or not, so you will need to store the name somewhere before the condition check occurs as you don’t have reference to the first target after the skill is executed.

      You may be able to use pre-skill effects which allows you to execute an effect before the skill itself is executed along with formula effects which allows you to execute a formula as the effect.

      The effect you might execute may be something like

      $game_variables[10] = b.original_name

      And then your scope condition will check the variable

      b.name.include?($game_variables[10])

  5. Matthew says:

    In terms of 'passive states' applied to enemies to identify a certain monster type, this would allow a skill to function like 'Dia' spells from Final Fantasy I, right?

  6. rubydragon44 says:

    But enemies don't consider this effect, is what I mean.
    I'm okay with the fact that it's about affecting someone and not about targeting or not targeting.
    I know that you can still target anyone using this script. But only the player knows not to use a move against someone who's conditions they don't meet.
    Even when I set them to autobattle, normally enemies use moves that are going to be the most useful, yet they don't see a false in a scope condition to be a consideration of how useful a move is.

  7. rubydragon44 says:

    I'm confuzzled.
    I was trying a Triple Battle System where the members on the left can't hit the enemies on the right and the members on the right can't hit the enemies on the left with most skills
    So my condition was
    scope condition: if a.state?(187); !b.state?(189); end; if a.state?(189); !b.state?(187); end; and nothing happened and I also tried
    a.state?(187) ? !b.state?(189) : a.state?(189) ? !b.state?(187) which that gave me an error

    • Hime says:

      You need to explain what your condition is supposed to mean.

      • rubydragon44 says:

        Oops. I'm sorry. facepalm If user has Left state (187) then target can't have Right state (189). If user has Right state (189), then target can't have Left state (187).

      • rubydragon44 says:

        Okay, I got it.
        scope condition: (a.state?(187) && !b.state?(189)) or (a.state?(189) && !b.state?(187)) or (a.state?(188)) or (!a.state?(187) && !a.state?(188) && !a.state?(189))
        So user has Left and target does not have Right, or Target has Right and target does not have Left, or user has Middle, or user does not have a position.
        :3
        And such works.

        • Hime says:

          Glad to see you've got it sorted out. Presumably when you were asked to explain yourself, you had to think about how you were going to phrase it in a coherent way, which typically means it has to be somewhat logical.

          • rubydragon44 says:

            🙂 Yup.
            There's a problem though. I'm not sure if I should put it on Bithub instead.
            Enemies don't consider the Scope Conditions in their actions.
            That means that an enemy on the right side will try to attack an actor on the left side and fail.

            I also know that there is http://www.himeworks.com/2014/02/23/enemy-action-conditions/
            but I would also wonder if there's a way to have enemies automatically take Scope Conditions into consideration.

          • Hime says:

            This script is not intended to determine whether you can select someone as a target or not, it simply determines whether it has any effect on the target or not.

            Your actors should still be able to pick one of the enemies that it shouldn't be targeting, as a target.

            Another script will be required to actually change who you can target.

    • rubydragon44 says:

      I also tried
      scope condition: (!a.state?(187) && !b.state?(189)) && (!a.state?(189) && !b.state?(187)) which lead to nothing happening

  8. KaizoVorna says:

    You mean Scope Condition? There wasn’t one. It started working properly only when I DID give it a Scope Condition.

  9. KaizoVorna says:

    Some sort of very bizarre error is popping up on line 100 of the script. I was fighting an enemy that just happens to have a skill that utilizes this script, everything goes without a hitch UNTIL the enemy uses its last attack before dying. (No other scripts involved in the process, just good ol’ Immortal until at 0% HP then use Skill that Does Not Utilize Target Scopes and remove Immortal afterwards so it dies.) The script causes the game to inexplicably crash at that particular enemy. (And no other enemy that also has final attacks as far as I know.) All I have is the fact that the enemy was paralyzed when it died, so could inability to act or something else cause a bug with it?

    • KaizoVorna says:

      Addendum: Nope, it’s not about the paralysis. Same thing happens normally too.
      It says “Script ‘Tsukihime_Scope_Conditions line 101 NoMethodError occured. undefined method ‘scope_condition_met?’ for nil:NilClass”

  10. Cristian says:

    I want to make some enemies (mostly bosses) to certain attack, to make this I want to make if certain switch is OFF the enemy could be target of this attack, how do I make this?

  11. Maliki79 says:

    UPDATE: I kinda figured it out. The reason it wasn’t working was because I was looking for a state which was listed as a Permastate (Thank you for that script as well). So, what would be the syntax for looking for a Permastate? (Looking for a “normal” state does work ok.)

  12. Maliki79 says:

    Hello TH.
    I’m trying to get this script to work via current states, but it’s not working.
    The formula I use is

    b.state?(n)

    where n is the state I’m checking for.
    Is this correct?
    Also, I don’t know if this matters, but I’m trying to use items from the menu outside of battle.

    Thanks for the assistance.

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax