• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Help with mega evolving rotom

172
Posts
7
Years
    • Seen Sep 6, 2022
    We found a solution for a Mega Rotom script, just scroll to the bottom if you'd like to know how it works and be able to use it for yourself :)


    So essentially what I wanted was a rotom that can mega evolve from any rotom form. For example, Rotom Heat can mega evolve into my Mega Rotom and it'll have Overheat, or you can have the normal Rotom and still mega evolve it into the same mega. So I was thinking about how to do this and I started by just adding a 6th Rotom in the Pokémon Forms PBS which would be the mega and when I went into the game to test it, it actually worked! Any of the Rotom forms can hold the mega stone and all evolve into the same mega regardless of its original form.

    The only error I'm having is with the mega evolve mechanics, because after the battle, it changes Rotom back to it's base Rotom form, instead of what it was, so Rotom Heat mega evolves, then after the battle it switches back to plain old Rotom and forgets Overheat. Is there a way to script that specific mega form to make sure it reverts back to the right form after each battle?
     
    Last edited:
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    So I think you want to look at Pokemon_MegaEvolution, and in particular makeUnmega/getUnmegaForm.

    Personally I think this is a bug in Essentials, and the way that makeUnmega should work is by restoring whichever form the Pokémon had before it mega evolved. You could do this by remembering the original form in makeMega, and restoring it in makeUnmega.
     
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    So I think you want to look at Pokemon_MegaEvolution, and in particular makeUnmega/getUnmegaForm.

    Personally I think this is a bug in Essentials, and the way that makeUnmega should work is by restoring whichever form the Pokémon had before it mega evolved. You could do this by remembering the original form in makeMega, and restoring it in makeUnmega.

    Yeah that seems like a good idea. Im looking at it now, would you happen to have an idea about which section I should try editing specifically? and how I would go about doing it? or even making its own separate script in that section just for rotom? I noticed kyogre and groudon have their own section because of the way they mega evolve, so maybe putting something together from scratch is the way to go to get the right result. Im just not good enough at scripting yet to make something like that
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Yeah that seems like a good idea. Im looking at it now, would you happen to have an idea about which section I should try editing specifically? and how I would go about doing it? or even making its own separate script in that section just for rotom? I noticed kyogre and groudon have their own section because of the way they mega evolve, so maybe putting something together from scratch is the way to go to get the right result. Im just not good enough at scripting yet to make something like that

    My recommendation is to have makeMega save the current form, and makeUnmage restore it. To do this you'll need an extra attribute on your objects that holds the current form. You can use an attr_accessor to add a new variable to your object (take a look at PokeBattle_Pokemon for some examples). And then it should be as simple as getting makeMega to write self.form to this variable before it changes the form, and then getting makeUnmega to set the form to the saved form, if it exists (i.e. was written to/is non-nil), and possibly unset the saved form.
     
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    My recommendation is to have makeMega save the current form, and makeUnmage restore it. To do this you'll need an extra attribute on your objects that holds the current form. You can use an attr_accessor to add a new variable to your object (take a look at PokeBattle_Pokemon for some examples). And then it should be as simple as getting makeMega to write self.form to this variable before it changes the form, and then getting makeUnmega to set the form to the saved form, if it exists (i.e. was written to/is non-nil), and possibly unset the saved form.

    so I ended up making a sample script based off of what I saw on this thread about mega evolving raichu and alolan raichu
    https://www.pokecommunity.com/showthread.php?t=375737

    and this is my script based off of that
    Spoiler:


    if there's any confusion about why theres so many forms it goes as follows:
    Spoiler:


    im not sure if theres an easier way to format it because im still new to scripting but for me to understand its the easiest way, I just made a new form in PBS pokemon forms for each one so technically they would each have their own mega but it would appear as if they were all the same mega rotom regardless of which form they started in.

    MY ACTUAL PROBLEM
    when I put this script into essentials it game me a syntax error on boot up to the bottom of Pokémon_MegaEvolution. So there's an error somewhere in the script I just don't know where. I;ve heard when you get a syntax error to your bottom line it means you forgot an "end" somewhere but im not sure where they would go. would you or anyone else be able to tell me where I may have messed up in this script?
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    MY ACTUAL PROBLEM
    when I put this script into essentials it game me a syntax error on boot up to the bottom of Pokémon_MegaEvolution. So there's an error somewhere in the script I just don't know where. I;ve heard when you get a syntax error to your bottom line it means you forgot an "end" somewhere but im not sure where they would go. would you or anyone else be able to tell me where I may have messed up in this script?
    You're right, it's usually a missing end, but in this case I think it's missing } at the end of your onSetForm proc (or maybe that's just a copy-paste error)?

    im not sure if theres an easier way to format it because im still new to scripting but for me to understand its the easiest way, I just made a new form in PBS pokemon forms for each one so technically they would each have their own mega but it would appear as if they were all the same mega rotom regardless of which form they started in.
    Just to say, yeah this is a pretty inelegant way to solve the problem but that's okay, if it works, it works :)

    You're basically storing the old form in the new form, which is a kinda neat way to do things. Although your math is a little off (what do you think "& 2" and "% 2" do?)
     
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    You're right, it's usually a missing end, but in this case I think it's missing } at the end of your onSetForm proc (or maybe that's just a copy-paste error)?


    Just to say, yeah this is a pretty inelegant way to solve the problem but that's okay, if it works, it works :)

    You're basically storing the old form in the new form, which is a kinda neat way to do things. Although your math is a little off (what do you think "& 2" and "% 2" do?)

    it might be a copy paste error, ill take a look into that soon.

    and im not 100% sure the difference honestly haha. from what I saw in that other post about alolan raichu mega evolving it seemed like it was just used as part of the script for calling another one of the raichu forms. what exactly did I do wrong with that part? haha
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    what exactly did I do wrong with that part? haha

    Ah, I don't want to spoil it, I'm confident that you can work it out for yourself. If you get stuck I have some hints, but honestly I don't think you need them, or should use them:

    Spoiler:
     
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    Ah, I don't want to spoil it, I'm confident that you can work it out for yourself. If you get stuck I have some hints, but honestly I don't think you need them, or should use them:

    Spoiler:

    so I fixed the syntax error, you were right I forgot to paste the very last line of the script. so I got into the game and tested the script, no errors came up, it actually just did the same exact thing as before. I mega evolved rotom heat and then after the battle it went back to regular rotom unfortunately.

    just to be clear this goes in the mega pokemon section of the scripts right?
    and in that section should I put it in a certain place or just anywhere?

    also would the %2 be like...5 or 6 instead? is that number based off of how many forms there are from the original? so in this case each mega being a new form and I have 6 megas in this strand.
     
    Last edited:
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    so I fixed the syntax error, you were right I forgot to paste the very last line of the script. so I got into the game and tested the script, no errors came up, it actually just did the same exact thing as before. I mega evolved rotom heat and then after the battle it went back to regular rotom unfortunately.

    just to be clear this goes in the mega pokemon section of the scripts right?
    and in that section should I put it in a certain place or just anywhere?
    Yeah, I think that you've put the code in the right place.

    also would the %2 be like...5 or 6 instead? is that number based off of how many forms there are from the original? so in this case each mega being a new form and I have 6 megas in this strand.

    % 2 is "what is the remainder after I divide by 2", so yes, I would expect to see some really weird stuff happening when your Rotoms unmega.
    Likewise I think getMegaForm has a weird way of mapping from a regular form number to a mega form number. & 2 is "mask the bits of my number against the binary number 10", which can only produce 0 or 2; it does this 0?0, 1?0, 2?2, 3?2, 4?0, 5?0. I would expect to see it map each Rotom to its mega number, like in your table:

    Code:
    0-rotom normal  6-mega rotom from form 0
    1-rotom heat    7-mega rotom from form 1
    2-rotom wash    8-mega rotom from form 2
    3-rotom frost   9-mega rotom from form 3
    4-rotom fan     10-mega rotom from form 4
    5-rotom mow     11-mega rotom from form 5

    So getMegaForm is taking columns on the left, and returning the values on the right (and either leaving values on the right the same, or ignoring them?I am not sure which).
    And getUnmegaForm is taking columns on the right, and returning the values on the left (probably with the same "return values on the left or ignore" behavior as form getMegaForm).
     
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    Yeah, I think that you've put the code in the right place.



    % 2 is "what is the remainder after I divide by 2", so yes, I would expect to see some really weird stuff happening when your Rotoms unmega.
    Likewise I think getMegaForm has a weird way of mapping from a regular form number to a mega form number. & 2 is "mask the bits of my number against the binary number 10", which can only produce 0 or 2; it does this 0?0, 1?0, 2?2, 3?2, 4?0, 5?0. I would expect to see it map each Rotom to its mega number, like in your table:

    Code:
    0-rotom normal  6-mega rotom from form 0
    1-rotom heat    7-mega rotom from form 1
    2-rotom wash    8-mega rotom from form 2
    3-rotom frost   9-mega rotom from form 3
    4-rotom fan     10-mega rotom from form 4
    5-rotom mow     11-mega rotom from form 5

    So getMegaForm is taking columns on the left, and returning the values on the right (and either leaving values on the right the same, or ignoring them?I am not sure which).
    And getUnmegaForm is taking columns on the right, and returning the values on the left (probably with the same "return values on the left or ignore" behavior as form getMegaForm).

    so are you saying if I did &2 instead of %2 for my script it would work out the numbers better? or do I need to have a different number on each line if I did %2 so something like %2, %3...?

    I mean ill try it out next time I open essentials, I just figured id ask now when you seem to be on for any other useful information that I can try out once I go back into my script. we're on pretty different time zones and im heading to sleep soon haha.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    so are you saying if I did &2 instead of %2 for my script it would work out the numbers better? or do I need to have a different number on each line if I did %2 so something like %2, %3...?

    I mean ill try it out next time I open essentials, I just figured id ask now when you seem to be on for any other useful information that I can try out once I go back into my script. we're on pretty different time zones and im heading to sleep soon haha.

    You are already using both & 2 and %2 (in getMegaForm and getUnmegaForm respectively). I am sure that you don't want to use &, because your numbers don't really work out for that. & is useful for extracting bits from numbers, but usually you only want to do that if the individual bits have some meaning, or sometimes you can use it like an % if the number you would be dividing by is a power of 2 (i.e. 1, 2, 4, 8, 16, ?).

    Let's try solving it from scratch. If we look at makeMega we can see that getMegaForm should return the number of the form to mega-evolve into or 0 if the Pok?mon cannot mega evolve; and in makeUnmega we can see that getUnmegaForm should return the fom number of the Pok?mon before mega evolution, or -1 if the Pok?mon was not mega evolved.

    Code:
    def makeMega
      fsp = self.getMegaForm
      if fsp>0 # Only if getMegaForm returns non-zero.
        f = pbGetSpeciesFromFSpecies(fsp)[1]
        self.form = f
      end
    end
    
    def makeUnmega
      newf = self.getUnmegaForm
      self.form = newf if newf>=0 # Only if getUnmegaForm returns non-minus-one.
    end

    You have this table of forms:
    Code:
    0-rotom normal  6-mega rotom from form 0
    1-rotom heat    7-mega rotom from form 1
    2-rotom wash    8-mega rotom from form 2
    3-rotom frost   9-mega rotom from form 3
    4-rotom fan     10-mega rotom from form 4
    5-rotom mow     11-mega rotom from form 5

    Let's start with getMegaForm:

    Code:
    # 1. We cannot mega evolve.
    "getMegaForm"=>proc{|pokemon|
      next 0
    },
    
    # 2. We can mega evolve, but only into form 6, i.e. the regular rotom-mega.
    "getMegaForm"=>proc{|pokemon|
      next 6 if isConst?(pokemon.item,PBItems,:ROTOMITE)
      next 0
    },
    
    # 3. We can mega evolve, into an appropriate form number. All we've done is copy the table from above.
    "getMegaForm"=>proc{|pokemon|
      next 6 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 0
      next 7 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 1
      next 8 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 2
      next 9 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 3
      next 10 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 4
      next 11 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 5
      next 0
    },
    
    # 4. 3, simplified.
    "getMegaForm"=>proc{|pokemon|
      next (pokemon.form + 6) if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form <= 5
      next 0
    },

    And now getUnmegaForm:

    Code:
    # 1. We cannot unmega.
    "getUnmegaForm"=>proc{|pokemon|
      next -1
    },
    
    # 2. We unmega into regular Rotom if we were mega evolved.
    "getUnmegaForm"=>proc{|pokemon|
      next 0 if pokemon.form >= 6
      next -1
    },
    
    # 3. We unmega into the Rotom form we started with. Copied from the table above.
    "getUnmegaForm"=>proc{|pokemon|
      next 0 if pokemon.form == 6
      next 1 if pokemon.form == 7
      next 2 if pokemon.form == 8
      next 3 if pokemon.form == 9
      next 4 if pokemon.form == 10
      next 5 if pokemon.form == 11
      next -1
    },
    
    # 4. Again, 3, simplified.
    "getUnmegaForm"=>proc{|pokemon|
      next (pokemon.form - 6) if pokemon.form >= 6
      next -1
    },

    I haven't actually tried any of this, so it might not work as-is, but I'm sure you can figure it out in the morning.
     
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    You are already using both & 2 and %2 (in getMegaForm and getUnmegaForm respectively). I am sure that you don't want to use &, because your numbers don't really work out for that. & is useful for extracting bits from numbers, but usually you only want to do that if the individual bits have some meaning, or sometimes you can use it like an % if the number you would be dividing by is a power of 2 (i.e. 1, 2, 4, 8, 16, ?).

    Let's try solving it from scratch. If we look at makeMega we can see that getMegaForm should return the number of the form to mega-evolve into or 0 if the Pok?mon cannot mega evolve; and in makeUnmega we can see that getUnmegaForm should return the fom number of the Pok?mon before mega evolution, or -1 if the Pok?mon was not mega evolved.

    Code:
    def makeMega
      fsp = self.getMegaForm
      if fsp>0 # Only if getMegaForm returns non-zero.
        f = pbGetSpeciesFromFSpecies(fsp)[1]
        self.form = f
      end
    end
    
    def makeUnmega
      newf = self.getUnmegaForm
      self.form = newf if newf>=0 # Only if getUnmegaForm returns non-minus-one.
    end

    You have this table of forms:
    Code:
    0-rotom normal  6-mega rotom from form 0
    1-rotom heat    7-mega rotom from form 1
    2-rotom wash    8-mega rotom from form 2
    3-rotom frost   9-mega rotom from form 3
    4-rotom fan     10-mega rotom from form 4
    5-rotom mow     11-mega rotom from form 5

    Let's start with getMegaForm:

    Code:
    # 1. We cannot mega evolve.
    "getMegaForm"=>proc{|pokemon|
      next 0
    },
    
    # 2. We can mega evolve, but only into form 6, i.e. the regular rotom-mega.
    "getMegaForm"=>proc{|pokemon|
      next 6 if isConst?(pokemon.item,PBItems,:ROTOMITE)
      next 0
    },
    
    # 3. We can mega evolve, into an appropriate form number. All we've done is copy the table from above.
    "getMegaForm"=>proc{|pokemon|
      next 6 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 0
      next 7 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 1
      next 8 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 2
      next 9 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 3
      next 10 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 4
      next 11 if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form == 5
      next 0
    },
    
    # 4. 3, simplified.
    "getMegaForm"=>proc{|pokemon|
      next (pokemon.form + 6) if isConst?(pokemon.item,PBItems,:ROTOMITE) && pokemon.form <= 5
      next 0
    },

    And now getUnmegaForm:

    Code:
    # 1. We cannot unmega.
    "getUnmegaForm"=>proc{|pokemon|
      next -1
    },
    
    # 2. We unmega into regular Rotom if we were mega evolved.
    "getUnmegaForm"=>proc{|pokemon|
      next 0 if pokemon.form >= 6
      next -1
    },
    
    # 3. We unmega into the Rotom form we started with. Copied from the table above.
    "getUnmegaForm"=>proc{|pokemon|
      next 0 if pokemon.form == 6
      next 1 if pokemon.form == 7
      next 2 if pokemon.form == 8
      next 3 if pokemon.form == 9
      next 4 if pokemon.form == 10
      next 5 if pokemon.form == 11
      next -1
    },
    
    # 4. Again, 3, simplified.
    "getUnmegaForm"=>proc{|pokemon|
      next (pokemon.form - 6) if pokemon.form >= 6
      next -1
    },

    I haven't actually tried any of this, so it might not work as-is, but I'm sure you can figure it out in the morning.


    it keeps giving me syntax errors on the "getmegaform"=proc{|pokemon| lines but im not sure why. its formatted the same way as the other mega pokemon scripts, the only thing I can see is it might not match up with the def somewhere but im not sure. im bad when it comes to syntax errors lol
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    it keeps giving me syntax errors on the "getmegaform"=proc{|pokemon| lines but im not sure why. its formatted the same way as the other mega pokemon scripts, the only thing I can see is it might not match up with the def somewhere but im not sure. im bad when it comes to syntax errors lol

    What exactly are you typing? The stuff I gave is mostly just to show you how it's done/how to build up to a solution, you only need one getMakeForm and one getUnmegaForm to replace the ones you already had.
     
    Last edited:
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    Hey guys, so me and mgriffin were able to come to a solution! Just follow these steps and it'll work just fine! Basically the end goal here was to have a Rotom that can mega evolve from any form.

    For example, Rotom Wash and Rotom Fan can both mega evolve, but the mega they become is the same one. For my game specifically I game Mega Rotom Protean as it's ability because I thought the idea of Rotom having all these different moves like Hydro Pump or Overheat based on it's form would pair really well with Protean, but feel free to use it any way you want!


    The error we were having with the original Mega Rotom was that regardless of which form it mega evolved in, wash, fan, etc. it would always revert back to the original Rotom form at the end of battle. Now with these edits, it'll retain it's form after the battle!

    Edit these lines in your script editor, - is to remove the line + is what you add...

    in PokeBattle_Pokemon
    Spoiler:

    After "class PokeBattle_Pokemon" but before "def getMegaForm(itemonly=false)" add a line that says "attr_accessor(:unmegaform)". This will be the variable that stores which form to turn back into when we unmega.


    In Pok?mon_MegaEvolution...
    Spoiler:

    Add "self.unmegaform = self.form" at the start of makeMega. This saves the current form as we mega evolve so that we can restore it later.



    Spoiler:


    Change the "newf = self.getUnmegaForm" line to check for a previously-saved form, then forget about that form with "self.unmegaform = nil". "x || y" returns x if x is not-nil, and y otherwise. If unmegaform has not been written to yet (i.e. somehow this function is called without having mega evolved) it will be nil, and we will fall back to the old behavior.

    CHANGING THIS FIXES THE AFTER BATTLE BUG

    Spoiler:
     
    Last edited:
    172
    Posts
    7
    Years
    • Seen Sep 6, 2022
    The only known bug with this script is in the game normally when you change into a Rotom form it will learn it's corresponding move, Hydro Pump, Overheat... so when you use Mega Rotom, after the battle the screen will fade to black and it'll show a promt "Rotom learned Hydro Pump!" or whichever move corresponds to your form. Then everything will continue normally. It's not a bug that break or affects anything, just something that happens. I haven't gotten the chance to find out exactly where it does that yet, but I'll be sure to post it on here if we can stop it from doing that!

    Also, just in case this wasn't obvious, you have to go into you Pok?mon Forms PBS and add Mega Rotom as a new Rotom form, after the current forms. Defining a Mega Pok?mon like you would any other.
     
    Back
    Top