The PokéCommunity Forums Fan Games Game Development Pokémon Essentials
Custom Feature Question Held Item that increases HP Stat

Pokémon Essentials All questions and discussion about Pokémon Essentials, the Pokémon game kit for RPG Maker XP, go in here. Also contains links to the latest downloads and the Essentials Wiki.

Reply
 
Thread Tools
  #1    
Old 2 Days Ago (1:16 PM).
Tommaniacal Tommaniacal is offline
     
    Join Date: Apr 2016
    Posts: 29
    For example, if I wanted the Reaper Cloth to increase Dusknoir's HP stat by 33% while holding it, how would I code that? It would be different than just having the damage multiplier be 66%, since moves like Seismic Toss, Nightshade, Dragon Rage, and Sonic Boom deal direct damage. It would affect moves like Wish and Leech seed as well, where a simple defense change wouldn't.

    I can't find anything like 'hpmult' (as opposed to speedmult and defmult), and I'd like to avoid making it a form change if possible.

    Thanks
    Reply With Quote
      #2    
    Old 2 Days Ago (1:36 PM).
    mgriffin's Avatar
    mgriffin mgriffin is offline
       
      Join Date: Apr 2014
      Posts: 137
      So I suppose the value you want to be modifying is "totalhp" (probably in PokeBattle_Pokemon). I'm not sure the best place to make the change, but calcStats seems like a reasonable candidate. You might need to make it so that equipping/unequipping an item calls calcStats if it doesn't already.
      Reply With Quote
        #3    
      Old 2 Days Ago (9:17 PM).
      Tommaniacal Tommaniacal is offline
         
        Join Date: Apr 2016
        Posts: 29
        Quote:
        Originally Posted by mgriffin View Post
        You might need to make it so that equipping/unequipping an item calls calcStats if it doesn't already.
        How would I go about doing this? I think I found the right place to change HP; the code is ugly but it doesn't return any errors lol
        Reply With Quote
          #4    
        Old 1 Day Ago (12:43 AM).
        mgriffin's Avatar
        mgriffin mgriffin is offline
           
          Join Date: Apr 2014
          Posts: 137
          Quote:
          Originally Posted by Tommaniacal View Post
          How would I go about doing this? I think I found the right place to change HP; the code is ugly but it doesn't return any errors lol
          What did you write?

          Does it cause the HP to increase?
          Reply With Quote
            #5    
          Old 1 Day Ago (8:06 AM).
          NewAgeSteel NewAgeSteel is offline
             
            Join Date: Jan 2017
            Gender: Male
            Posts: 93
            Quote:
            Originally Posted by Tommaniacal View Post
            For example, if I wanted the Reaper Cloth to increase Dusknoir's HP stat by 33% while holding it, how would I code that? It would be different than just having the damage multiplier be 66%, since moves like Seismic Toss, Nightshade, Dragon Rage, and Sonic Boom deal direct damage. It would affect moves like Wish and Leech seed as well, where a simple defense change wouldn't.

            I can't find anything like 'hpmult' (as opposed to speedmult and defmult), and I'd like to avoid making it a form change if possible.

            Thanks
            Just giving you a heads up, changing up can get a little weird. I did this with some mega Pokémon, not realizing that they never actual increase hp in the normal megas and it’s because of how it changes back and forth. So with your item for example, if it gets knocked off or taken during battle your dusknoir could just faint right when it loses the item if it’s hp is low enough. Or even outside of battle, for example if dusknoir is your only alive Pokémon but is low on hp and you remove the item for some reason causing it to faint then your whole party is knocked out. Just make sure you cover all your bases when you do this so it doesn’t lead to any weird glitches or errors
            Reply With Quote
              #6    
            Old 1 Day Ago (12:29 PM). Edited 1 Day Ago by Tommaniacal.
            Tommaniacal Tommaniacal is offline
               
              Join Date: Apr 2016
              Posts: 29
              Quote:
              Originally Posted by mgriffin View Post
              What did you write?

              Does it cause the HP to increase?
              in Pokebattle_Pokemon:

              Code:
              # Returns the maximum HP of this Pokémon.
                def calcHP(base,level,iv,ev)
                  return 1 if base==1
                  return ((base*2+iv+(ev>>2))*level/100).floor+level+10
                  if isConst?(self.species,PBSpecies,:DUSKNOIR) && 
                    self.hasWorkingItem(:REAPERCLOTH)
                    return ((((base*2+iv+(ev>>2))*level/100)+level+10)*1.3).floor
                  end
                end
              edit: I tried rearranging the script so that dusknoir's code happens before the normal calculation:

              Code:
              # Returns the maximum HP of this Pokémon.
                def calcHP(base,level,iv,ev)
                  return 1 if base==1
                  return ((((base*2+iv+(ev>>2))*level/100)+level+10)*1.3).floor if isConst?(self.species,PBSpecies,:DUSKNOIR) && 
                    self.hasWorkingItem(:REAPERCLOTH)   
                  return ((base*2+iv+(ev>>2))*level/100).floor+level+10
                end
              but it still doesn't change.
              It so far is not changing HP at all, I'm assuming it's because equipping items isn't calling calcStats. Maybe I messed up somewhere else, idk
              Reply With Quote
                #7    
              Old 1 Day Ago (1:28 PM).
              mgriffin's Avatar
              mgriffin mgriffin is offline
                 
                Join Date: Apr 2014
                Posts: 137
                Quote:
                Originally Posted by Tommaniacal View Post
                in Pokebattle_Pokemon:

                Code:
                # Returns the maximum HP of this Pokémon.
                  def calcHP(base,level,iv,ev)
                    return 1 if base==1
                    return ((base*2+iv+(ev>>2))*level/100).floor+level+10
                    if isConst?(self.species,PBSpecies,:DUSKNOIR) && 
                      self.hasWorkingItem(:REAPERCLOTH)
                      return ((((base*2+iv+(ev>>2))*level/100)+level+10)*1.3).floor
                    end
                  end
                edit: I tried rearranging the script so that dusknoir's code happens before the normal calculation:

                Code:
                # Returns the maximum HP of this Pokémon.
                  def calcHP(base,level,iv,ev)
                    return 1 if base==1
                    return ((((base*2+iv+(ev>>2))*level/100)+level+10)*1.3).floor if isConst?(self.species,PBSpecies,:DUSKNOIR) && 
                      self.hasWorkingItem(:REAPERCLOTH)   
                    return ((base*2+iv+(ev>>2))*level/100).floor+level+10
                  end
                but it still doesn't change.
                It so far is not changing HP at all, I'm assuming it's because equipping items isn't calling calcStats. Maybe I messed up somewhere else, idk
                Your second code looks reasonable—you're right that if you don't put the Dusknoir case above the normal case that it will never apply.

                And I think you're also right that equipping items doesn't call calcStats—if I remove the item check the HP *is* modified; and if I leave the item check in (actually I used hasItem instead of hasWorkingItem) then my HP is modified if I faint/gain a level.

                So add a call to calcStats in setItem and then have a think about what NewAgeSteel said about Pokémon getting KOed by the sudden change in max HP.
                Reply With Quote
                  #8    
                Old 1 Day Ago (4:43 PM).
                Tommaniacal Tommaniacal is offline
                   
                  Join Date: Apr 2016
                  Posts: 29
                  Quote:
                  Originally Posted by mgriffin View Post
                  And I think you're also right that equipping items doesn't call calcStats—if I remove the item check the HP *is* modified; and if I leave the item check in (actually I used hasItem instead of hasWorkingItem) then my HP is modified if I faint/gain a level.
                  Yeah I tested this and it returned an undefined method error. changing 'self.hasWorkingItem(:REAPERCLOTHER)' to 'isConst?(self.item,PBItems,:REAPERCLOTH)' fixed this.

                  Quote:
                  So add a call to calcStats in setItem
                  this is a dumb question but how do I add a call to something? I tried adding 'def calcStats above setItem's script in Pokebattle_Pokemon, but this returned an error:

                  Code:
                  # Sets this Pokémon's item. Accepts symbols.
                     def calcStats
                       def setItem(value)
                         if value.is_a?(String) || value.is_a?(Symbol)
                              value=getID(PBItems,value)
                         end
                         self.item=value
                       end
                     end
                  This was basically me just guessing so I kinda expected it not to work lol
                  Reply With Quote
                    #9    
                  Old 1 Day Ago (11:40 PM).
                  mgriffin's Avatar
                  mgriffin mgriffin is offline
                     
                    Join Date: Apr 2014
                    Posts: 137
                    Quote:
                    Originally Posted by Tommaniacal View Post
                    this is a dumb question but how do I add a call to something? I tried adding 'def calcStats above setItem's script in Pokebattle_Pokemon, but this returned an error:

                    Code:
                    # Sets this Pokémon's item. Accepts symbols.
                       def calcStats
                         def setItem(value)
                           if value.is_a?(String) || value.is_a?(Symbol)
                                value=getID(PBItems,value)
                           end
                           self.item=value
                         end
                       end
                    What you did there is essentially redefine calcStats and remove the definition of setItem, so yeah, I wouldn't expect that to work.

                    You want to write something more like this:

                    Code:
                         # Sets this Pokémon's item. Accepts symbols.
                         def setItem(value)
                           if value.is_a?(String) || value.is_a?(Symbol)
                                value=getID(PBItems,value)
                           end
                           self.item=value
                           self.calcStats
                         end
                    The intent here is that the last thing we do after setting the item is recalculate the stats.
                    Reply With Quote
                      #10    
                    Old 12 Hours Ago (11:15 AM).
                    Tommaniacal Tommaniacal is offline
                       
                      Join Date: Apr 2016
                      Posts: 29
                      Quote:
                      Originally Posted by mgriffin View Post
                      You want to write something more like this:

                      Code:
                           # Sets this Pokémon's item. Accepts symbols.
                           def setItem(value)
                             if value.is_a?(String) || value.is_a?(Symbol)
                                  value=getID(PBItems,value)
                             end
                             self.item=value
                             self.calcStats
                           end
                      The intent here is that the last thing we do after setting the item is recalculate the stats.
                      This worked! Thank you!

                      Quote:
                      Originally Posted by NewAgeSteel View Post
                      Just giving you a heads up, changing up can get a little weird. I did this with some mega Pokémon, not realizing that they never actual increase hp in the normal megas and it’s because of how it changes back and forth. So with your item for example, if it gets knocked off or taken during battle your dusknoir could just faint right when it loses the item if it’s hp is low enough. Or even outside of battle, for example if dusknoir is your only alive Pokémon but is low on hp and you remove the item for some reason causing it to faint then your whole party is knocked out. Just make sure you cover all your bases when you do this so it doesn’t lead to any weird glitches or errors
                      Would there be a way to have it so if its HP hit zero upon the item's removal, it would go to 1 HP instead? This would fix most of the problems, I think.
                      Reply With Quote
                        #11    
                      Old 10 Hours Ago (1:07 PM).
                      mgriffin's Avatar
                      mgriffin mgriffin is offline
                         
                        Join Date: Apr 2014
                        Posts: 137
                        Quote:
                        Originally Posted by Tommaniacal View Post
                        Would there be a way to have it so if its HP hit zero upon the item's removal, it would go to 1 HP instead? This would fix most of the problems, I think.
                        I am confident that if you have a look at the nearby code you can work out how to do that yourself. (Or something very similar)
                        Reply With Quote
                          #12    
                        Old 8 Hours Ago (3:18 PM).
                        Tommaniacal Tommaniacal is offline
                           
                          Join Date: Apr 2016
                          Posts: 29
                          Quote:
                          Originally Posted by mgriffin View Post
                          I am confident that if you have a look at the nearby code you can work out how to do that yourself. (Or something very similar)
                          I'm sure it would be 'return 1 if...' but I don't know where to go from there, or where to put it. I don't know how to code "if item is removed and hp drops to zero or below" lol

                          Also, if the item is lost during battle, it won't recalculate its hp. I tried adding 'opponent.calcStats' to Knock Off's script, but I got an undefined method error:

                          Code:
                          class PokeBattle_Move_0F0 < PokeBattle_Move
                            def pbEffectAfterHit(attacker,opponent,turneffects)
                              if !attacker.fainted? && !opponent.fainted? && opponent.item!=0 &&
                                 opponent.damagestate.calcdamage>0 && !opponent.damagestate.substitute
                                if !attacker.hasMoldBreaker && opponent.hasWorkingAbility(:STICKYHOLD)
                                  abilityname=PBAbilities.getName(opponent.ability)
                                  @battle.pbDisplay(_INTL("{1}'s {2} made {3} ineffective!",opponent.pbThis,abilityname,@name))
                                elsif [email protected](opponent,opponent.item)
                                  itemname=PBItems.getName(opponent.item)
                                  opponent.item=0
                                  opponent.calcStats
                                  opponent.effects[PBEffects::ChoiceBand]=-1
                                  opponent.effects[PBEffects::Unburden]=true
                                  @battle.pbDisplay(_INTL("{1} dropped its {2}!",opponent.pbThis,itemname))
                                end
                              end
                            end
                          Reply With Quote
                            #13    
                          Old 20 Minutes Ago (11:29 PM). Edited 18 Minutes Ago by mgriffin.
                          mgriffin's Avatar
                          mgriffin mgriffin is offline
                             
                            Join Date: Apr 2014
                            Posts: 137
                            Quote:
                            Originally Posted by Tommaniacal View Post
                            I'm sure it would be 'return 1 if...' but I don't know where to go from there, or where to put it. I don't know how to code "if item is removed and hp drops to zero or below" lol
                            Like I said, look at nearby code. You should be able to prevent a Pokémon from fainting because of a change in their HP base stat (which is not quite the same thing, but I don't think the difference is all that relevant).

                            Quote:
                            Originally Posted by Tommaniacal View Post
                            Also, if the item is lost during battle, it won't recalculate its hp. I tried adding 'opponent.calcStats' to Knock Off's script, but I got an undefined method error:
                            Yeah, I think that Pokémon in battle are a different type (PokeBattle_Battler) to Pokémon out of battle (PokeBattle_Pokemon). This is why I used hasItem? instead of hasWorkingItem?. You could try opponent.pokemon.calcStats, but it makes more sense to try and find what the equivalent function is. Search for calcStats in PokeBattle_Battler and make a judgement call about which function that calls calcStats is most likely to be what you want.
                            Reply With Quote
                            Reply

                            Quick Reply

                            Join the conversation!

                            Create an account to post a reply in this thread, participate in other discussions, and more!

                            Create a PokéCommunity Account
                            Thread Tools

                            Posting Rules
                            You may not post new threads
                            You may not post replies
                            You may not post attachments
                            You may not edit your posts

                            BB code is On
                            Smilies are On
                            [IMG] code is On
                            HTML code is Off

                            Forum Jump


                            All times are GMT -8. The time now is 11:50 PM.