[SCRIPTING] [RMVX ACE] TURNING SWITCH ON AMBUSH\PREEMPTIVE BATTLES
Posts
Pages:
1
Hi there
So I'm trying to make a unique animation when running into either a pre-emptive or ambush battle. I made common events that will trigger when a switch it on however I'm struggling on having said switch turned on when either happen.
I'm not sure if this is important to note but I'm using on map battles through events.
Heres the script, keep in mind I barely know anything about scripting besides some basics.
Would appreciate any help!
So I'm trying to make a unique animation when running into either a pre-emptive or ambush battle. I made common events that will trigger when a switch it on however I'm struggling on having said switch turned on when either happen.
I'm not sure if this is important to note but I'm using on map battles through events.
Heres the script, keep in mind I barely know anything about scripting besides some basics.

Would appreciate any help!
Hi Porkate42,
You're on the right track, but you may have mixed up some MV scripting.
First step, we want to call the original on_encounter code to set those random values.
The simple method is to simply copy the code into your redefined function:
But that way leads to compatibility problems if more than one script modifies the same function.
So instead we should alias and monkey patch like this:
The alias is a bit more complicated than usual, because we're working with a module. For regular classes not using the "self.method", the aliasing would look like this:
Finally, you want to store the @preemptive and @ambush values in switches.
This is where you seem to have mixed in some MV style code.
In VX ace, it's much simpler: $game_switches can be accessed as if it were an array:
But, @preemptive is already the right type, so we can store directly in the switch:
You're on the right track, but you may have mixed up some MV scripting.
First step, we want to call the original on_encounter code to set those random values.
The simple method is to simply copy the code into your redefined function:
module BattleManager #-------------------------------------------------------------------------- # * Processing at Encounter Time #-------------------------------------------------------------------------- def self.on_encounter @preemptive = (rand < rate_preemptive) @surprise = (rand < rate_surprise && !@preemptive) # TODO: add new code end end
But that way leads to compatibility problems if more than one script modifies the same function.
So instead we should alias and monkey patch like this:
module BattleManager #-------------------------------------------------------------------------- # * Processing at Encounter Time #-------------------------------------------------------------------------- class << self alias on_encounter_pes on_encounter end def self.on_encounter self.on_encounter_pes # TODO: add new code print(@preemptive) end end
The alias is a bit more complicated than usual, because we're working with a module. For regular classes not using the "self.method", the aliasing would look like this:
class Game_CharacterBase
alias ccss_move_straight move_straight;
def move_straight(d, turn_ok = true)
Finally, you want to store the @preemptive and @ambush values in switches.
This is where you seem to have mixed in some MV style code.
In VX ace, it's much simpler: $game_switches can be accessed as if it were an array:
$game_switches[431] = true
But, @preemptive is already the right type, so we can store directly in the switch:
module BattleManager #-------------------------------------------------------------------------- # * Processing at Encounter Time #-------------------------------------------------------------------------- class << self alias on_encounter_pes on_encounter end def self.on_encounter self.on_encounter_pes $game_switches[431] = @preemptive $game_switches[432] = @ambush end end
I'm not sure if this is important to note but I'm using on map battles through events.You could in this case set the switches via event commands...
But you'll probably need to call BattleManager.on_encounter in a script call before battle processing, as it's normally only used for random encounters IIRC.
So I attempted the script code and unfortunately nothing has changed, they still dont turn on for some reason.
It MAY be the fact that I'm using several scripts. One of them being this one that makes on map enemies trigger both ambush and preemptive
If switches don't work I could also work with calling common events.
And if calling it via the monster events could work, how would I go about that?
Thanks.
EDIT:
So I edited the code a bit like this
and it appears to be working. The common event I want occurs after battle though. However this is a start. Thank you!
It MAY be the fact that I'm using several scripts. One of them being this one that makes on map enemies trigger both ambush and preemptive
If switches don't work I could also work with calling common events.
And if calling it via the monster events could work, how would I go about that?
Thanks.
EDIT:
So I edited the code a bit like this
module BattleManager
#--------------------------------------------------------------------------
# * Processing at Encounter Time
#--------------------------------------------------------------------------
class << self
alias on_encounter_pes on_encounter
end
def self.on_encounter
self.on_encounter_pes
if @preemptive
$game_switches[431] = true
elsif @surprise
$game_switches[432] = true
end
end
end
and it appears to be working. The common event I want occurs after battle though. However this is a start. Thank you!
The common event I want occurs after battle though.
Yes, unfortunately parallel / autorun common events activated by switches only run on the map.
You'll need a troop event, or a script that allows you to use common event(s) as troop events.
A troop event can call a common event with no problems, so worst case you could add an event to every troop that calls common event X - and in common event X check the switches you're interested in and call common events Y,Z...
Pages:
1














