thepsynergist

A Gym Leader, Kyushu Region

Age 30
Male
California, USA
Seen 2 Days Ago
Posted 3 Weeks Ago
790 posts
11.7 Years
-Made with Pkmn Essentials v17.2 + EBS in mind.

If you use Pokemon Reborn's Battle Animations files in your game, and you also use the EBS system, you may notice a 1.5 second hang each time the game loads a battle animation. You can remove this lag by caching the animations files. Here's a handy tutorial to help you out!


-First things first, this will obviously only work if you use Pokemon Reborn's animations. So, download the game and copy over two files from the "Data" folder, and paste them inside the "Data" folder of your project.


PkmnAnimations.rxdata
Move2anim.dat

-Then, open your script editor within your project.

-Go to your EBS Settings (SJPlugins_Settings), and set

CUSTOMANIMATIONS = false REPLACEMISSINGANIM = true
-Then, make a new script section above "Main", and paste the following code:

Spoiler:

#Animations Cache
class PokemonTemp
  attr_accessor :cachePkmnAnims
end

def pbLoadCachedAnimations
  $PokemonTemp=PokemonTemp.new if !$PokemonTemp
  if !$PokemonTemp.cachePkmnAnims
    $PokemonTemp.cachePkmnAnims=load_data("Data/PkmnAnimations.rxdata")
  end
  return $PokemonTemp.cachePkmnAnims
end



-Then, make another new section and paste this:

Spoiler:

#Moves2Anim Cache
class PokemonTemp
  attr_accessor :cachePkmnAnims2
end

def pbLoadCachedAnimations2
  $PokemonTemp=PokemonTemp.new if !$PokemonTemp
  if !$PokemonTemp.cachePkmnAnims2
    $PokemonTemp.cachePkmnAnims2=load_data("Data/move2anim.dat")
  end
  return $PokemonTemp.cachePkmnAnims2
end



-Next, go to PField_Metadata, and go to class PokemonTemp, and add the following to the bottom of the class, under forceSingleBattle:

  attr_accessor :cachePkmnAnims
  attr_accessor :cachePkmnAnims2

-After you do that, go to PokeBattle_Scene, in the def pbFindAnimation, where move2anim is referenced and replace the line:

move2anim=load_data("Data/move2anim.dat")
with
move2anim=pbLoadCachedAnimations2

-Next, go to the def pbCommonAnimation, and replace the line:

animations=load_data("Data/PkmnAnimations.rxdata")
with
animations=pbLoadCachedAnimations

-Right below in pbAnimation, replace the line:

animations=load_data("Data/PkmnAnimations.rxdata")
with
animations=pbLoadCachedAnimations

