Golisopod User

he/him
Alola Reigon
Seen 1 Day Ago
Posted 1 Day Ago
649 posts
4.9 Years



Mid Battle Dialogue/Scripted Battles

Overview:
The main aim of this script was to recreate the feature in BW2 which allowed Trainers to say a line of dialogue when they send out their last Pokemon and when their last Pokemon is at Low HP. This feature was expanded upon in Pokemon SwSh, where an opponent made a statement even when using a move, fainting a Pokemon, before Dynamaxing their Pokemon etc. Its a feature which adds personality to trainers. This script, takes that to the next level, with many more cases to trigger dialogue and with the functionality to run whole chunks of code mid Battle, essentially allowing you to edit every aspect about the battle, the Pokemon in Battle, the battle scene and even stuff in the Overworld. It also allows for Dialogue in Wild Battles. The only limit is your imagination.

Features:
  1. Displaying dialogue Mid Battle with many options.
  2. Sword/Shield Message Display Animation
  3. Changing BGM Mid Battle
  4. Allowing Dialogue to appear in many different places throughout the battle, not just on sending out the last Pokemon
  5. Usage of code blocks allows manipulation of the battle, the battle scene and the battlers at deep levels which allows highly intricately crafted and unique battle scenarios.
  6. Works with both Trainer as well as Wild Battles

Example Battles made using this Script:
Spoiler:
  • Rival Battle from Pokemon FRLG:
  • Simple Pokemon Catching Tutorial:
  • Gym Leader Opal from Pokemon Sword and Shield:
  • Gym Leader Brock from the Anime Episode Showdown in Pewter City:


Download Link

This script is not compatible with Essentials v17, or with EBS or EBDX. I do not plan to add compatibility for any of them.

Instructions

Spoiler:

Installation of Script:
Spoiler:
  1. Place the contents of script1.rb in a new script section above Main called BattleScript_Main
  2. Place the contents of script2.rb in a new script section above Main called BattleScript_Data
  3. Place the Graphics into the Battle Animations Folder
  4. Start a new save (Optional)

Note: A .rb file is like a .txt file, and can be opened with any text editor. No need to panic.


Script Commands for the Battles:
Spoiler:

