Battlers should only use buffs if they have no buff active at the moment

The title actually says it all. I want battlers to buff -e.g. ATK-Buff- only if their ATK-Buff isn't active at the moment. I want to prevent battlers from using the same buff skill over and over again. My goal is that opponents always have a buff active and don't use the buff otherwise. If the buff disappears, the opponents should notice this and cast it again immediately in the next turn.

Thought about doing this with "Turn No" in the database, but I guess this won't work properly if the player interferes their skill pattern (e.g. by using stun).

Sounds simple. Don't know if this can be done in a simple way, though. Any help?
You can use Yanfly's Battle A.I. Core (YEP) for that. Just put the following notetag into the enemy's notes.


<AI Level: 50>
<AI Priority>
User state !== state X: SKILL Y, User
</AI Priority>


X is your ATK-Buff-State and Y is the skill that applies the ATK-Buff.
Replace X and Y with the exact name or ID-number in the database

With this, the enemy has a 50% chance each turn to cast the ATK-Buff, but ONLY if he does not already have the buff. If the skill is not used, the enemy will go back to his assigned skills from the database.

You can leave out the "User" from the notetag if the buff can be applied to other allies aswell.

<AI Level: 50>
<AI Priority>
state !== state X: SKILL Y
</AI Priority>
@ScorchedGround Thanks, Scorch. I need it for Vx Ace, though. Your link leads me to an MV plugin.
Oof sorry, that's awkward.
Well I am not very familiar with Ace, so before I tell you any stupid stuff, I'll let someone else help you with this.
No prob, bro.
Los Bumpos
Los Bumpos
Did you forget about the 72 hours rule for bumping?

Sounds like you could do this in the damage formula
a.states.include?(5) ? dam = 100 : a.add_state(5); damage formula + dam; end
or something to that effect
Sounds like you could do this in the damage formula
a.states.include?(5) ? dam = 100 : a.add_state(5); damage formula + dam; end
or something to that effect

Hi, Ronni. Thanks for that. So I have to include this into the damage formula with dam = my damage formula? What is damage formula + dam? I think states.include?(5) refers to the state with state ID 5 but I don't understand any more of this. Mind to explain it to me?
Mind to explain it to me?

I would like to say sorry if I was rude.

If I wrote it as
a.states.include?(state_id) ? value to apply = integer value or whatever you want : a.add_state(State_id); your damage formula + value to apply; end

Would that make sense?
Of course this can be changed to however you feel it will fit your skill.
You have completed games before and never did damage formulas?

Yes, you're right.

I tested your solution but it seems like it doesn't work.

Unbenannt.png
seems like it doesn't work
Looks like it complains with the end. Try removing that part. And the ; at the end.
a.states.include?(5) ? dam = 100 : a.add_state(5); damage formula + dam

Mind you I see that you are doing 0 damage. So if that is your goal then all you need is
a.states.include?(5) ? true : a.add_state(5); 0
RTFS. Don't mean to be rude, but if you've been using the program for a while and did googling, this should be easy to understand. You've been a member of the forums since 2018 after all. You have completed games before and never did damage formulas?
Also, you're wrong about a.states.include?(state_id), and I believe you've been coding for a while now, check what does .states return. Hint, it isn't an integer
Spoiler
a.state?(state_id)

-----
I do have a little bit elegant solution, but still involves script edit.
I'll get back to you later after I fix my internet.
I don't have any knowledge about scripting or damage formulas, so I might have an idea about how to work around that. It might be a little rough and I don't know if it could work, but it's at least worth a try.

Add a status to the buffing skill that locks all other buffing skills. You'd have to specify all of those skills (unless they have the own category)individually, but then the player wouldn't be able to use any buffing skills. Of course, you'd need to remove that status when the buff disappears. I'm not sure how well it would work with enemies, but that's all I can think of.
Hint, it isn't an integer
Yes, it's a boolean check to determine if the condition is true or false.
I think I used .include? wrong then. Need to check if the state is applied.
Have to think on it.

Game_BattlerBase line 127.
Should return true or false.
so does the
a.states.include?(5) ? true : a.add_state(5); 0
not work?
Using this by asking if true or false in a ternary operator condition would run either true or false. Correct?
So then a.add_state(5) would apply if the state is not applied.
Of course I don't play with damage formulas much and haven't tested this.
@Roninator2 what Theo is trying to say is that the method you're using will always return false, because that method a.states.include?(state_id) is checking if a state ID exists rather than a state object. Here is the method 'states' in Game_BattlerBase:
Ruby:
  #--------------------------------------------------------------------------
  # * Get Current States as an Object Array
  #--------------------------------------------------------------------------
  def states
    @states.collect {|id| $data_states[id] }
  end
As you can see, it's a collection of the states, not the state IDs.

The method you want to use is
Ruby:
  def state?(state_id)
    @states.include?(state_id)
  end


I'm not sure if using the damage formula is the best choice for this, anyway. I'd recommend using something like Hime's Enemy Action Conditions. You can set it up so that the enemy has a skill that adds the buff and give it a high rating, and then set it so that it only uses it if it doesn't already have the buff.
My solution is close to what AMN posted, I had no idea that had been done before, so that makes things easier. I assume Hime's script does not change anything regarding the action rating (and just deal with the condition), here is what you can do

For buff action, put the rating at the highest rating, for example, 10
Then set the condition like !a.state?(10) (assuming state 10 is the buff state).
This way, if the condition is valid, every other action that is below 8 will not get executed and always use the buff action.
will always return false, because that method a.states.include?(state_id) is checking if a state ID exists rather than a state object
Right, I see it now. I was taking the block code and trying to put it in the formula. Not thinking there was a states block that would be called for the condition .include?
set the condition like !a.state?(10)
Thanks for helping to clarify my misunderstanding.

Original thread: https://forums.rpgmakerweb.com/threads/battlers-should-only-use-buffs-if-they-have-no-buff-active-at-the-moment.121758/