Now, in the script section EliteBattle_2 (or Animations Script if it's renamed) under def PbAnimation, below "anim=animid[0]" replace:

animations=load_data("Data/PkmnAnimations.rxdata")
with
animations=pbLoadCachedAnimations

In the script section EliteBattle_7 (), under "if REPLACEMISSINGANIM" right under "anim=animid[0], replace

animations=load_data("Data/PkmnAnimations.rxdata")
with
animations=pbLoadCachedAnimations

Lastly, if you happen to use KleinStudio's Transform Mosaic script, go to the class PokeBattle_Scene's def pbAnimation, under anim=animid[0], replace:

animations=load_data("Data/PkmnAnimations.rxdata")
with
animations=pbLoadCachedAnimations

Once you do all that, you should have lagless battle animations! Let me know if you have any questions!




Pokemon Pyrite is now complete, check out the trailer/download link here: https://www.youtube.com/watch?v=X6g5pXPXyV4

thepsynergist

A Gym Leader, Kyushu Region

Age 30
Male
California, USA
Seen 2 Days Ago
Posted 3 Weeks Ago
790 posts
11.7 Years
Calling the battleback as this:

`@scene.sprites["battlebg"].setBitmap("XXX",@scene)` where XXX is the name of the battleback.

might prevent lag from being formed. I don't have an issue with battleback changing lag, but it might have had to do with how you were calling it.




Pokemon Pyrite is now complete, check out the trailer/download link here: https://www.youtube.com/watch?v=X6g5pXPXyV4

thepsynergist

A Gym Leader, Kyushu Region

Age 30
Male
California, USA
Seen 2 Days Ago
Posted 3 Weeks Ago
790 posts
11.7 Years
I forgot one thing (thanks Vendily). The game won't cache the animations on a new game unless you add this:

-Next, go to PScreen_Load, and go to the elsif statement mentioning cmdNewGame (should be around line 403), and paste the following directly after the line, "$game_map.autoplay":
        pbLoadCachedAnimations
        pbLoadCachedAnimations2




Pokemon Pyrite is now complete, check out the trailer/download link here: https://www.youtube.com/watch?v=X6g5pXPXyV4

thepsynergist

A Gym Leader, Kyushu Region

Age 30
Male
California, USA
Seen 2 Days Ago
Posted 3 Weeks Ago
790 posts
11.7 Years
It works perfectly, the problem is that after passing a combat the fps drops (and the character walks with frame stops) and sometimes it can even crash. Why does this happen? I've seen it happen to quite a few people.
Not sure about the fps drops, but I have seen it crash sometimes in my game when a battle starts, randomly, but I have no idea what is actually causing it. If anyone figures that out, please let me know, and i'll update the thread.




Pokemon Pyrite is now complete, check out the trailer/download link here: https://www.youtube.com/watch?v=X6g5pXPXyV4
Seen July 21st, 2020
Posted May 19th, 2020
6 posts
197 Days
Not sure about the fps drops, but I have seen it crash sometimes in my game when a battle starts, randomly, but I have no idea what is actually causing it. If anyone figures that out, please let me know, and i'll update the thread.
hi so i hella did not know this was a thing and ended up making my own. it just throws the entire animation file into a global variable at load time, and it calls that variable when checking for animations.
this was how i did it: psyduck forget it i can't post links. it's on one of my devblog posts.
i dunno if this helps with yours at all, but maybe it does?


edit:
psyduck forget it i can't post links.
i hate this website.
Seen September 9th, 2020
Posted May 31st, 2020
24 posts
2.6 Years
hi so i hella did not know this was a thing and ended up making my own. it just throws the entire animation file into a global variable at load time, and it calls that variable when checking for animations.
this was how i did it: psyduck forget it i can't post links. it's on one of my devblog posts.
i dunno if this helps with yours at all, but maybe it does?


edit:


i hate this website.
Hi, sorry for my ignorance, but how could I do this with the moves?

thepsynergist

A Gym Leader, Kyushu Region

Age 30
Male
California, USA
Seen 2 Days Ago
Posted 3 Weeks Ago
790 posts
11.7 Years
Marin helped me out with this one.

alias old_load_data load_data if !defined?(old_load_data)
alias old_save_data save_data if !defined?(old_save_data)

LOAD_DATA_CACHE = {}

def load_data(filename, cache=false)
  LOAD_DATA_CACHE.fetch(filename) do
    data = old_load_data(filename)
    LOAD_DATA_CACHE[filename] = data if cache
    next data
  end
end

def save_data(data, filename)
  LOAD_DATA_CACHE[filename] = data
  return old_save_data(data, filename)
end

def preload_data(filename)
  load_data(filename, true)
  return nil
end
You'd call the animation calls in script with:
animations=load_data("Data/PkmnAnimations.rxdata", true)

instead of:
animations=load_data("Data/PkmnAnimations.rxdata")

I'll have to remake my tutorial sometime, but this prevents the crashing, that I've noticed. You can also use this to cache other stuff, like tilesets, if your tilesets are too large.




Pokemon Pyrite is now complete, check out the trailer/download link here: https://www.youtube.com/watch?v=X6g5pXPXyV4
Seen September 9th, 2020
Posted May 31st, 2020
24 posts
2.6 Years
Marin helped me out with this one.

alias old_load_data load_data if !defined?(old_load_data)
alias old_save_data save_data if !defined?(old_save_data)

LOAD_DATA_CACHE = {}

def load_data(filename, cache=false)
  LOAD_DATA_CACHE.fetch(filename) do
    data = old_load_data(filename)
    LOAD_DATA_CACHE[filename] = data if cache
    next data
  end
end

def save_data(data, filename)
  LOAD_DATA_CACHE[filename] = data
  return old_save_data(data, filename)
end

def preload_data(filename)
  load_data(filename, true)
  return nil
end
You'd call the animation calls in script with:
animations=load_data("Data/PkmnAnimations.rxdata", true)

instead of:
animations=load_data("Data/PkmnAnimations.rxdata")

I'll have to remake my tutorial sometime, but this prevents the crashing, that I've noticed. You can also use this to cache other stuff, like tilesets, if your tilesets are too large.
But then would this script be added after "Moves2Anim Cache" and replace "animations = pbLoadCachedAnimations" with "animations = load_data (" Data / PkmnAnimations.rxdata ", true)"?

thepsynergist

A Gym Leader, Kyushu Region

Age 30
Male
California, USA
Seen 2 Days Ago
Posted 3 Weeks Ago
790 posts
11.7 Years
It would replace it entirely, which is why I have to rewrite the tutorial. This is caching them outside the $Pokemon.Temp, which was causing the crashes, iirc, as that gets flushed occasionally, so the animations that were cached were nil'd when called. That's my theory as to why it was crashing, anyway.




Pokemon Pyrite is now complete, check out the trailer/download link here: https://www.youtube.com/watch?v=X6g5pXPXyV4
Seen July 21st, 2020
Posted May 19th, 2020
6 posts
197 Days
Are you the same andracass from Pokemon Reborn?

No worries, I got you:
yup, that's me.
hopefully if you add this to the end of that link, it'll actually take you to the comment where i go over this.
/records/183-beta-r53/?do=findComment&comment=1409

wow i also can't quote urls. what an experience.
Seen September 9th, 2020
Posted May 31st, 2020
24 posts
2.6 Years
yup, that's me.
hopefully if you add this to the end of that link, it'll actually take you to the comment where i go over this.
/records/183-beta-r53/?do=findComment&comment=1409

wow i also can't quote urls. what an experience.

I have followed all the steps but I receive this error when using or receiving any move.

Spoiler:
[Pokémon Essentials version 17.2]
Exception: NoMethodError
Message: undefined method `[]' for nil:NilClass
PokeBattle_Scene:3006:in `pbAnimation'
PokeBattle_Scene:3002:in `pbSaveShadows'
PokeBattle_Scene:3008:in `pbAnimation'
PokeBattle_Battle:2381:in `pbAnimation'
PokeBattle_Move:1452:in `pbShowAnimation'
PokeBattle_Move:1415:in `pbEffect'
PokeBattle_Battler:3087:in `pbProcessMoveAgainstTarget'
PokeBattle_Battler:2989:in `each'
PokeBattle_Battler:2989:in `pbProcessMoveAgainstTarget'
PokeBattle_Battler:3566:in `pbUseMove'