The script commands to add Dialogue to a trainer battle are
BattleScripting.set(condition,data)
Spoiler:
  • data can be 1 of 4 things.
    • String => Will Display a basic String Dialogue along with the Trainer Sprite sliding in Trainer Battles.
      Eg: "This is my Ace Magikarp, you're not gonna get through him!"
    • Array=> Will Display multiple Dialogues one after the other along with the Trainer Sprite sliding in Trainer Battles.
      Eg: ["This is my Ace Magikarp.","He's even more powerful than a Mega Gyarados","Even faster than a Mega Salamence","And even tougher than a Gigantamax Corviknight","Good luck beating him"]
    • Hash=> Allows you to display Dialogue, change BGM and display a different Trainer Graphic than usual and even display a Trainer when in Wild Battles. The key values are:
      • "text" : The Dialogue to be displayed. Can be a String or Array
      • "bgm" : The BGM to Switch to
      • “bar” : set this to true if you want the SwSh styled Bar Animation when displaying text.
      • "opp" : Can be a String or Number. If its a Number then it displays the Trainer of that Index (Eg in a Battle against 2 Trainers,
      • “abovePkmn” : set this to true if you want the Trainer Sprite to appear above the Pokemon during dialogue.
        if Opp is set to 2 then the Graphic of the 2nd Trainer will be shown)
        If its a string then it'll display a graphic from the Trainers folder.(Eg: trainer024 will display the Prof Oak graphic even though Prof Oak isn't part of the Battle)
        Eg: {"text" => "Time to finish this","bgm" => "SwShGymCheer", "opp" => 2,”bar”=>true}
        {"text" => "This Pikachu should be easy to catch","bgm" => "Oak Intro", "opp" => "trainer024"}
    • Proc=> Run entire chunks of code. Detailed example given in the Example Battles section.

  • condition is the condition for the dialogue to activate. It can be one of the following:
    • "battleStart" => for changing the "X would like to battle!" text
    • "turnStartX" => triggered at the start of turn X of the battle
    • "turnEndX" => triggered at the end of turn X of the battle
    • "randX" => triggered at the end of a turn with the chance of 1 in X
    • "last" => triggered when player sends out their last battler
    • "lastOpp" => triggered when opponent sends out their last battler
    • "item" => triggered when player uses item
    • "itemOpp" => triggered when opponent uses item
    • "mega" => triggered when player Mega Evolves battler
    • "megaopp" => triggered when opponent Mega Evolves battler
    • "recall" => triggered when player recalls battler
    • "recallOpp" => triggered when opponent recalls battler
    • "lowHP" => triggered when player's battler HP reduced to below 25%
    • "lowHPOpp" => triggered when opponent's battler HP reduced to below 25%
    • "halfHP" => triggered when player's battler HP reduced to below 50%
    • "halfHPOpp" => triggered when opponent's battler HP reduced to below 50%
    • "bigDamage" => triggered when player's battler receives over 60% damage from move
    • "bigDamageOpp" => triggered when opponent's battler receives over 60% damage from move
    • "smlDamage" => triggered when player's battler receives less than 30% damage from move
    • "smlDamageOpp" => triggered when opponent's battler receives less than 30% damage from move
    • "fainted" => triggered when player's battler faints
    • "faintedOpp" => triggered when opponent's battler faints
    • "attack" => triggered when player performs their 1st attack
    • "attackOpp" => triggered when opponent performs their 1st attack attack
    • "loss" => triggered when player loses battle
    • "endspeech" => triggers when player wins Battle
    • "sendoutX" => triggers when player sends out the Xth Pokemon in their party (doesn't apply for last member)
    • "sendoutXOpp" => triggers when opponent sends out the Xth Pokemon in their party (doesn't apply for last member)

      For each of these conditions, you can add a
      ,Z
      to denote the dialogue to play on the Zth instance of the condition. So you could do
      BattleScripting.set(“recall”,”Whoa! Nice save!”)
      BattleScripting.set(“recall.2”,”Whoa! Nice save again!”)
      
      Note: For the conditions, 
      
      "lowHP","lowHPOpp","halfHP","halfHPOpp","bigDamage","bigDamageOpp","smlDamage","smlDamageOpp","attack","attackOpp","superEff","superEffOpp","notEff","notEffOpp"
      the Zth instance means the Zth Pokemon sent out. So bigDamageOpp,2 will play when the 2nd Pokemon in the opponents party is hit with an attack that takes it down 60% of it's HP.
      And it’ll display a different dialogue the 2nd time the event occurs.


BattleScripting.setInScript(condition,data)
Spoiler:

If for some reason you can't fit your data from
BattleScripting.set(condition,data)
then you can define a new variable in the module provided in BattleScript_Data. Eg:
In BattleScript_Data
Joey_TurnStart0 = {"text"=>"What! You don't like shorts? Time to die!","bar"=>true}
In your event
BattleScripting.setInScript("turnStart0",:Joey_TurnStart0)


BattleScripting.copy(condition 1,conditions....)
Spoiler:

BattleScripting.copy copies all the data from condition 1 to all the conditions specified. Eg:
BattleScripting.set("recall","Huh! Are you already giving up?")
BattleScripting.copy("recall","fainted")
BattleScripting.copy("recall","fainted","sendout2Opp","lastOpp")


BattleScripting.setTrainerAce(ace1,ace2,ace3.......)
Spoiler:

This command allows you to define an "Ace Pokemon" ie a Pokemon that is sent out last no matter what. ace1 applies to the 1st Trainer, ace2 applies to the 2nd Trainer, ace3 applies to the 3rd Trainer. ace1, ace2, ace3 are numbers corresponding to the position of the Pokemon in the Trainer's party, as defined in the trainers.txt. If you have 4 or more trainers on 1 side, then adding an ace4 will also work. The script is designed with that in mind. Eg.
BattleScripting.setTrainerAce(2)
# This will make the 2nd Pokemon in the Trainers party its ace.


BattleScripting.setTrainerOrder(order1,order2,order3.......)
Spoiler:

This command allows you to define theorder in which a Trainer sendsout their Pokemon" ie a Pokemon. order1 applies to the 1st Trainer, order2 applies to the 2nd Trainer, order3 applies to the 3rd Trainer. order1, order2, order3 are arrays of numbers corresponding to the position of the Pokemon in the Trainer's party, as defined in the trainers.txt. If you have 4 or more trainers on 1 side, then adding an ace4 will also work. The script is designed with that in mind. This will not change the 1st Pokemon sent out by the Trainer. Eg.
BattleScripting.setTrainerOrder([1,3,4,2,6,5])
# This will make it so that after the 1st Pokemon is sent out, the next is the 3rd, then 4th, then 2nd, then 6th, then 5th.


Here are some example commands that can be used inside Procs. (Important if you want the Trainer to Animate when saying Dialogue)
Spoiler:

# For changing/animating Trainer Sprites. Works with any sprite in the Trainers Folder
TrainerDialogue.changeTrainerSprite(["trainer024","trainer024_1","trainer024_2","trainer024_2"],battle.scene,delay=5)
# Here the trainer024,trainer024_1..... are sprites in my Graphics/Trainers folder. The delay is the amount of frames to wait before changing the sprite.

# For Opponent Sprite to Slide into Battle
battle.scene.pbShowOpponent(0,true) #0 is Index of Trainer. It can be 1 in a double battle if you want to show the 2nd Trainer. The "true" is if you want the Trainer to appear in front of their Pokemon
battle.scene.pbHideOpponent

# For showing the SwSh styled animation for Dialogue
battle.scene.appearBar
#{Dialogue Stuff}
battle.scene.disappearBar
# Note that the Black Bars are drawn above the Battle UI so you'd wanna hide the bars before proceeding with any Battle Animations and All

# For hiding and showing the HP Box in Battle
battle.scene.disappearDatabox
#{Dialogue Stuff}
battle.scene.appearDatabox

# Dialogue
pbMessage("\\f[IintroOak]\\c[2]OK \\PN, let's see if you can beat this Pikachu!")

# Yes/No
pbConfirmMessage("Are you sad?")

# Choices
pbShowCommands(nil,"Are you sad?",["Why do you care?",''Nopity Nope","Who are you?"])

# Battle Text
battle.pbDisplay("It's stats rose!")

# Raising and Lowering Stats
battle.battlers[1].pbRaiseStatStage(PBStats::ATTACK,1,battle.battlers[1])
battle.battlers[1].pbRaiseLowerStage(PBStats::ATTACK,1,battle.battlers[1])

# Displaying Common Animations
battle.pbCommonAnimation("Sky Attack charging",nil,nil)
battle.pbCommonAnimation("StatUp",nil,nil)

# Setting Weather
battle.pbStartWeather(battle.battlers[1],PBWeather::Sandstorm)

# Setting Terrain
battle.pbStartWeather(battle.battlers[1],PBBattleTerrains::Electric)

# Forcefully Ending Battle
battle.scene.pbRecall(0)
battle.scene.pbRecall(2)
battle.pbCommonAnimation("MegaEvolution",nil,nil)
battle.decision=2 # Lost Battle
battle.decision=3# Flee
battle.decision=1# Won

# Reducing HP of Pokemon on Player's side
battle.battlers[0].pbReduceHP((battle.battlers[0].totalhp/5).floor)
battle.battlers[2].pbReduceHP((battle.battlers[2].totalhp/5).floor)

# Recovering HP of Pokemon on Player's side
battle.battlers[1].pbReduceHP((battle.battlers[1].totalhp/5).floor)
battle.battlers[3].pbReduceHP((battle.battlers[3].totalhp/5).floor)

# Setting Status
battle.pbAnimation(getID(PBMoves,:DARKVOID),battle.battlers[1],battle.battlers[0])
battle.battlers[2].pbSleep if battle.battlers[2].pbCanSleep?(battle.battlers[1],false)
battle.battlers[0].pbSleep if battle.battlers[0].pbCanSleep?(battle.battlers[1],false)

# Setting up Effects on Opposing Side of Field
battle.pbAnimation(getID(PBMoves,:STEALTHROCK),battle.battlers[1],battle.battlers[0])
battle.battlers[0].pbOpposingSide.effects[PBEffects::StealthRock]=true

battle.pbAnimation(getID(PBMoves,:BARRIER),battle.battlers[1],nil)
battle.battlers[0].pbOwnSide.effects[PBEffects::LightScreen]=3
If you want more examples of how to use this script, I highly recommend checking out the BattleScript_Data from:
Pokémon Splice
Pokemon Bushido
Touhou Puppet Play ~ The Festival of Curses

If you haven't played these games already then I highly recommend checking these games out. They all make really creative use of the system, and are just damn good games in general.
Or have a look at the Example Map provided in the download, with its example battles.



Example Battles:
Spoiler:

Test out the Battles yourself by adding the Map provided in the download to your game
To add this new map to you game:
  • Paste the MapXXX.rxdata to your projects Data Folder
  • Create a New Map in your Project
  • Go to Map Properties and note down the ID Number (Eg: 069)
  • Save and Close RPG Maker
  • Delete the Map corresponding to the ID we noted down (So Map069.rxdata will be deleted)
  • Rename the Dowloaded file such that the XXX matches the ID we noted down.
  • Open RMXP and have fun with the Trainer Battles!




Minor Issues:
Spoiler:
  • Syntax Errors may be a big problem in setting up the events. I'd suggest actually creating the Script Command in a .txt file and pasting it into your Event once you're done. If you still get a Syntax Error, re-evaluate the parts where the error points you to. Usually it's something as simple as a missing bracket, comma or colon


Credits
Spoiler:
  • Golisopod User
  • Luka SJ


Changelog
Spoiler:
  • v1.8
    The script now allows you to define an "Ace" for a trainer, a Pokemon that will always be sent out last no matter what.
    The script now allows you to define the "Order" of sending Pokemon for a trainer.
    Minor bugfixes relating to compatibility with the newly released ZUD Plugin and the Gen 8 Project
  • v1.6
    There have been various bugfixes to the script. Mainly compatibility issues.
    The format for BattleScripting.copy has changed, please make sure you update your script command accordingly.
    The instructions have been updated as well. Please check them out.

  • v1.5
    Fixed a few bugs
    Added support of larger screen sizes
    Added a random chance dialogue option
    Made it easier to add bigger Dialogues
    (If you're using the old Script Commands from v1.0, they are still compatible don't worry)
    Be sure to check out the updated instructions on how to use the script.

  • v1.0
    Script Released

Golisopod User

he/him
Alola Reigon
Seen 1 Day Ago
Posted 1 Day Ago
649 posts
4.9 Years
This is a very stupid question but... where do you set up the commands? in the script? in the event via call script?.
Just set up the commands anywhere and it'll all be added in the next battle you have. Ideally I'd put it right before the Trainer/Wild Battle Event. It'd be good if you check out the example battles I've set up in the map provided.

Golisopod User

he/him
Alola Reigon
Seen 1 Day Ago
Posted 1 Day Ago
649 posts
4.9 Years
Im having an error using the turnStart0 command
What exactly is the error? Did you put turnStart0 in quotation marks?

Hey guys, can someone hook it up with a .txt of the commands in the event? For some reason I've never been able to resize windows in rpgxp, and when I go to edit in order to copy text, I only get part of it.
Have you tried using extendtext.exe
Seen August 21st, 2021
Posted August 21st, 2021
47 posts
3.5 Years
Hey Golisopod, it's something to do with the compatibility settings on my end. I even tried using an external app to resize windows, but it doesn't work. Even in scripts I can't see the full line number.

P.s. Forgot to answer lol I have tried using extend text, but most of the text is cut off and I can't see it

Golisopod User

he/him
Alola Reigon
Seen 1 Day Ago
Posted 1 Day Ago
649 posts
4.9 Years
Hey Golisopod, it's something to do with the compatibility settings on my end. I even tried using an external app to resize windows, but it doesn't work. Even in scripts I can't see the full line number.

P.s. Forgot to answer lol I have tried using extend text, but most of the text is cut off and I can't see it
I should have seen this coming. I'd actually never written the example battles in the tiny RMXP Script Window. I copied it from a text file which I don't have anymore.

And any which ways, those scripts are meant to serve as examples for what the script can do. They aren't meant to be copy-pasted. I'd suggest reading the instructions and the examples to try creating your own unique dialogue. And if you still have trouble, I'll try my best to help you out.

Golisopod User

he/him
Alola Reigon
Seen 1 Day Ago
Posted 1 Day Ago
649 posts
4.9 Years
Basically every time I encounter the event mon that error shows up. And yes I put turnStart0 in quotes
What exactly is the error?
Seen September 7th, 2021
Posted January 15th, 2021
93 posts
1.9 Years
This script is not compatible with Essentials v17, or with EBS or EBDX. I do not plan to add compatibility for any of them.
Does this work with Essentials V.17.2?
Why do you think he'd accept your request when you don't even have the decency of reading the entire post.

Golisopod User

he/him
Alola Reigon
Seen 1 Day Ago
Posted 1 Day Ago
649 posts
4.9 Years
Update!
A new update for the Mid Battle Dialogue/Scripted Battles script has been released with many bugfixes and new features. Be sure to check the updated instructions and changelog.

StCooler

Mayst thou thy peace discover.

Seen 5 Hours Ago
Posted 16 Hours Ago
3,598 posts
1.7 Years
when I install this script and the Max reid battle script, when capturing the pokemon after you win the raid, it says q the pokemon died and I don't capture it. Can you solve this problem?
This is because both the Max Raid plugin and the Mid Battle Dialog plugin rewrite the function pbFaint() of the class PokeBattle_Battler.
From what you are saying, I assume you have the Mid Battle Dialog plugin set AFTER the Max Raid plugin. If that's the reverse, DO NOT use my bugfix.

In the script Mechanic_Compatibility of the Max Raid plugin, find the code of the function pbFaint():
  def pbFaint(showMessage=true)
and copy the whole code of that function.
Then, in the script BattleScript_Main of the Mid Battle Dialog plugin, find the code of the function pbFaint():
  def pbFaint(showMessage=true)
Comment the whole function (I would strongly advise against deleting the code), and paste the code of the Max raid plugin.
Then, AFTER the line @battle.pbEndPrimordialWeather and BEFORE the two "end"s:
      @battle.pbEndPrimordialWeather
      # < -------- HERE -------- >
    end
  end
paste the following lines:
    if !opposes?
      TrainerDialogue.display("fainted",@battle,@battle.scene)
    else
      TrainerDialogue.display("faintedOpp",@battle,@battle.scene)
    end
Basically, I am merging the two functions pbFaint().
Male
Seen 57 Minutes Ago
Posted September 7th, 2021
275 posts
1.4 Years
Hello, I have a problem I have added the script and tried running the test battle but got the error message seen in the picture, in the right of the picture i have added a screenshot of where i save the scripts. https://ibb.co/yRL794d
Did you did anything with the event script

भाग्य ज्योति

Age 15
Male
बिहार, भारत। Bihar, India.
Seen 3 Weeks Ago
Posted August 9th, 2021
2,152 posts
2.4 Years
Hello, I have a problem I have added the script and tried running the test battle but got the error message seen in the picture, in the right of the picture i have added a screenshot of where i save the scripts. https://ibb.co/yRL794d
You maybe tried to study the event script and in the process broke it. Open that script and run extendtext.exe given with the PE. this will make up space for that long code to come in 1 single line.
14 year-old amteur GAME DEVELOPER.
Join my discord which has all Pokemon stuffs, from gaming to game-making and from arts showcase to poketubing.
My DeviantArt- https://www.deviantart.com/bhagyajyoti
Pokemon BHARAT: My fangame based on the Indian-Subcontinent.