• 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] Manipulating an Item

  • 6
    Posts
    7
    Years
    • Seen Mar 5, 2017
    Hello, I wanted to add the 12 E-Card-Reader-Berries to the Itemlist, but I don't know how to give them effects. I searched on the Pokemon Essentials Wiki, but all Indfos didn't help and so I wanted to ask if somebody knows how I could Manipulate those Berries/Items (add a effect). I hope you can help me...
     
  • 971
    Posts
    7
    Years
    • Age 22
    • Seen Nov 28, 2022
    Hello, I wanted to add the 12 E-Card-Reader-Berries to the Itemlist, but I don't know how to give them effects. I searched on the Pokemon Essentials Wiki, but all Indfos didn't help and so I wanted to ask if somebody knows how I could Manipulate those Berries/Items (add a effect). I hope you can help me...

    So a berry with an effect, ok. What effect should it be? Maybe I can help you.
     
  • 6
    Posts
    7
    Years
    • Seen Mar 5, 2017
    So a berry with an effect, ok. What effect should it be? Maybe I can help you.

    Well 10 of those Berries are just Ingredients for Poffin's/Pokéblocks, but I wanted to add an effect to ALL such Berries, that you can give them to your pokemon as food and when your pokemon eats them, the friendship will grow on +1 or +2 points, nothing special, but better than nothing. The other berry is a heal-berry, that heals your Pokémon from Infatuation. And the last berry raises a state when it's lowered in a battle. But my biggest problem is: I don't even know WHERE to manipulate them and give them those effects! Do you need an special extra software for that or did I just missunderstand something? But anyways, thank you very much that you answered me! :)
     
  • 1,682
    Posts
    8
    Years
    • Seen Jun 13, 2024
    Okay, here's what you have to do to add an effect to your berries, or literally any other item you want.
    Go to script section PItem_ItemEffects. This is where the effects are in v16+. There are a few different effects that we can make based on how the item is used (from the bag, in the field, on a pokemon, etc). We are interested in ItemHandlers::UseOnPokemon so scroll down to line 937, the bottom that section of code, so stuff stays organized. Still with me? Great!

    This here is a basic use of item script, with all the parts
    Code:
    ItemHandlers::UseOnPokemon.add(:ITEMNAME,proc{|item,pokemon,scene|
       next (boolean)
    })
    item and pokemon are variables that represents the used item and the pokemon it was used on. scene isn't all that important, don't worry about that.
    boolean is either true if the item was used or false if it wasn't. Use from bag is different, but that doesn't matter here either.

    So, your first effect is increase the happiness by 1 or 2.
    Code:
    ItemHandlers::UseOnPokemon.add(:HAPPYBERRY,proc{|item,pokemon,scene|
       Kernel.pbMessage(_INTL("{1} liked the berry!.",pokemon.name))
       pokemon.happiness+=1
       pokemon.happiness=[[255,pokemon.happiness].min,0].max
       next true
    })
    This is bare-boned, I would add some better dialogue or not let the player feed the berry if the happiness is max. Whatever.
    Now, you have some 10 berries with the same effect. You don't want to write that 10 times do you? Fortunately, there is something for that too.
    Code:
    ItemHandlers::UseOnPokemon.copy(:HAPPYBERRY,:FRIENDBERRY,:JOYBERRY,:YOUGETTHEPOINTBERRY)
    This will copy the effect from the first berry to the rest. Neat, right?

    Okay, Curing of attraction berry. Never made a battle item, but let's give it a shot.
    This is probably a BattleUseOnBattler effect, since only Battlers have in battle effects, (Pokemon in battle have a battler assigned to them which includes the inbattle stats like increasing and decreasing and confusion.)
    Code:
    ItemHandlers::BattleUseOnBattler.add(:ITEMNAME,proc{|item,battler,scene|
       return (boolean)
    })
    battler is what I mentioned earlier, and you can see the main code attached to it in the PokeBattle_Battler.

    Code:
    ItemHandlers::BattleUseOnBattler.add(:UNATTRACTBERRY,proc{|item,battler,scene|
       battle = battler.battle
       if battler.effects[PBEffects::Attract]>=0
          battle.pbDisplay(_INTL("{1} is nolonger infatuated",battler.pbThis))
          pbCureAttract
          return true
       else
          battle.pbDisplay(_INTL("It won't have any effect."))
          return false
       end
    })
    battle.pbDisplay is how we make a battle message appear. We check if the battler is infatuated and if so cure it. but we don't lose the item if the battler is not infatuated.

    Raising a lowered stat, can't really be done here. it's a battle effect, kind of like Leftovers. But, we can still do this.
    Go to script section PokeBattle_BattlerEffects, line 803 in def pbCanReduceStatStage?
    Add the lines in red.
    Code:
            if stat==PBStats::ACCURACY && hasWorkingAbility(:KEENEYE)
              abilityname=PBAbilities.getName(self.ability)
              @battle.pbDisplay(_INTL("{1}'s {2} prevents accuracy loss!",pbThis,abilityname)) if showMessages
              return false
            end
            [COLOR="Red"]if hasWorkingItem(:STATBERRY)
              berryname=PBItems.getName(self.item)
              pbConsumeItem
              @battle.pbDisplay(_INTL("{1} ate the {2} to avoid the stat loss!",pbThis,berryname)) if showMessages
              return false
            end[/COLOR]

    DISCLAMER: I have tested none of this.
    Have fun.

    OH, oh! Relevant Wiki. Sorry, I forgot.
     
    Last edited:
  • 6
    Posts
    7
    Years
    • Seen Mar 5, 2017
    Thank you sooo much! But I have to say that I'm completely new to this and don't know how to go to this script and to edit it. Do I have to use the Essentials Editor? And how exactly? Also how can I add the effect, that a Pokémon with a specific nature gets 5 instead of 1 or 2 points? And how can I give a Berry the type and damage for the attack "natural gift"? Hope you can help me with this too... ^^
     
    Last edited:
  • 1,682
    Posts
    8
    Years
    • Seen Jun 13, 2024
    Thank you sooo much! But I have to say that I'm completely new to this and don't know how to go to this script and to edit it. Do I have to use the Essentials Editor? And how exactly? Also how can I add the effect, that a Pokémon with a specific nature gets 5 instead of 1 or 2 points? And how can I give a Berry the type and damage for the attack "natural gift"? Hope you can help me with this too... ^^

    Whoa, slow down there. Let's get you on the script editor first. This is sort of RMXP 101 here.
    Manipulating an Item

    This is the script editor button.

    Spoiler: Big Image warning
    Manipulating an Item

    On the left are all the script sections, and on the right is the code in the section you have selected. RMXP uses the language Ruby, with some added functionality for games specifically. So, when I said go to script section PItem_ItemEffects, I wanted you to click on that section on the left so it opens on the right.
    A few short-cuts to know are "CTRL + G", which lets you jump to a specific line number, "CTRL + F" which lets you search for a phrase in the opened script section, and "CTRL + SHIFT + F", which lets you search every script section at the same time.

    Okay, back to the code. We want to check for a certain nature and give it more happiness. Fortunately, We have functions that check for us.
    Code:
    ItemHandlers::UseOnPokemon.add(:HAPPYBERRY,proc{|item,pokemon,scene|
       Kernel.pbMessage(_INTL("{1} liked the berry!.",pokemon.name))
       (pokemon.hasNature?(PBNatures::JOLLY)) ? pokemon.happiness+=5 : pokemon.happiness+=1
       pokemon.happiness=[[255,pokemon.happiness].min,0].max
       next true
    })
    hasNature? is a function in PokeBattle_Pokemon which checks if the nature we gave it as an argument is the same as the one the pokemon has. PBNatures::JOLLY is a constant. It will always have the same value, and this is useful because it means we don't have to remember the number the nature has (You can give it a string too, but ehh). You can see what number all the natures have by going to script section PBNatures.
    Code:
    (pokemon.hasNature?(PBNatures::JOLLY)) [COLOR="Red"]?[/COLOR] pokemon.happiness+=5 [COLOR="red"]:[/COLOR] pokemon.happiness+=1
    Finally, do you see the red ? and :? That is called a ternary operator. What it does is check if the code before the ? is true or false and then do one of the arguments depending on the result.
    Code:
    (boolean) ? (true result) : (false result)
    Don't forget that we made the other berries copy this one, so they will all check for a Jolly nature. You may not want this.

    That last one, making a berry do damage... I don't know how to do... sorry.
     
  • 6
    Posts
    7
    Years
    • Seen Mar 5, 2017
    Thanks again, when I can get to my PC, I will try all those things! I think that I can find how to edit the damage and type for the new berries, I just try to check the script with the attacks. You're awesome, thank you for all your help! I hope that I don't need more help, but when, I let this discussion open for the moment. :)
     
  • 6
    Posts
    7
    Years
    • Seen Mar 5, 2017
    So, I added 11 of the 12 Berries. I added the Eggant Berry (curring from Attraction) to the red flute (just like the Persim Berrywith the yellow flute) and tried to make the script for the 10 friendship+ Berries (in the moment without the controler for the nature...). To those 10 Berries, I added the other Poffin ingredient Berries (like Razz Berry and so on), but when I try to use them from the bag, I can only use those 10 Berries, it doesn't work with the other Berries... But I have to look at the .txt file with the Items and look if I made them usable from the bag... While it did work with those 11 E-Card-Reader Berries, it didn't work with the 12th Berry, the Ginema Berry (rises a lowered state when carried in battle), could you help me with this too? :)
     
  • 1,682
    Posts
    8
    Years
    • Seen Jun 13, 2024
    While it did work with those 11 E-Card-Reader Berries, it didn't work with the 12th Berry, the Ginema Berry (rises a lowered state when carried in battle), could you help me with this too? :)

    So, If I understand this correctly, you aren't able to use the Ginema Berry on your pokemon from the bag?
    That's supposed to happen. I only defined it to have an effect if held in battle, though admittedly, I realize i never explained that code
    Code:
            if hasWorkingItem(:STATBERRY)
              berryname=PBItems.getName(self.item)
              pbConsumeItem
              @battle.pbDisplay(_INTL("{1} ate the {2} to avoid the stat loss!",pbThis,berryname)) if showMessages
              return false
            end
    This is the code I gave last time. hasWorkingItem checks if the pokemon is able to use the item it is carrying, so say if Embargo was in effect, it would return false.
    pbConsumeItem makes the pokemon automatically eat what it's holding.
    The return false is there to prevent the stat from decreasing at all, since this is inside the check to see if the stat should decrease.
     
  • 6
    Posts
    7
    Years
    • Seen Mar 5, 2017
    So, If I understand this correctly, you aren't able to use the Ginema Berry on your pokemon from the bag?
    That's supposed to happen. I only defined it to have an effect if held in battle, though admittedly, I realize i never explained that code
    Code:
            if hasWorkingItem(:STATBERRY)
              berryname=PBItems.getName(self.item)
              pbConsumeItem
              @battle.pbDisplay(_INTL("{1} ate the {2} to avoid the stat loss!",pbThis,berryname)) if showMessages
              return false
            end
    This is the code I gave last time. hasWorkingItem checks if the pokemon is able to use the item it is carrying, so say if Embargo was in effect, it would return false.
    pbConsumeItem makes the pokemon automatically eat what it's holding.
    The return false is there to prevent the stat from decreasing at all, since this is inside the check to see if the stat should decrease.

    No, I ment holding in battle. ^^' But thanks, I hope this will work! And when I did everything, I can post any files for the berries so that everyone can finally add the long lost E-Card-Reader-Berries from Pokémon Ruby, Sapphire, Emerald, Firered and Leafgreen into there own game! Now I only have to find a way, how to let an Item from the menu open a new screen, so that I can make an portable Item for Berry powder and Berry juice! But that could be hard and eventually I am not able to finish this, but I will try! ^^
     
    Back
    Top