The PokéCommunity Forums Fan Games Game Development Scripts & Tutorials
Essentials Script Pokemon dropping items after battle

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.


Reply
 
Thread Tools
  #1    
Old August 4th, 2014 (11:14 AM).
aramant16 aramant16 is offline
     
    Join Date: Feb 2012
    Posts: 8
    I made this simple script to make wild pokemon drop the items they held.
    HankMan and Nickalooose first discussed this subject in an old topic (I still can't post the link to the topic, but if you search for "Pokemon essentials dropping items" on Google you will find it) .

    If a wild pokemon is holding an item when he is defeated, there is a 50% chance that he will drop it. The item is dropped right after the Exp Gain, as suggested by Nickalooose.
    It won't work against another trainer (if you want to do so, you have to delete "[email protected]" in the function definition).

    First, I added the highlited part at the end of PokeBattle_Battle:

    Code:
        @scene.pbEndBattle(@decision)
        for i in @battlers
          i.pbResetForm
        end
        for i in $Trainer.party
          i.item=i.itemInitial
          i.itemInitial=i.itemRecycle=0
        end
        return @decision
      end
      
    ### Wild pokemon drops item if defeated
      def pbDropItem (i)
        if rand(100)>50 && @battlers[i].item!=0 && [email protected]
          $PokemonBag.pbStoreItem(@battlers[i].item)
          pbDisplay(_INTL("{1} picked up {2} from the pokemon!", $Trainer.name, PBItems.getName(@battlers[i].item)))
          end
      end   
    end
    Then I put the function after the exp gain at the end of pbGainExp, but before the battler's data are deleted ("[I]@battlers.participants=[]"). It's in the PokeBattle_Battle section, around line 1799.

    Code:
                        # Finding all moves learned at this level
                        movelist=thispoke.getMoveList
                        for k in movelist
                          if k[0]==thispoke.level   # Learned a new move
                            pbLearnMove(j,k[1])
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
            pbDropItem (i)
            # Now clear the participants array
            @battlers[i].participants=[]
          end
        end
      end
    Reply With Quote

    Relevant Advertising!

      #2    
    Old August 4th, 2014 (11:43 AM).
    Lusus's Avatar
    Lusus Lusus is offline
       
      Join Date: Jan 2013
      Location: Ljubljana
      Age: 18
      Gender: Other
      Nature: Lonely
      Posts: 1,409
      This is actually one of the scripts i need for my game, awesome!
      Reply With Quote
        #3    
      Old August 16th, 2014 (8:09 AM).
      Gexeys's Avatar
      Gexeys Gexeys is offline
      Location: Ilex Forest shrine
         
        Join Date: Dec 2013
        Gender: Male
        Nature: Adamant
        Posts: 70
        Awesome script, such a neat idea!
        One question, rather than "Player picked up Item from the pokemon!" wouldn't it be better to say "Player picked up Item from the PokemonName"?
        I've tried doing this myself but pokemon.name doesn't seem to work because I assume the Pokemon no longer exists because it has fainted.
        __________________
        Reply With Quote
          #4    
        Old August 16th, 2014 (9:32 AM).
        mej71's Avatar
        mej71 mej71 is offline
           
          Join Date: Mar 2014
          Location: Omnipresence
          Gender: Male
          Posts: 1,226
          It doesn't work because pokemon is not defined here. Use @battlers[i].name instead
          Reply With Quote
            #5    
          Old August 17th, 2014 (2:40 AM).
          aramant16 aramant16 is offline
             
            Join Date: Feb 2012
            Posts: 8
            This way it should work:
            pbDisplayPaused(_INTL("{1} picked up {2} from {3}!",$Trainer.name,PBItems.getName(@battlers[i].item),@battlers[i].name))

            "@battlers[i].name" should get you the species of the pokemon.
            Reply With Quote
              #6    
            Old October 13th, 2016 (10:20 AM).
            rizakh rizakh is offline
               
              Join Date: Jul 2015
              Posts: 55
              how to use that in 16.2? i tried adapt but without success
              Reply With Quote
                #7    
              Old December 4th, 2016 (6:22 PM).
              dydd90's Avatar
              dydd90 dydd90 is offline
                 
                Join Date: Dec 2013
                Location: Italy
                Gender: Male
                Posts: 248
                Quote:
                Originally Posted by aramant16 View Post
                I made this simple script to make wild pokemon drop the items they held.
                HankMan and Nickalooose first discussed this subject in an old topic (I still can't post the link to the topic, but if you search for "Pokemon essentials dropping items" on Google you will find it) .

                If a wild pokemon is holding an item when he is defeated, there is a 50% chance that he will drop it. The item is dropped right after the Exp Gain, as suggested by Nickalooose.
                It won't work against another trainer (if you want to do so, you have to delete "[email protected]" in the function definition).

                First, I added the highlited part at the end of PokeBattle_Battle:

                Code:
                    @scene.pbEndBattle(@decision)
                    for i in @battlers
                      i.pbResetForm
                    end
                    for i in $Trainer.party
                      i.item=i.itemInitial
                      i.itemInitial=i.itemRecycle=0
                    end
                    return @decision
                  end
                  
                ### Wild pokemon drops item if defeated
                  def pbDropItem (i)
                    if rand(100)>50 && @battlers[i].item!=0 && [email protected]
                      $PokemonBag.pbStoreItem(@battlers[i].item)
                      pbDisplay(_INTL("{1} picked up {2} from the pokemon!", $Trainer.name, PBItems.getName(@battlers[i].item)))
                      end
                  end   
                end
                Then I put the function after the exp gain at the end of pbGainExp, but before the battler's data are deleted ("[I]@battlers.participants=[]"). It's in the PokeBattle_Battle section, around line 1799.

                Code:
                                    # Finding all moves learned at this level
                                    movelist=thispoke.getMoveList
                                    for k in movelist
                                      if k[0]==thispoke.level   # Learned a new move
                                        pbLearnMove(j,k[1])
                                      end
                                    end
                                  end
                                end
                              end
                            end
                          end
                        end
                        pbDropItem (i)
                        # Now clear the participants array
                        @battlers[i].participants=[]
                      end
                    end
                  end
                Hei Aramant i tried your script in v16 but i never got the items, do you have a solution?
                __________________


                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

                Sponsored Links
                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 8:07 AM.