- Pokémon Essentials Version
- v20.1 ➖
This script creates a "battle foreground"- an image that with a priority above the battlers, but still below the UI!
In Battle (PokeBattle_Battle prior to v20), find the section at the top that starts off like this:
Anywhere in that big section - after
Then go to the next section below it, which starts off like this:
Anywhere after that initial conditional, put in this:
In Scene_Initialize, find
Put this:
In Overworld_BattleStarting (PField_Battles in versions before v19), find def
Add this to the list of rules:
(Versions prior to v19 should delete "then")
Below that, find:
Add "foreground" to the list, quotes included. (Don't forget a comma after "outcome"!)
Finally, in this same script, find
Paste this anywhere in that method (as long as it's not in another conditonal):
The plug-and-play script from v18 will be left here for posterity.
Note that this plug-and-play does overwrite several commands in the PokeBattle_Battle and PokeBattle_Scene classes, so be sure to double-check that it doesn't conflict with any other plugins!
You'll need a new folder in Graphics/Battlebacks titled "Foregrounds". Name a file in there anything you want, and then to use it in battle, just call
Graphics should be on a 512x288 canvas, or whatever canvas size your battlebacks are on.
A sample foreground can be found in the download link, which was generously made public by NocTurn! Be sure to credit him if you use it in your projects, and be sure to check out Pokémon Champions, the game it was made for!
In Battle (PokeBattle_Battle prior to v20), find the section at the top that starts off like this:
Ruby:
attr_reader :scene # Scene object for this battle
attr_reader :peer
Anywhere in that big section - after
class Battle
(or class PokeBattle_Battle
prior to v20) and before end
- put in this:
Ruby:
attr_accessor :foreground # Filename fragment used for foreground graphics
Then go to the next section below it, which starts off like this:
Ruby:
def initialize(scene,p1,p2,player,opponent)
if p1.length==0
raise ArgumentError.new(_INTL("Party 1 has no Pokémon."))
elsif p2.length==0
raise ArgumentError.new(_INTL("Party 2 has no Pokémon."))
end
@scene = scene
Anywhere after that initial conditional, put in this:
Ruby:
@foreground = ""
In Scene_Initialize, find
def pbCreateBackdropSprites
. Right above this line:
Ruby:
# Finalise filenames
Ruby:
foregroundFilename = @battle.foreground
if pbResolveBitmap(sprintf("Graphics/Battlebacks/Foregrounds/"+foregroundFilename))
battleFG = "Graphics/Battlebacks/Foregrounds/"+foregroundFilename
end
if battleFG
fg = pbAddSprite("battle_fg",0,0,battleFG,@viewport)
fg.z = 100
end
In Overworld_BattleStarting (PField_Battles in versions before v19), find def
add_battle_rule
. (def recordBattleRule
prior to v20)Add this to the list of rules:
Ruby:
when "foreground"; then rules["foreground"] = var
(Versions prior to v19 should delete "then")
Below that, find:
Ruby:
when "terrain", "weather", "environment", "environ", "backdrop",
"battleback", "base", "outcomevar", "outcome"
Finally, in this same script, find
def prepare_battle
. (def pbPrepareBattle
prior to v20)Paste this anywhere in that method (as long as it's not in another conditonal):
Ruby:
#Foreground
if !battleRules["foreground"].nil?
battle.foreground = battleRules["foreground"]
end
The plug-and-play script from v18 will be left here for posterity.
Ruby:
class PokeBattle_Battle
attr_accessor :foreground # Filename fragment used for foreground graphics
def initialize(scene,p1,p2,player,opponent)
if p1.length==0
raise ArgumentError.new(_INTL("Party 1 has no Pokémon."))
elsif p2.length==0
raise ArgumentError.new(_INTL("Party 2 has no Pokémon."))
end
@scene = scene
@peer = PokeBattle_BattlePeer.create
@battleAI = PokeBattle_AI.new(self)
@field = PokeBattle_ActiveField.new # Whole field (gravity/rooms)
@sides = [PokeBattle_ActiveSide.new, # Player's side
PokeBattle_ActiveSide.new] # Foe's side
@positions = [] # Battler positions
@battlers = []
@sideSizes = [1,1] # Single battle, 1v1
@backdrop = ""
@backdropBase = nil
#techfore
@foreground = ""
@time = 0
@environment = PBEnvironment::None # e.g. Tall grass, cave, still water
@turnCount = 0
@decision = 0
@caughtPokemon = []
player = [player] if !player.nil? && !player.is_a?(Array)
opponent = [opponent] if !opponent.nil? && !opponent.is_a?(Array)
@player = player # Array of PokeBattle_Trainer objects, or nil
@opponent = opponent # Array of PokeBattle_Trainer objects, or nil
@items = nil
@endSpeeches = []
@endSpeechesWin = []
@party1 = p1
@party2 = p2
@party1order = Array.new(@party1.length) { |i| i }
@party2order = Array.new(@party2.length) { |i| i }
@party1starts = [0]
@party2starts = [0]
@internalBattle = true
@debug = false
@canRun = true
@canLose = false
@switchStyle = true
@showAnims = true
@controlPlayer = false
@expGain = true
@moneyGain = true
@rules = {}
@priority = []
@priorityTrickRoom = false
@choices = []
@megaEvolution = [
[-1] * (@player ? @player.length : 1),
[-1] * (@opponent ? @opponent.length : 1)
]
@initialItems = [
Array.new(@party1.length) { |i| (@party1[i]) ? @party1[i].item : 0 },
Array.new(@party2.length) { |i| (@party2[i]) ? @party2[i].item : 0 }
]
@recycleItems = [Array.new(@party1.length,0),Array.new(@party2.length,0)]
@belch = [Array.new(@party1.length,false),Array.new(@party2.length,false)]
@battleBond = [Array.new(@party1.length,false),Array.new(@party2.length,false)]
@usedInBattle = [Array.new(@party1.length,false),Array.new(@party2.length,false)]
@successStates = []
@lastMoveUsed = -1
@lastMoveUser = -1
@switching = false
@futureSight = false
@endOfRound = false
@moldBreaker = false
@runCommand = 0
@nextPickupUse = 0
if hasConst?(PBMoves,:STRUGGLE)
@struggle = PokeBattle_Move.pbFromPBMove(self,PBMove.new(getConst(PBMoves,:STRUGGLE)))
else
@struggle = PokeBattle_Struggle.new(self,nil)
end
end
end
class PokeBattle_Scene
def pbCreateBackdropSprites
case @battle.time
when 1; time = "eve"
when 2; time = "night"
end
# Put everything together into backdrop, bases and message bar filenames
backdropFilename = @battle.backdrop
baseFilename = @battle.backdrop
baseFilename = sprintf("%s_%s",baseFilename,@battle.backdropBase) if @battle.backdropBase
messageFilename = @battle.backdrop
#techfore
foregroundFilename = @battle.foreground
if time
trialName = sprintf("%s_%s",backdropFilename,time)
if pbResolveBitmap(sprintf("Graphics/Battlebacks/"+trialName+"_bg"))
backdropFilename = trialName
end
trialName = sprintf("%s_%s",baseFilename,time)
if pbResolveBitmap(sprintf("Graphics/Battlebacks/"+trialName+"_base0"))
baseFilename = trialName
end
trialName = sprintf("%s_%s",messageFilename,time)
if pbResolveBitmap(sprintf("Graphics/Battlebacks/"+trialName+"_message"))
messageFilename = trialName
end
end
if !pbResolveBitmap(sprintf("Graphics/Battlebacks/"+baseFilename+"_base0")) &&
@battle.backdropBase
baseFilename = @battle.backdropBase
if time
trialName = sprintf("%s_%s",baseFilename,time)
if pbResolveBitmap(sprintf("Graphics/Battlebacks/"+trialName+"_base0"))
baseFilename = trialName
end
end
end
# Finalise filenames
battleBG = "Graphics/Battlebacks/"+backdropFilename+"_bg"
playerBase = "Graphics/Battlebacks/"+baseFilename+"_base0"
enemyBase = "Graphics/Battlebacks/"+baseFilename+"_base1"
messageBG = "Graphics/Battlebacks/"+messageFilename+"_message"
#techfore
if pbResolveBitmap(sprintf("Graphics/Battlebacks/Foregrounds/"+foregroundFilename))
battleFG = "Graphics/Battlebacks/Foregrounds/"+foregroundFilename
end
# Apply graphics
bg = pbAddSprite("battle_bg",0,0,battleBG,@viewport)
bg.z = 0
bg = pbAddSprite("battle_bg2",-Graphics.width,0,battleBG,@viewport)
bg.z = 0
bg.mirror = true
#techfore
if battleFG
fg = pbAddSprite("battle_fg",0,0,battleFG,@viewport)
fg.z = 100
end
for side in 0...2
baseX, baseY = PokeBattle_SceneConstants.pbBattlerPosition(side)
base = pbAddSprite("base_#{side}",baseX,baseY,
(side==0) ? playerBase : enemyBase,@viewport)
base.z = 1
if base.bitmap
base.ox = base.bitmap.width/2
base.oy = (side==0) ? base.bitmap.height : base.bitmap.height/2
end
end
cmdBarBG = pbAddSprite("cmdBar_bg",0,Graphics.height-96,messageBG,@viewport)
cmdBarBG.z = 180
end
end
class PokemonTemp
def recordBattleRule(rule,var=nil)
rules = self.battleRules
case rule.to_s.downcase
when "single", "1v1", "1v2", "2v1", "1v3", "3v1",
"double", "2v2", "2v3", "3v2", "triple", "3v3"
rules["size"] = rule.to_s.downcase
when "canlose"; rules["canLose"] = true
when "cannotlose"; rules["canLose"] = false
when "canrun"; rules["canRun"] = true
when "cannotrun"; rules["canRun"] = false
when "roamerflees"; rules["roamerFlees"] = true
when "noExp"; rules["expGain"] = false
when "noMoney"; rules["moneyGain"] = false
when "switchstyle"; rules["switchStyle"] = true
when "setstyle"; rules["switchStyle"] = false
when "anims"; rules["battleAnims"] = true
when "noanims"; rules["battleAnims"] = false
when "terrain"; rules["defaultTerrain"] = getID(PBBattleTerrains,var)
when "weather"; rules["defaultWeather"] = getID(PBWeather,var)
when "environment", "environ"; rules["environment"] = getID(PBEnvironment,var)
when "backdrop", "battleback"; rules["backdrop"] = var
when "base"; rules["base"] = var
when "outcomevar", "outcome"; rules["outcomeVar"] = var
when "nopartner"; rules["noPartner"] = true
#techfore
when "foreground"; rules["foreground"] = var
else
raise _INTL("Battle rule \"{1}\" does not exist.",rule)
end
end
end
def setBattleRule(*args)
r = nil
for arg in args
if r
$PokemonTemp.recordBattleRule(r,arg)
r = nil
else
case arg.downcase
#techfore
when "terrain", "weather", "environment", "environ", "backdrop",
"battleback", "base", "outcomevar", "outcome", "foreground"
r = arg
next
end
$PokemonTemp.recordBattleRule(arg)
end
end
raise _INTL("Argument {1} expected a variable after it but didn't have one.",r) if r
end
def pbPrepareBattle(battle)
battleRules = $PokemonTemp.battleRules
# The size of the battle, i.e. how many Pokémon on each side (default: "single")
battle.setBattleMode(battleRules["size"]) if !battleRules["size"].nil?
# Whether the game won't black out even if the player loses (default: false)
battle.canLose = battleRules["canLose"] if !battleRules["canLose"].nil?
# Whether the player can choose to run from the battle (default: true)
battle.canRun = battleRules["canRun"] if !battleRules["canRun"].nil?
# Whether wild Pokémon always try to run from battle (default: nil)
battle.rules["alwaysflee"] = battleRules["roamerFlees"]
# Whether Pokémon gain Exp/EVs from defeating/catching a Pokémon (default: true)
battle.expGain = battleRules["expGain"] if !battleRules["expGain"].nil?
# Whether the player gains/loses money at the end of the battle (default: true)
battle.moneyGain = battleRules["moneyGain"] if !battleRules["moneyGain"].nil?
# Whether the player is able to switch when an opponent's Pokémon faints
battle.switchStyle = ($PokemonSystem.battlestyle==0)
battle.switchStyle = battleRules["switchStyle"] if !battleRules["switchStyle"].nil?
# Whether battle animations are shown
battle.showAnims = ($PokemonSystem.battlescene==0)
battle.showAnims = battleRules["battleAnims"] if !battleRules["battleAnims"].nil?
# Terrain
battle.defaultTerrain = battleRules["defaultTerrain"] if !battleRules["defaultTerrain"].nil?
# Weather
if battleRules["defaultWeather"].nil?
case $game_screen.weather_type
when PBFieldWeather::Rain, PBFieldWeather::HeavyRain, PBFieldWeather::Storm
battle.defaultWeather = PBWeather::Rain
when PBFieldWeather::Snow, PBFieldWeather::Blizzard
battle.defaultWeather = PBWeather::Hail
when PBFieldWeather::Sandstorm
battle.defaultWeather = PBWeather::Sandstorm
when PBFieldWeather::Sun
battle.defaultWeather = PBWeather::Sun
end
else
battle.defaultWeather = battleRules["defaultWeather"]
end
# Environment
if battleRules["environment"].nil?
battle.environment = pbGetEnvironment
else
battle.environment = battleRules["environment"]
end
# Backdrop graphic filename
if !battleRules["backdrop"].nil?
backdrop = battleRules["backdrop"]
elsif $PokemonGlobal.nextBattleBack
backdrop = $PokemonGlobal.nextBattleBack
elsif $PokemonGlobal.surfing
backdrop = "water" # This applies wherever you are, including in caves
else
back = pbGetMetadata($game_map.map_id,MetadataBattleBack)
backdrop = back if back && back!=""
end
backdrop = "indoor1" if !backdrop
battle.backdrop = backdrop
# Choose a name for bases depending on environment
if battleRules["base"].nil?
case battle.environment
when PBEnvironment::Grass, PBEnvironment::TallGrass,
PBEnvironment::ForestGrass; base = "grass"
# when PBEnvironment::Rock; base = "rock"
when PBEnvironment::Sand; base = "sand"
when PBEnvironment::MovingWater, PBEnvironment::StillWater; base = "water"
when PBEnvironment::Puddle; base = "puddle"
when PBEnvironment::Ice; base = "ice"
end
else
base = battleRules["base"]
end
battle.backdropBase = base if base
# Time of day
if pbGetMetadata($game_map.map_id,MetadataEnvironment)==PBEnvironment::Cave
battle.time = 2 # This makes Dusk Balls work properly in caves
elsif TIME_SHADING
timeNow = pbGetTimeNow
if PBDayNight.isNight?(timeNow); battle.time = 2
elsif PBDayNight.isEvening?(timeNow); battle.time = 1
else; battle.time = 0
end
end
#techfore
if !battleRules["foreground"].nil?
battle.foreground = battleRules["foreground"]
end
end
You'll need a new folder in Graphics/Battlebacks titled "Foregrounds". Name a file in there anything you want, and then to use it in battle, just call
setBattleRule("foreground","filename")
before the battle!Graphics should be on a 512x288 canvas, or whatever canvas size your battlebacks are on.
A sample foreground can be found in the download link, which was generously made public by NocTurn! Be sure to credit him if you use it in your projects, and be sure to check out Pokémon Champions, the game it was made for!
- Credits
- TechSkylander1518- Code
NocTurn- Concept, and graphic, if used