Thread: [Essentials script] Apricorn System for Essentials
View Single Post
  #6    
Old August 19th, 2012 (05:21 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,409
Interesting, but you can put all in one code, it is easier for people install, Quick example:

Code:
# Apricorn system by zingzags
# credits will be nice!

# Okay, so here is how you use it.
# pbPokeballTime
# must be used with a time sensitive event, because it is not like he can craft a pokeball in a blink of an eye like magic.

# To call upon the screen you must use
# pbApricorn
# Also you must set what ever switch you defined "Choose" to "ON" so that you can craft a pokeball in the same event.

#===============================================================================
# * These are custom settings for the Apricorn Box.
# * "ApricornColorNumber" defines which Apricorn color represents which number
#      set it to what ever variable you want.
# * "Apricornqty" defines the quantity of the Apricorn which you want to make
#      again set it to what ever variable you want.
# * The "Choose" switch is to define if the player can only view what is inside
#      the Apricorn box, or choose an item inside. 
#===============================================================================
ApricornColorNumber=50
Apricornqty=51
Choose=50

class Apricorn
  
  def pbUpdate
   pbUpdateSpriteHash(@sprites)
  end
 
  def pbEndScene
   pbDisposeSpriteHash(@sprites)
   @viewport.dispose
  end

class TrainerBgPlane < AnimatedPlane
 
end
  def pbStartScene
    @sprites={}
    @posx={}
    @posy={}
    @choose=1
    @posx[1],@posy[1]=30,0
    @posx[2],@posy[2]=120,30
    @posx[3],@posy[3]=30,65
    @posx[4],@posy[4]=120,90
    @posx[5],@posy[5]=30,130
    @posx[6],@posy[6]=120,155
    @posx[7],@posy[7]=30,190
    
    @viewport=Viewport.new(0,0,Graphics.width, Graphics.height)
    @viewport.z=99999
    
    @sprites["bg"]=IconSprite.new(0,0,@viewport)
    @sprites["bg"].setBitmap("Graphics/Pictures/Apricorn/Apricorn_menu")
    @sprites["bg"].z=1
    @sprites["up"]=AnimatedSprite.create("Graphics/Pictures/Apricorn/uparrow1",10,3,@viewport)
    @sprites["up"].x=30
    @sprites["up"].y=0
    @sprites["up"].z=3
    @sprites["up"].play
    @sprites["abg"]=TrainerBgPlane.new(@viewport)
    @sprites["abg"].setBitmap("Graphics/Pictures/Apricorn/ApricornBG")
    @sprites["abg"].z=0
    
    @sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
    @sprites["overlay"].z=2
    overlay=@sprites["overlay"].bitmap
    overlay.clear
    base=Color.new(12*8,12*8,12*8)
    base1=Color.new(255,255,240)
    shadow=Color.new(12*8,12*8,12*8)
    pbSetSystemFont(overlay)
    textpos=[
  [_ISPRINTF("{1:3d}",$PokemonBag.pbQuantity(PBItems::REDAPRICORN)),102,94,1,base,shadow],
  [_ISPRINTF("{1:3d}",$PokemonBag.pbQuantity(PBItems::YLWAPRICORN)),198,127,1,base,shadow],
  [_ISPRINTF("{1:3d}",$PokemonBag.pbQuantity(PBItems::BLUAPRICORN)),102,160,1,base,shadow],
  [_ISPRINTF("{1:3d}",$PokemonBag.pbQuantity(PBItems::GRNAPRICORN)),198,190,1,base,shadow],
  [_ISPRINTF("{1:3d}",$PokemonBag.pbQuantity(PBItems::PNKAPRICORN)),102,223,1,base,shadow],
  [_ISPRINTF("{1:3d}",$PokemonBag.pbQuantity(PBItems::WHTAPRICORN)),198,253,1,base,shadow],
  [_ISPRINTF("{1:3d}",$PokemonBag.pbQuantity(PBItems::BLKAPRICORN)),102,287,1,base,shadow],
  [_ISPRINTF("Apricorn Box"),180,333,1,base1,shadow],
  ]
 pbDrawTextPositions(overlay,textpos)
 end 
  
  def pbScene
  loop do
    Graphics.update
    Input.update
    pbUpdate
    @sprites["abg"].update
    
    if Input.trigger?(Input::LEFT)
            @choose-=1
            @choose=7 if @choose<=0
            @sprites["up"].x=@posx[@choose]
            @sprites["up"].y=@posy[@choose]
    end


    if Input.trigger?(Input::RIGHT)
        @choose+=1
        @choose=1 if @choose>=8
        @sprites["up"].x=@posx[@choose]
        @sprites["up"].y=@posy[@choose]
    end

    if Input.trigger?(Input::B)
        break
    end


if $game_switches[Choose]==true  
    if @sprites["up"].x==@posx[1] && @sprites["up"].y==@posy[1] && $PokemonBag.pbQuantity(PBItems::REDAPRICORN)>=1
      if Input.trigger?(Input::C)
       if Kernel.pbConfirmMessage(_INTL("Are you sure you want me to use a Red Apricorn?"))
     itemqty=$PokemonBag.pbQuantity(PBItems::REDAPRICORN)
      params=ChooseNumberParams.new
      params.setRange(1,itemqty)
      params.setInitialValue(itemqty)
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(
         _INTL("How much do you want to give?"),params
      )
        $PokemonBag.pbDeleteItem(PBItems::REDAPRICORN,qty)
        $game_variables[ApricornColorNumber]=1
        $game_variables[Apricornqty]=qty
        $game_switches[Choose]=false
        pbWait(30)
        break
      else
         Kernel.pbMessage(_INTL("Please choose an Apricorn."))
      end
    end
  end
  
    
    if @sprites["up"].x==@posx[2] && @sprites["up"].y==@posy[2] && $PokemonBag.pbQuantity(PBItems::YLWAPRICORN)>=1
      if Input.trigger?(Input::C)
         if Kernel.pbConfirmMessage(_INTL("Are you sure you want me to use a Yellow Apricorn?"))
      itemqty=$PokemonBag.pbQuantity(PBItems::YLWAPRICORN)
      params=ChooseNumberParams.new
      params.setRange(1,itemqty)
      params.setInitialValue(itemqty)
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(
         _INTL("How much do you want to give?"),params
      )
        $PokemonBag.pbDeleteItem(PBItems::YLWAPRICORN,qty)
        $game_variables[ApricornColorNumber]=2
        $game_variables[Apricornqty]=qty
        $game_switches[Choose]=false
        pbWait(30)
        break
      else
        Kernel.pbMessage(_INTL("Please choose an Apricorn."))
       end
      end
     end
    
    if @sprites["up"].x==@posx[3] && @sprites["up"].y==@posy[3] && $PokemonBag.pbQuantity(PBItems::BLUAPRICORN)>=1
      if Input.trigger?(Input::C)
        if Kernel.pbConfirmMessage(_INTL("Are you sure you want me to use a Blue Apricorn?"))
      itemqty=$PokemonBag.pbQuantity(PBItems::BLUAPRICORN)
      params=ChooseNumberParams.new
      params.setRange(1,itemqty)
      params.setInitialValue(itemqty)
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(
         _INTL("How much do you want to give?"),params
      )
        $PokemonBag.pbDeleteItem(PBItems::BLUAPRICORN,qty)
        $game_variables[ApricornColorNumber]=3
        $game_variables[Apricornqty]=qty  
        $game_switches[Choose]=false
         pbWait(30)
        break
      else
        Kernel.pbMessage(_INTL("Please choose an Apricorn."))
      end
      
      end
    end

    if @sprites["up"].x==@posx[4] && @sprites["up"].y==@posy[4] && $PokemonBag.pbQuantity(PBItems::GRNAPRICORN)>=1
      if Input.trigger?(Input::C)
        if Kernel.pbConfirmMessage(_INTL("Are you sure you want me to use a Green Apricorn?"))
      itemqty=$PokemonBag.pbQuantity(PBItems::GRNAPRICORN)
      params=ChooseNumberParams.new
      params.setRange(1,itemqty)
      params.setInitialValue(itemqty)
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(
         _INTL("How much do you want to give?"),params
      )
        $PokemonBag.pbDeleteItem(PBItems::GRNAPRICORN,qty)
        $game_variables[ApricornColorNumber]=4
        $game_variables[Apricornqty]=qty
        $game_switches[Choose]=false
        pbWait(30)
        break
      else
        Kernel.pbMessage(_INTL("Please choose an Apricorn."))
      end
      
      end
    end

    if @sprites["up"].x==@posx[5] && @sprites["up"].y==@posy[5] && $PokemonBag.pbQuantity(PBItems::PNKAPRICORN)>=1
      if Input.trigger?(Input::C)
        if Kernel.pbConfirmMessage(_INTL("Are you sure you want me to use a Pink Apricorn?"))
      itemqty=$PokemonBag.pbQuantity(PBItems::PNKAPRICORN)
      params=ChooseNumberParams.new
      params.setRange(1,itemqty)
      params.setInitialValue(itemqty)
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(
         _INTL("How much do you want to give?"),params
      )
        $PokemonBag.pbDeleteItem(PBItems::PNKAPRICORN,qty)
        $game_variables[ApricornColorNumber]=5
        $game_variables[Apricornqty]=qty
        $game_switches[Choose]=false
        pbWait(30)
        break
      else
        Kernel.pbMessage(_INTL("Please choose an Apricorn."))
      end
      
      end
    end

    if @sprites["up"].x==@posx[6] && @sprites["up"].y==@posy[6] && $PokemonBag.pbQuantity(PBItems::WHTAPRICORN)>=1
      if Input.trigger?(Input::C)
        if Kernel.pbConfirmMessage(_INTL("Are you sure you want me to use a White Apricorn?"))
      itemqty=$PokemonBag.pbQuantity(PBItems::WHTAPRICORN)
      params=ChooseNumberParams.new
      params.setRange(1,itemqty)
      params.setInitialValue(itemqty)
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(
         _INTL("How much do you want to give?"),params
      )
        $PokemonBag.pbDeleteItem(PBItems::WHTAPRICORN,qty)
        $game_variables[ApricornColorNumber]=6
        $game_variables[Apricornqty]=qty
        $game_switches[Choose]=false
        pbWait(30)
        break
      else
        Kernel.pbMessage(_INTL("Please choose an Apricorn."))
      end
      
      end
    end

    if @sprites["up"].x==@posx[7] && @sprites["up"].y==@posy[7] && $PokemonBag.pbQuantity(PBItems::BLKAPRICORN)>=1
      if Input.trigger?(Input::C)
        if Kernel.pbConfirmMessage(_INTL("Are you sure you want me to use a Black Apricorn?"))
      itemqty=$PokemonBag.pbQuantity(PBItems::BLKAPRICORN)
      params=ChooseNumberParams.new
      params.setRange(1,itemqty)
      params.setInitialValue(itemqty)
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(
         _INTL("How much do you want to give?"),params
      )
        $PokemonBag.pbDeleteItem(PBItems::BLKAPRICORN,qty)
        $game_variables[ApricornColorNumber]=7
        $game_variables[Apricornqty]=qty
        $game_switches[Choose]=false
        pbWait(30)
        break
      else
        Kernel.pbMessage(_INTL("Please choose an Apricorn."))
        end
      end
     end
    end
      
     
    end
  end
  
end

    class ApricornScreen
         def initialize(scene)
                @scene = scene
         end
              
         def pbStartScreen
                @scene.pbStartScene
                @scene.pbScene
                @scene.pbEndScene
         end

    end

  def pbPokeballTime
     if $game_variables[ApricornColorNumber]==1
         Kernel.pbReceiveItem(PBItems::LEVELBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==2    
         Kernel.pbReceiveItem(PBItems::MOONBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==3    
         Kernel.pbReceiveItem(PBItems::LUREBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==4    
         Kernel.pbReceiveItem(PBItems::FRIENDBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==5    
         Kernel.pbReceiveItem(PBItems::LOVEBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==6    
         Kernel.pbReceiveItem(PBItems::FASTBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==7    
         Kernel.pbReceiveItem(PBItems::HEAVYBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
       end
       $game_variables[ApricornColorNumber]=0
       $game_variables[Apricornqty]=0
  end

    def pbApricorn
          scene=Apricorn.new
          screen=ApricornScreen.new(scene)
          pbFadeOutIn(99999) { 
          screen.pbStartScreen
          }
    end

ItemHandlers::UseFromBag.add(:APRICORNBOX,proc{|item|
   pbApricorn
   next 1 # Continue
})


ItemHandlers::UseInField.add(:APRICORNBOX,proc{|item|
   pbApricorn
})
And, besides this, the code can be improved, like changing

Code:
def pbPokeballTime
     if $game_variables[ApricornColorNumber]==1
         Kernel.pbReceiveItem(PBItems::LEVELBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==2    
         Kernel.pbReceiveItem(PBItems::MOONBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==3    
         Kernel.pbReceiveItem(PBItems::LUREBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==4    
         Kernel.pbReceiveItem(PBItems::FRIENDBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==5    
         Kernel.pbReceiveItem(PBItems::LOVEBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==6    
         Kernel.pbReceiveItem(PBItems::FASTBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
     elsif $game_variables[ApricornColorNumber]==7    
         Kernel.pbReceiveItem(PBItems::HEAVYBALL,$game_variables[Apricornqty])
         $game_variables[Apricornqty]=0
       end
       $game_variables[ApricornColorNumber]=0
       $game_variables[Apricornqty]=0
  end
to
Code:
def pbPokeballTime
  if(1<=$game_variables[ApricornColorNumber] && $game_variables[ApricornColorNumber]<=7)
    apricornBall=[PBItems::LEVELBALL,PBItems::MOONBALL,PBItems::LUREBALL,PBItems::FRIENDBALL,
        PBItems::LOVEBALL,PBItems::FASTBALL,PBItems::HEAVYBALL][$game_variables[ApricornColorNumber]-1]
    Kernel.pbReceiveItem(apricornBall,$game_variables[Apricornqty])
    $game_variables[Apricornqty]=0
  end
end
__________________
Reply With Quote