Preemptive/Surprise for scripted battles

 I've been working on something and I've hit a bit of a snag. In the game I've got going, you can choose from one of several characters, all of which have different stat growth rates. Some of them, in particular, have lower-than-average stat growths, compensated for by special abilities (for example, the Assassin gets Preemptive Up).


 The thing is that I'm not using random encounters. All of the enemies in the game have ramped up difficulty and (hopefully) advanced AIs, making each fight challenging in its own right... so having random battles would end up as a frustrating experience (That, and I'm creating 4 different versions of each creature based on the difficulty setting you choose, each with a slightly different AI and stats)


 The thing is that I'm pretty sure that you don't get preemptive (or surprise) battles with scripted fights by default.


so, I'm looking to do something like this:


Normal Characters: 3% Preemptive Chance, 5% Surprise Chance


Agility Characters:  5% Preemptive Chance, 3% Surprise Chance


Assassin: 20% Preemptive Chance, 5% Surprise Chance


Rogue: 5% Preemptive Chance, 0% Surprise Chance


 I suppose I could use 2 variables (Preemptive and Surprise) and set them whenever you select your character.......... but I'm not sure exactly how I would implement them.
One question. So that you said you didn't use random encounter, and you said scripted battle. What exactly do you mean? Did you use battle processing directly from event, or what? 
yeah, I'm using battle processing directly from events that you touch. Each battle is connected to a switch that gets reset when you change levels.
You can try this plugin





I basically give you two variables (surprise and pre-emptive), and then it's up to you to set them.


You can use the "Control Variable" event to choose a random number between 1 and 100.




So for example, with your rogue character, you might use conditional branches to roll a random number between 1 and 100, and store that in variable 8 (arbitrarily picked)


Then you would use a conditional branch to check if the number is greater than 5 (because the chance of getting a number between 6 and 100 is 95% compared a number between 1 and 5). If so, then you would set "pre-emptive" variable to 1, which means the next battle will be pre-emptive.


The next battle would then be a pre-emptive battle


You can do the same for the others, rolling random numbers to check if it should be surprise or pre-emptive.
 This looks like exactly the kind of thing I need... but how do you install the plugin in VXAce?


 I don't see any kind of js folder for my project.
Oops, this was posted in Ace support lol


Use this for Ace.


Just set the variable ID's at the top.


The variables will automatically decrease by 1 once you start a battle.


Pre-emptive takes precedence over surprise, so if both variables are set, then pre-emptive is taken first.


This overrides the default pre-emptive/surprise mechanics.

Code:
module TH
  module PreEmptive_Battle_Events
    PreEmptiveID = 1
    SurpriseID = 2
  end
end

module BattleManager
  class << self
    alias :th_preemptive_battle_events_battle_start :battle_start
  end
  def self.battle_start
    check_preemptive_variables
    th_preemptive_battle_events_battle_start    
  end
  
  def self.check_preemptive_variables
    @preemptive = false
    @surprise = false
    if $game_variables[TH::PreEmptive_Battle_Events::PreEmptiveID] > 0
      @preemptive = true
      $game_variables[TH::PreEmptive_Battle_Events::PreEmptiveID] -= 1
    elsif $game_variables[TH::PreEmptive_Battle_Events::SurpriseID] > 0
      @surprise = true
      $game_variables[TH::PreEmptive_Battle_Events::SurpriseID] -= 1
    end
  end
end
that worked perfectly. Thank you so much. I'm definitely using this 😛

Original thread: https://forums.rpgmakerweb.com/threads/preemptive-surprise-for-scripted-battles.56587/