There is one final way of entering a midbattle script, which is to simply hardcode the entirety of the script itself, rather than relying on a hash. The advantage of using this method is that you are totally unrestricted in what you're able to do, as long as you have the know-how to code it. The downside is that this requires more technical grasp of Essentials and Ruby in general, and a lot of things that are simply configured automatically when entering data into a hash must now be set up manually. Because of this, setting up scripts in this manner should be reserved for more advanced users who are already somewhat competent at coding, so I'm not going to go into extensive detail here since I can assume these users can figure it out mostly by looking at examples.
To hardcode a midbattle script, you have to use the MidbattleHandlers module to set up your own midbattle handler. To do so, open the Deluxe Battle Kit plugin scripts, create a new text file and name it whatever you want. In here, you may include all of your custom handlers. Here's an example of what one of these may look like:
MidbattleHandlers.add(:midbattle_scripts, :midbattle_example_script,
proc { |battle, idxBattler, idxTarget, trigger|
scene = battle.scene
case trigger
when "RoundStartCommand_1_foe"
scene.pbStartSpeech(1)
battle.pbDisplayPaused(_INTL("You're not gonna beat me this time!"))
when "BattleEndLose"
scene.pbStartSpeech(1)
battle.pbDisplayPaused(_INTL("See? I told you!"))
when "BattleEndWin"
scene.pbStartSpeech(1)
battle.pbDisplayPaused(_INTL("No! Impossible!"))
end
}
)
I'll provide a quick breakdown of the arguments used in these handlers.
Handler type
This identifies whether this handler is a trigger handler, or a script handler. For your purposes, this argument should be :midbattle_scripts, as you are using this handler to hardcode an entire script, not a specific trigger. However, if you're designing a global midbattle script, you'd want to use :midbattle_global instead (more on this in the "Advanced: Global Scripts" section).
Script ID
This is the specific ID that should be used to identify this script handler. This is what is used to actually call upon this script when entered in the "midbattleScript" Battle Rule in an event. In the above example, I used the id :midbattle_example_script, but this can be whatever symbol you want. This should be a unique symbol not shared by any other midbattle script handler. This is what you actually enter in the battle rule to call this script. As a rule of thumb, I suggest that these ID's are always in lower case, so that you don't risk confusing them with constants entered in the MidbattleScripts module outlined in the previous subsection.
Proc
This is where you'll actually code the battle script you want. This proc will always contain the following arguments:
The battle class. You can use this to access pretty much anything you want related to the battle.
The index of the battler who activated the Trigger Key. You can use this to obtain the battler object that appears at this index.
The index of the target. This is usually only relevant for Trigger Keys related to using moves.
The specific Trigger Key that has been activated.
Once your handler is set up, you may then set this script by calling it with the the "midbattleScript" Battle Rule in an event, like so:
How I suggest setting up these handlers is by using case trigger, followed by a series of when X statements for each specific Trigger Key that you want to check for where you want something to happen. Then you can simply code whatever it is you want to happen for each Trigger Key. Though, there may be situations where there's a more efficient way to set this up. If you want more intricate examples of midbattle scripts that utilize midbattle handlers, check the plugin file [002] Midbattle Scripting/[004] MidbattleHandlers Scripts.
Something to note is that any variations of the "_repeat" or "_random" Trigger Key extensions have no use when hardcoding midbattle scripts. When coding scripts in this way, each key is automatically assumed to always trigger and always repeat indefinitely. So if you want something to only trigger once, or to only occur at a random, you have to specifically code it to do so.
While I'm at it, here's a list of methods and/or properties that you might want to reference when hardcoding your scripts to help with this as well as other scenarios, since this plugin adds a lot of new custom content which you may need to call on to make certain things happen:
Battle Class
pbTriggerActivated?(*triggers)
Returns true if any of the inputted Trigger Keys have activated in this battle at least once. You may use this to check for repeated keys if you only want a specific Trigger Key to trigger only once.
pbPauseAndPlayBGM(track)
Pauses the current BGM playing in this battle and saves its position to be restored later before playing the new track, which should be an audio file or name of one.
pbResumeBattleBGM
Ends the current BGM and resumes playing a previously paused BGM from the same position it was paused at. This doesn't do anything if no BGM is currently paused.
Battle::Battler Class
@damageThreshold
Sets the damage cap for a battler. This works exactly as the "battlerDamageCap" Command Key does.
wild_flee(fleeMsg = nil)
Used to make a wild battler flee from battle. Doesn't do anything if the battler isn't a wild Pokemon. You can set fleeMsg to a string to set a custom message upon fleeing.
Battle::Scene Class
pbStartSpeech(speaker)
Begins cinematic speech. If the entered argument is a battler index, the speaker will be set to whichever trainer owns the battler at that index. If it's a wild Pokemon, then the speaker will be set to the wild Pokemon itself. If the entered argument is a battler object, then the speaker will be set to that specific battler itself, regardless if it's owned by a trainer or not. If the speaker is set to a symbol (either a species ID or a trainer type ID), then the speaker will be set to that specific species or trainer type, even if they aren't participating in this battle. For species ID's in particular, this can be entered as an array containing the ID, form number, gender number, and a boolean to determine shininess to customize this Pokemon speaker.
pbGetSpeaker(speaker)
If speaker is nil, this returns the object that was set as the last active speaker. This can be either an in-battle trainer or battler, a Pokemon object, or a Trainer Type object. If speaker is set to a battler index, this will return the object that should be assigned as the speaker for that index. For wild Pokemon, this will return the battler object itself. For non-wild Pokemon, it will return the trainer object that owns the Pokemon at that index.
pbHideSpeaker
This will slide the sprite of the current speaker off screen (if any) during cinematic speech and close any of their message boxes which may be on screen.
pbShowSpeaker(speaker)
This will slide in the sprite of a new speaker during cinematic speech (if any). This accepts the same arguments as pbStartSpeech.
pbUpdateSpeakerSprite(speaker)
This will replace the sprite of the currently active speaker during cinematic speech (if any), without sliding the current sprite off screen first. This can be used to display different "frames" of the same speaker to convey different emotions, for example. The argument set here can either be a trainer type ID or a Pokemon species ID. For Pokemon species in particular, this can be set as an array containing the ID, form number, gender number, and a boolean to determine shininess to customize this Pokemon speaker.
pbShowSpeakerWindows(name, windowskin)
This can be used to update and display the current speaker's and/or windowskin that is used for their dialogue. If either argument is set to nil, then the default name and/or windowskin will be displayed.
pbHideSpeakerWindows(speech)
This can be used to hide the display of the current speaker's message windows. If speech is set to true, the text color will be set to white so that any displayed text can be displayed over the cinematic black bar itself, instead of within a message box.
pbInCinematicSpeech?
Returns true if you are currently in the middle of cinematic speech.
pbForceEndSpeech
This abruptly ends cinematic speech, hides all speaker sprites and returns the battle scene to normal.