States That Have a Chance of Automatically Using Skills

I'm requesting a script that would essentially be an add-on for Victor Sant's Passive States script (just Ctrl+F "passive," and it should be the only result). The idea is to allow for States to have a chance of using a skill at the start of a combat round, with the skill's id and % chance indicated by notetags; something like <passive state skill: x, y%> with "x" being the skill id and "y" being the chance of it occurring. Obviously, it should do this regardless of whether they actually know the skill, before turn order, and without affecting the battler's actions (actor or enemy), especially if they have any Action Times+ features.

An example would be if Eric had a passive skill (due to Victor Sant's script) called "Burst of Power," which has a 10% chance of using "ATK Up" (let's say skill 41) at the start of each round, despite him not knowing that skill. Using the previous example notetag, in the "Burst of Power" State's note box you would put <passive state skill: 41, 10%>. During a battle, you choose to Attack. The notetag makes it so that there is a 1/10 chance of Eric using skill 41, "ATK Up," at the start of each round, but even if activates that turn, he'll still Attack like you told him to.

For another example, Natalie has "Burst of Power" like Eric does, but also has the Action Times +100% feature, meaning she'll always act twice per round. During a battle with a Slime, Natalie is faster than Eric, but slower than the Slime, and you have her Attack for both of her turns. Eric's Burst of Power doesn't activate, but Natalie's does, making her use ATK Up at the round's start before actions are carried out. The Slime attacks, then Natalie attacks twice as she was instructed, and then Eric does whatever you told him to do that turn.

I'm not sure how complicated this is, but I think this could make for some interesting gameplay, and also help further differentiate classes beyond what they learn.

EDIT: Added link to Victor's script drive gallery thing. I realized that one issue would be if an actor or battler was afflicted with a State that prevented actions (Sleep, Paralysis, etc, but NOT Death). I guess just make the passive-activated skills ignore those restrictions on actions (again, not Death).
This script might do the job:

http://forums.rpgmakerweb.com/index.php?/topic/38777-doublex-rmvxa-state-triggers/

Using your "Burst of Power" as an example:

<turn state trigger: STC1, STA1>Where STC1 is:

STC1 = "rand < x" # The probability of returning true is xAnd STA1 is:

STA1 = "force_action(skill_id, target_index); BattleManager.force_action(self)"Where skill_id is the id of the skill to be used, and target_index is:

-2: last target index-1: randomn(>=0): index n - 1Check the Force Action Event Commands for details.

P.S.: I don't know if that script's compatible with Victor's ones 🙂
My knowledge of scripting is practically nil, so this is pretty much all flying over my head. Even so, I think I got it set up right - no crashes - but it has the character use the skill at round's end, rather than at round start. 

 



EDIT: In addition, it always kicks in if I set the "rand < x" to anything other than 0, in which case it instead never activates. Did I do something wrong?
That's because turn state trigger only triggers when the turns are reduced by 1, which occurs at the end of a turn. For what you want, you would need a way to trigger it at the start of the turn. Maybe Yanfly's Lunatic states script would work for this?

Edit: Ok, it would require an edit or an add-on to pull that off, but Yanfly's Lunatic states does have the ability to flag a state to have things occur at the start of the parties turn. You would need an add-on written then to take advantage of that so that your random state can occur.

Unfortunately my knowledge of reading notetags is really poor for what you need here, so I doubt I can do it for a few weeks (at minimum) as I would have to go learn how to read notetags better first. But maybe someone can write an add - on to Yanfly's Lunatic states with this idea in mind?
That's because turn state trigger only triggers when the turns are reduced by 1, which occurs at the end of a turn. For what you want, you would need a way to trigger it at the start of the turn. Maybe Yanfly's Lunatic states script would work for this?
Thanks for the reminder. I think I need to upgrade the state trigger script to support both the end and start of a turn lol
If you could, that would fix the problem, as Yanfly's Lunatic states script forgot the eval command so the OP cannot use the custom conditions to set it up. Not without a custom add-on script written first.
So what's with the issue where it seems to think that setting the x in "rand < x" to anything over 0 means it should always kick in?
Are you using integers or decimals? By default, rand returns a number between 0 and 1, so if you have 1 in there it always kicks in. Instead, if you want 10%, you need to use 0.10.
Shoot, I was using integers because I thought that's how it worked. Using decimals as you suggested, it works properly on that front.
First, use this snippet(to be part of the coming update):

