• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • 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] How do I give a Pokemon a "Bonus Value" I can modify that's 0 by default, and another that's randomly-selected? I've got a custom feature in mind.

  • 413
    Posts
    5
    Years
    How do I give a Pokemon a "Bonus Value" I can modify that's 0 by default, and another that's randomly-selected? I've got a custom feature in mind.

    How do I give a Pokemon a "Bonus Value" I can modify that's 0 by default, but can be modified to anything between 0 and 18 in a dedicated NPC's multiple-choice menu...

    and another "Bonus Value 2" between 0 and 4 that's randomly-generated and set in stone once the pokemon with it is generated?

    I've got a custom feature in mind that will require these features and it uses some in-progress custom scripting I'm working on. Basically it will check those two values and do stuff. but first, i need to know how to set those values in this engine.

    If you help, I'll give the scripting used in this feature out once I release the pokemon essentials game that uses it. Anyone will be free to use this feature in their games. And it will be a great feature.
     
    Last edited:
    Look inside the script section PokeBattle_Pokemon. You can create your own attribute by adding to the list of attr_accessor's:
    Code:
    attr_accessor(:newValue)
    Then, initialize your new attribute at the very bottom of "def initialize" with:
    Code:
    @newValue = 0
    Basically just look at how other attr_accessor's are handled and copy accordingly.
     
    Thank you, this seems to work so far. Final pieces of the puzzle:

    How do I get NPCs to let the player pick a pokemon in their party, check what a chosen Pokemon's attr_accessor is, and react differently depending on its number? Like those "Check temporary choice number" codes but specifically for that attr_accessor.

    How do I get a custom attr_accessor to set itself as a random number from 0 to 4 on pokemon creation? (ideally this will also affect wild pokemon and trainer pokemon, but i don't care about changing the custom attrs of trainer pokemon to specific numbers)

    How do I get NPCs to let the player pick a pokemon in their party, and set one of that pokemon's custom attr_accessors of my choice to a number of my choice?

    Once I know all of these things, I will be able to code everything else solo. It will be a truly incredible feature. Everyone will love it. Many people will probably use it in their fangames. I'm tempted to spoil what it is, but I can't do that until the game's done.
     
    Last edited:
    To make it random, do the same thing you did before to create your other accessor, but in the initialize def, set it as a random number out of 4 rather than zero.

    To change one of these accessors to a specific number via an event, just insert a script in the event that just literally changes the number. Something like "pkmn.accessorname = number", where "pkmn" is equal the Pokemon you selected (accomplished with pbChoosePokemon), "accessorname" is the name of the attr_accessor that youre changing, and "number" is the desired number.

    Look at the example events that come with Essentials as your guide. Any event that allows you to choose a specific Pokemon from your party (move deleter/relearner, day care, trades, etc) will give you a clearer idea.
     
    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 17.2]

    Exception: RuntimeError

    Message: Script error within event 30 (coords 27,5), map 3 (AAA's house):

    Exception: ArgumentError

    Message: PokeBattle_Pokemon:911:in `PokemonSize'wrong number of arguments(1 for 0)

    ***Full script:

    pkmn = pbGenPkmn(:PIKACHU,1)
    pbAddForeignPokemon(pkmn)


    Interpreter:243:in `pbExecuteScript'

    PokeBattle_Pokemon:911:in `calcStats'

    PokeBattle_Pokemon:1000:in `__mf_initialize'

    Pokemon_Forms:43:in `initialize'

    PokeBattle_Pokemon:1020:in `new'

    PokeBattle_Pokemon:1020:in `pbGenPkmn'

    (eval):1:in `pbExecuteScript'

    Interpreter:1606:in `eval'

    Interpreter:243:in `pbExecuteScript'

    Interpreter:1606:in `command_355'



    Interpreter:276:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:163:in `update'

    Scene_Map:161:in `loop'

    Scene_Map:170:in `update'

    Scene_Map:234:in `main'



    This exception was logged in

    C:\Users\MYNAME\Saved Games\Pokemon Essentials\errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------

    What have I done wrong?

    I added this
    if PokemonSize(:PokemonSize)==0
    pvalues=[100,100,100,100,500]
    end
    to def calcstats under the Natures stuff,

    and @PokemonSize = rand(4)
    is in def initialize under @eggsteps.

    The "Pokemon Size" term and terrible stat change used here is just a placeholder for making sure the code works(easier to see a very visible size boost than a barely-noticeable one), this won't involve the existing Fishing Guru's Size-Judging code in any way.
     
    Last edited:
    What have I done wrong?

    The error says what's wrong.
    Code:
    Message: PokeBattle_Pokemon:911:in `PokemonSize'wrong number of arguments(1 for 0)

    You have an argument listed for 'PokemonSize' when it isn't expecting one to be there.

    The code you inputted:
    Code:
    if PokemonSize(:PokemonSize)==0
    pvalues=[100,100,100,100,500]
    end

    You have an argument in parentheses, but there shouldn't be one there unless you created a method for it that includes an argument. What would probably make more sense is if you wrote it like:
    Code:
    if self.pokemonSize==0
     
    yes

    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 17.2]

    Exception: RuntimeError

    Message: Script error within event 30 (coords 27,5), map 3 (AAA's house):

    Exception: NoMethodError

    Message: PokeBattle_Pokemon:911:in `calcStats'undefined method `pokemonSize' for #<PokeBattle_Pokemon:0xf415a08>

    ***Full script:

    pkmn = pbGenPkmn(:PIKACHU,1)
    pbAddForeignPokemon(pkmn)


    Interpreter:243:in `pbExecuteScript'

    PokeBattle_Pokemon:1000:in `__mf_initialize'

    Pokemon_Forms:43:in `initialize'

    PokeBattle_Pokemon:1020:in `new'

    PokeBattle_Pokemon:1020:in `pbGenPkmn'

    (eval):1:in `pbExecuteScript'

    Interpreter:1606:in `eval'

    Interpreter:243:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'



    Interpreter:276:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:163:in `update'

    Scene_Map:161:in `loop'

    Scene_Map:170:in `update'

    Scene_Map:234:in `main'



    This exception was logged in

    C:\Users\Jason\Saved Games\Pokemon Essentials\errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------

    edit: that aipom is (eval) : 1 :
     
    That's not the same error, it's pointing to something different this time.
    Code:
    Message: PokeBattle_Pokemon:911:in `calcStats'undefined method `pokemonSize' for #<PokeBattle_Pokemon:0xf415a08>
    It seems to be saying that the Pokemon you're selecting to change doesn't have any values assigned to whatever this "pokemonSize" attribute is supposed to be set to. This is either because you're testing this on a Pokemon that existed prior to adding this attribute (and thus, won't have anything assigned to it), or because you didn't add this attribute to the initialize def (and thus, will not spawn with anything assigned to it).

    Basically you just need to make sure that "pokemonSize" is set up properly as a value that is initialized upon the Pokemon's creation. Any Pokemon that was created prior to adding this in will obviously not have this attribute, however. So you're better off starting a new game after adding it in so that every Pokemon is sure to spawn with this attribute.
     
    I started a new save, but the error happened when I got my starter.

    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 17.2]

    Exception: RuntimeError

    Message: Script error within event 30 (coords 27,5), map 3 (AAA's house):

    Exception: NoMethodError

    Message: PokeBattle_Pokemon:911:in `calcStats'undefined method `pokemonSize' for #<PokeBattle_Pokemon:0xeedc8a0>

    ***Full script:

    pkmn = pbGenPkmn(:PIKACHU,1)
    pbAddForeignPokemon(pkmn)


    Interpreter:243:in `pbExecuteScript'

    PokeBattle_Pokemon:1000:in `__mf_initialize'

    Pokemon_Forms:43:in `initialize'

    PokeBattle_Pokemon:1020:in `new'

    PokeBattle_Pokemon:1020:in `pbGenPkmn'

    (eval):1:in `pbExecuteScript'

    Interpreter:1606:in `eval'

    Interpreter:243:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'



    Interpreter:276:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:163:in `update'

    Scene_Map:161:in `loop'

    Scene_Map:170:in `update'

    Scene_Map:234:in `main'



    This exception was logged in

    C:\Users\MYNAME\Saved Games\Pokemon Essentials\errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------
     
    Alright, it's all coming together. The game no longer crashes upon getting a Pokemon. How do I let an NPC check if the custom accessor PokemonSize of a Pokemon is 0, 1, 2, or 3?
     
    Back
    Top