Spoiler
class RPG::State < RPG::BaseItem #----------------------------------------------------------------------------| # New public instance variables | #----------------------------------------------------------------------------| attr_accessor :state_triggers #----------------------------------------------------------------------------| # New method: load_notetags_state_triggers | # - Loads each <timing state trigger: STCX, STAX> notetag from its notebox | #----------------------------------------------------------------------------| def load_notetags_state_triggers # Stores all timing, STCX and STAX triples from matching lines sequentially @state_triggers = {} st = "DoubleX_RMVXA::State_Triggers::" @note.split(/[\r\n]+/).each { |line| next unless line =~ /<(\w+) state trigger:\s*(\w+)\s*,\s*(\w+)\s*>/ @state_triggers[$1.to_sym] ||= [] @state_triggers[$1.to_sym].push( [eval("-> battler { battler.instance_exec { #{eval("#{st}#{$2}")} } }"), eval("-> battler { battler.instance_exec { #{eval("#{st}#{$3}")} } }")]) } # end # load_notetags_state_triggersend # RPG::State
Try to open a battle event with Condition Turn No. 1 * X and Span Turn. Add the below script call into that event:

all_battle_members.each { |battler| battler.instance_exec { @states.each { |state_id| eval_state_triggers(state_id, :turn) } }}If you want the turn start triggers to be different from the turn end triggers, use this instead:

all_battle_members.each { |battler| battler.instance_exec { @states.each { |state_id| eval_state_triggers(state_id, :custom) } }}:custom can be replaced by any symbol other than :add, :turn and :remove(it must also only consist of alphanumeric characters).

Then all the state trigger notetags to be used at the turn start need to be changed to this:

<custom state trigger: STCX, STAX>I think I've to inform users in the script info region that they can create state triggers with custom timings. Utilizing this needs decent scripting proficiency however, unless there are external helps lol

P.S.: I didn't mention that as even I didn't realize that script can have such capabilities just by tweaking minor stuffs. Now I feel incredibly dumb XD
Gave me an error when I tried to battle test.

Script 'DoubleX RMXVA State Triggers' line 321: NoMethodError occurred.

 

undefined methods `each' for nil:NilClass
EDIT: I thought I had found a second bug. Turned out I just forgot to delete a test state. The above issue still applies though.
Gave me an error when I tried to battle test.

EDIT: I thought I had found a second bug. Turned out I just forgot to delete a test state. The above issue still applies though.
That issue's due to an incredibly dumb mistake lol

Now try this snippet:

Spoiler
Code:
#------------------------------------------------------------------------------|#  * Edit class: RPG::State                                                    |#------------------------------------------------------------------------------|class RPG::State < RPG::BaseItem  #----------------------------------------------------------------------------|  #  New public instance variables                                             |  #----------------------------------------------------------------------------|  attr_accessor :state_triggers  #----------------------------------------------------------------------------|  #  New method: load_notetags_state_triggers                                  |  #  - Loads each <timing state trigger: STCX, STAX> notetag from its notebox  |  #----------------------------------------------------------------------------|  def load_notetags_state_triggers    # Stores all timing, STCX and STAX triples from matching lines sequentially    @state_triggers = { :add => [], :turn => [], :remove => [] }    st = "DoubleX_RMVXA::State_Triggers::"    @note.split(/[\r\n]+/).each { |line|      next unless line =~ /<(\w+) state trigger:\s*(\w+)\s*,\s*(\w+)\s*>/      @state_triggers[$1.to_sym] ||= []      @state_triggers[$1.to_sym].push(      [eval("-> battler { battler.instance_exec { #{eval("#{st}#{$2}")} } }"),       eval("-> battler { battler.instance_exec { #{eval("#{st}#{$3}")} } }")])    }    #  end # load_notetags_state_triggersend # RPG::State
I pasted the snippet as its own script. Then, I set up a testing state with the notetag <custom state trigger: STC7, STA4> (basically set to always activate). I made a new Battle Event page with Condition: Turn No. 1 + 1 *X, and Span: Turn, and added a Script call of

Spoiler
all_battle_members.each { |battler|battler.instance_exec {
@states.each { |state_id|
eval_state_triggers(state_id, :custom) }
}
}
Once I selected my actions, it gave me the error:

Script 'Game_Interpreter' line 1411: NameError occurred.

 

undefined local variable or method `all_battle_members' for #<Game_Interpreter:0x84512a0>
You want $game_party.battle_members, there's no such thing as all_battle_members in the interpreter, which is the class you're working inside with battle events.
Alright, so in red is the difference from before:

Spoiler
$game_party.battle_members { |battler|

  battler.instance_exec { 

    @states.each { |state_id| 

eval_state_triggers(state_id, :custom) }

  }

}
While testing, instead of crashing, nothing happens/there's no effect. The other states seem to still work, though.
You want $game_party.battle_members, there's no such thing as all_battle_members in the interpreter, which is the class you're working inside with battle events.
(Facepalmed)How could I make such an incredibly dumb mistake lol

Alright, so in red is the difference from before:

Spoiler
$game_party.battle_members { |battler|

  battler.instance_exec { 

    @states.each { |state_id| 

eval_state_triggers(state_id, :custom) }

  }

}
Spoiler
While testing, instead of crashing, nothing happens/there's no effect. The other states seem to still work, though.
The state trigger script has been updated to v1.01a:

http://forums.rpgmakerweb.com/index.php?/topic/38777-doublex-rmvxa-state-triggers/?p=385381

Now try this script call in the battle event:

$game_party.battle_members.each { |member| member.exec_state_triggers(state_id, :turn_start) }Where state_id is the id of the state to be triggered at the start of a battle turn.

Also, that state needs to use the below state trigger(s):

<turn_start state trigger: STC1, STA1>I've tested and this works in my case. Hope it works on yours too 🙂
It does work, though the .each makes every character use it regardless of whether they have the skill/state or not.

EDIT: Did more testing. The script call definitely doesn't care if anyone actually has the skill/state or not. The script call behaves differently depending on if the activation rate is 100% or not. If it is, then everyone in the party will use the assigned skill; if it isn't, a random character(s) has a chance of using it each turn.
It does work, though the .each makes every character use it regardless of whether they have the skill/state or not.

EDIT: Did more testing. The script call definitely doesn't care if anyone actually has the skill/state or not. The script call behaves differently depending on if the activation rate is 100% or not. If it is, then everyone in the party will use the assigned skill; if it isn't, a random character(s) has a chance of using it each turn.
(My bad)Try this script call instead:

Code:
$game_party.battle_members.each { |member|  next unless member.states.include?($data_states[state_id])  member.exec_state_triggers(state_id, :turn_start)}
Ran a battle test with neither of the actors having the state to check what would happen. Once the first turn actually started (i.e. following command input):

Script 'Game_Interpreter' line 1411: ArgumentError occurred. wrong number of arguments(0 for 1)
I then tried it with only one of them having it, and even with both of them having it, and it gave me the same error.
Maybe you'll need to give me your demo this time 🙂

Original thread: https://forums.rpgmakerweb.com/threads/states-that-have-a-chance-of-automatically-using-skills.39489/