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 January 27th, 2014 (3:45 PM).
p.claydon p.claydon is offline
     
    Join Date: Jan 2011
    Gender:
    Posts: 335
    ok well as some people may know i have been working on a way to improve on how we buy things with coins (such as the prizes in the Game Corner) so I came up with this modified version of the PokéMart script all you need to do is paste this script in essentials (I place it directly below the PokéMart script) and way you go

    Code:
    def pbcoinvalue
      $game_variables[32]=$PokemonGlobal.coins
      $game_variables[31]=$Trainer.money
      $Trainer.money=$game_variables[32]
    end
    
    def pbgoldvalue
      $game_variables[32]=$Trainer.money
      $Trainer.money=$game_variables[31]
      $PokemonGlobal.coins=$game_variables[32]
    end
    
    class PokemonMartCoinsAdapter
      def getMoney
        return $Trainer.money
      end
    
      def setMoney(value)
        $Trainer.money=value
      end
    
      def getInventory()
        return $PokemonBag
      end
    
      def getPrice(item)
        return $ItemData[item][ITEMPRICE]
      end
    
      def getItemIcon(item)
        return nil if !item
        return pbItemIconFile(item)
      end
    
      def getItemIconRect(item)
        return Rect.new(0,0,48,48)
      end
    
      def getDisplayName(item)
        itemname=PBItems.getName(item)
        if pbIsMachine?(item)
          machine=$ItemData[item][ITEMMACHINE]
          itemname=_INTL("{1} {2}",itemname,PBMoves.getName(machine))
        end
        return itemname
      end
    
      def getName(item)
        return PBItems.getName(item)
      end
    
      def getDisplayPrice(item)
        price=getPrice(item)
        return _ISPRINTF("{1:d} Coins",price)
      end
    
      def getDescription(item)
        return pbGetMessage(MessageTypes::ItemDescriptions,item)
      end
    
      def addItem(item)
        return $PokemonBag.pbStoreItem(item)
      end
    
      def getQuantity(item)
        return $PokemonBag.pbQuantity(item)
      end
    
      def canSell?(item)
        return getPrice(item)>0 && !pbIsImportantItem?(item)
      end
    
      def showQuantity?(item)
        return !pbIsImportantItem?(item)
      end
    
      def removeItem(item)
        return $PokemonBag.pbDeleteItem(item)
      end
    end
    
    class GameCornerScene
      def update
        pbUpdateSpriteHash(@sprites)
        @subscene.update if @subscene
      end
    
      def pbChooseNumber(helptext,item,maximum)
        curnumber=1
        ret=0
        [email protected]["helpwindow"]
        [email protected](item)
        itemprice/=2 if [email protected]
        pbDisplay(helptext,true)
        using(numwindow=Window_AdvancedTextPokemon.new("")){ # Showing number of items
           [email protected](item)
           using(inbagwindow=Window_AdvancedTextPokemon.new("")){ # Showing quantity in bag
              pbPrepareWindow(numwindow)
              pbPrepareWindow(inbagwindow)
              [email protected]
              numwindow.width=224
              numwindow.height=64
              numwindow.baseColor=Color.new(88,88,80)
              numwindow.shadowColor=Color.new(168,184,184)
              [email protected]
              [email protected]
              inbagwindow.width=190
              inbagwindow.height=64
              inbagwindow.baseColor=Color.new(88,88,80)
              inbagwindow.shadowColor=Color.new(168,184,184)
              inbagwindow.text=_ISPRINTF("In Bag:<r>{1:d}  ",qty)
              numwindow.text=_ISPRINTF("x{1:d} {2:d} Coins",curnumber,curnumber*itemprice)
              pbBottomRight(numwindow)
              numwindow.y-=helpwindow.height
              pbBottomLeft(inbagwindow)
              inbagwindow.y-=helpwindow.height
              loop do
                Graphics.update
                Input.update
                numwindow.update
                inbagwindow.update
                self.update
                if Input.repeat?(Input::LEFT)
                  pbPlayCursorSE()
                  curnumber-=10
                  curnumber=1 if curnumber<1
                  numwindow.text=_ISPRINTF("x{1:d} {2:d} Coins",curnumber,curnumber*itemprice)
                elsif Input.repeat?(Input::RIGHT)
                  pbPlayCursorSE()
                  curnumber+=10
                  curnumber=maximum if curnumber>maximum
                  numwindow.text=_ISPRINTF("x{1:d} {2:d} Coins",curnumber,curnumber*itemprice)
                elsif Input.repeat?(Input::UP)
                  pbPlayCursorSE()
                  curnumber+=1
                  curnumber=1 if curnumber>maximum
                  numwindow.text=_ISPRINTF("x{1:d} {2:d} Coins",curnumber,curnumber*itemprice)
                elsif Input.repeat?(Input::DOWN)
                  pbPlayCursorSE()
                  curnumber-=1
                  curnumber=maximum if curnumber<1
                  numwindow.text=_ISPRINTF("x{1:d} {2:d} Coins",curnumber,curnumber*itemprice)
                elsif Input.trigger?(Input::C)
                  pbPlayDecisionSE()
                  ret=curnumber
                  break
                elsif Input.trigger?(Input::B)
                  pbPlayCancelSE()
                  ret=0
                  break
                end     
              end
           }
        }
        helpwindow.visible=false
        return ret
      end
    
      def pbPrepareWindow(window)
        window.visible=true
        window.letterbyletter=false
      end
    
      def pbStartBuyOrSellScene(buying,stock,adapter)
        # Scroll right before showing screen
        pbScrollMap(6,5,5)
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        @stock=stock
        @adapter=adapter
        @sprites={}
        @sprites["background"]=IconSprite.new(0,0,@viewport)
        @sprites["background"].setBitmap("Graphics/Pictures/martScreen")
        @sprites["icon"]=IconSprite.new(12,Graphics.height-74,@viewport)
        winAdapter=buying ? BuyAdapter.new(adapter) : SellAdapter.new(adapter)
        @sprites["itemwindow"]=Window_PokemonMart.new(stock,winAdapter,
           Graphics.width-316-16,12,330+16,Graphics.height-126)
        @sprites["itemwindow"].[email protected]
        @sprites["itemwindow"].index=0
        @sprites["itemwindow"].refresh
        @sprites["itemtextwindow"]=Window_UnformattedTextPokemon.new("")
        pbPrepareWindow(@sprites["itemtextwindow"])
        @sprites["itemtextwindow"].x=64
        @sprites["itemtextwindow"].y=Graphics.height-96-16
        @sprites["itemtextwindow"].width=Graphics.width-64
        @sprites["itemtextwindow"].height=128
        @sprites["itemtextwindow"].baseColor=Color.new(248,248,248)
        @sprites["itemtextwindow"].shadowColor=Color.new(0,0,0)
        @sprites["itemtextwindow"].visible=true
        @sprites["itemtextwindow"].[email protected]
        @sprites["itemtextwindow"].windowskin=nil
        @sprites["helpwindow"]=Window_AdvancedTextPokemon.new("")
        pbPrepareWindow(@sprites["helpwindow"])
        @sprites["helpwindow"].visible=false
        @sprites["helpwindow"].[email protected]
        pbBottomLeftLines(@sprites["helpwindow"],1)
        @sprites["moneywindow"]=Window_AdvancedTextPokemon.new("")
        pbPrepareWindow(@sprites["moneywindow"])
        @sprites["moneywindow"].visible=true
        @sprites["moneywindow"].[email protected]
        @sprites["moneywindow"].x=0
        @sprites["moneywindow"].y=0
        @sprites["moneywindow"].width=190
        @sprites["moneywindow"].height=96
        @sprites["moneywindow"].baseColor=Color.new(88,88,80)
        @sprites["moneywindow"].shadowColor=Color.new(168,184,184)
        pbDeactivateWindows(@sprites)
        @buying=buying
        pbRefresh
        Graphics.frame_reset
      end
    
      def pbStartBuyScene(stock,adapter)
        pbStartBuyOrSellScene(true,stock,adapter)
      end
      
      def pbStartSellScene(bag,adapter)
        if $PokemonBag
          pbStartSellScene2(bag,adapter)
        else
          pbStartBuyOrSellScene(false,bag,adapter)
        end
      end
    
      def pbStartSellScene2(bag,adapter)
        @subscene=PokemonBag_Scene.new
        @adapter=adapter
        @viewport2=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport2.z=99999
        for j in 0..17
          col=Color.new(0,0,0,j*15)
          @viewport2.color=col
          Graphics.update
          Input.update
        end
        @subscene.pbStartScene(bag)
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        @sprites={}
        @sprites["helpwindow"]=Window_AdvancedTextPokemon.new("")
        pbPrepareWindow(@sprites["helpwindow"])
        @sprites["helpwindow"].visible=false
        @sprites["helpwindow"].[email protected]
        pbBottomLeftLines(@sprites["helpwindow"],1)
        @sprites["moneywindow"]=Window_AdvancedTextPokemon.new("")
        pbPrepareWindow(@sprites["moneywindow"])
        @sprites["moneywindow"].visible=false
        @sprites["moneywindow"].[email protected]
        @sprites["moneywindow"].x=0
        @sprites["moneywindow"].y=0
        @sprites["moneywindow"].width=186
        @sprites["moneywindow"].height=96
        @sprites["moneywindow"].baseColor=Color.new(88,88,80)
        @sprites["moneywindow"].shadowColor=Color.new(168,184,184)
        pbDeactivateWindows(@sprites)
        @buying=false
        pbRefresh
      end
    
      def pbShowMoney
        pbRefresh
        @sprites["moneywindow"].visible=true
      end
    
      def pbHideMoney
        pbRefresh
        @sprites["moneywindow"].visible=false
      end
    
      def pbEndBuyScene
        pbDisposeSpriteHash(@sprites)
        @viewport.dispose
        # Scroll left after showing screen
        pbScrollMap(4,5,5)
      end
    
      def pbEndSellScene
        if @subscene
          @subscene.pbEndScene
        end
        pbDisposeSpriteHash(@sprites)
        if @viewport2
          for j in 0..17
            col=Color.new(0,0,0,(17-j)*15)
            @viewport2.color=col
            Graphics.update
            Input.update
          end
          @viewport2.dispose
        end
        @viewport.dispose
        if [email protected]
          pbScrollMap(4,5,5)
        end
      end
    
      def pbDisplay(msg,brief=false)
        [email protected]["helpwindow"]
        cw.letterbyletter=true
        cw.text=msg
        pbBottomLeftLines(cw,2)
        cw.visible=true
        i=0
        pbPlayDecisionSE()
        loop do
          Graphics.update
          Input.update
          self.update
          if brief && !cw.busy?
            return
          end
          if i==0 && !cw.busy?
            pbRefresh
          end
          if Input.trigger?(Input::C) && cw.busy?
            cw.resume
          end
          if i==60
            return
          end
          i+=1 if !cw.busy?
        end
      end
    
      def pbDisplayPaused(msg)
        [email protected]["helpwindow"]
        cw.letterbyletter=true
        cw.text=msg
        pbBottomLeftLines(cw,2)
        cw.visible=true
        i=0
        pbPlayDecisionSE()
        loop do
          Graphics.update
          Input.update
          wasbusy=cw.busy?
          self.update
          if !cw.busy? && wasbusy
            pbRefresh
          end
          if Input.trigger?(Input::C) && cw.resume && !cw.busy?
            @sprites["helpwindow"].visible=false
            return
          end
        end
      end
    
      def pbConfirm(msg)
        [email protected]["helpwindow"]
        dw.letterbyletter=true
        dw.text=msg
        dw.visible=true
        pbBottomLeftLines(dw,2)
        commands=[_INTL("Yes"),_INTL("No")]
        cw = Window_CommandPokemon.new(commands)
        [email protected]
        pbBottomRight(cw)
        cw.y-=dw.height
        cw.index=0
        pbPlayDecisionSE()
        loop do
          cw.visible=!dw.busy?
          Graphics.update
          Input.update
          cw.update
          self.update
          if Input.trigger?(Input::B) && dw.resume && !dw.busy?
            cw.dispose
            @sprites["helpwindow"].visible=false
            return false
          end
          if Input.trigger?(Input::C) && dw.resume && !dw.busy?
            cw.dispose
            @sprites["helpwindow"].visible=false
            return (cw.index==0)?true:false
          end
        end
      end
    
      def pbRefresh
        if [email protected]
          [email protected]["itemwindow"]
          [email protected](itemwindow.item)
          @sprites["icon"].setBitmap(filename)
          @sprites["icon"].[email protected](itemwindow.item)   
          @sprites["itemtextwindow"].text=(itemwindow.item==0) ? _INTL("Quit shopping.") :
             @adapter.getDescription(itemwindow.item)
          itemwindow.refresh
        end
        @sprites["moneywindow"].text=_INTL("Coins\n<r> {1}",@adapter.getMoney())
      end
    
      def pbChooseBuyItem
        [email protected]["itemwindow"]
        @sprites["helpwindow"].visible=false
        pbActivateWindow(@sprites,"itemwindow"){
           pbRefresh
           loop do
             Graphics.update
             Input.update
             olditem=itemwindow.item
             self.update
             if itemwindow.item!=olditem
               [email protected](itemwindow.item)
               @sprites["icon"].setBitmap(filename)
               @sprites["icon"].[email protected](itemwindow.item)   
               @sprites["itemtextwindow"].text=(itemwindow.item==0) ? _INTL("Quit shopping.") :
                  @adapter.getDescription(itemwindow.item)
             end
             if Input.trigger?(Input::B)
               return 0
             end
             if Input.trigger?(Input::C)
               if itemwindow.index<@stock.length
                 pbRefresh
                 return @stock[itemwindow.index]
               else
                 return 0
               end
             end
           end
        }
      end
    =begin
      def pbChooseSellItem
        if @subscene
          return @subscene.pbChooseItem
        else
          return pbChooseBuyItem
        end
      end
    =end  
    end
    
    class PokemonMartCoinsScreen
      def initialize(scene,stock)
        @scene=scene
        @stock=stock
        @adapter=$PokemonBag ? PokemonMartCoinsAdapter.new : RpgxpMartAdapter.new
      end
    
      def pbConfirm(msg)
        return @scene.pbConfirm(msg)
      end
    
      def pbDisplay(msg)
        return @scene.pbDisplay(msg)
      end
    
      def pbDisplayPaused(msg)
        return @scene.pbDisplayPaused(msg)
      end
    
      def pbBuyScreen
        @scene.pbStartBuyScene(@stock,@adapter)
        item=0
        loop do
          [email protected]
          quantity=0
          break if item==0
          [email protected](item)
          [email protected](item)
          if @adapter.getMoney()<price
            pbDisplayPaused(_INTL("You don't have enough money."))
            next
          end
          if pbIsImportantItem?(item)
            if !pbConfirm(_INTL("Certainly.  You want {1}.\r\nThat will be {2} Coins.  OK?",itemname,price))
              next
            end
            quantity=1
          else
            maxafford=(price<=0) ? BAGMAXPERSLOT : @adapter.getMoney()/price
            maxafford=BAGMAXPERSLOT if maxafford>BAGMAXPERSLOT
            [email protected](
               _INTL("{1}?  Certainly.\r\nHow many would you like?",itemname),item,maxafford)
            if quantity==0
              next
            end
            price*=quantity
            if !pbConfirm(_INTL("{1}, and you want {2}.\r\nThat will be {3} Coins.  OK?",itemname,quantity,price))
              next
            end
          end
          if @adapter.getMoney()<price
            pbDisplayPaused(_INTL("You don't have enough money."))
            next
          end
          added=0
          quantity.times do
            if [email protected](item)
              break
            end
            added+=1
          end
          if added!=quantity
            added.times do
              if [email protected](item)
                raise _INTL("Failed to delete stored items")
              end
            end
            pbDisplayPaused(_INTL("You have no more room in the Bag."))  
          else
            @adapter.setMoney(@adapter.getMoney()-price)
            for i in 0...@stock.length
              if pbIsImportantItem?(@stock[i]) && $PokemonBag.pbQuantity(@stock[i])>0
                @stock[i]=nil
              end
            end
            @stock.compact!
            pbDisplayPaused(_INTL("Here you are!\r\nThank you!"))
            if $PokemonBag
              if quantity>=10 && isConst?(item,PBItems,:POKEBALL) && 
                 hasConst?(PBItems,:PREMIERBALL)
                if @adapter.addItem(getConst(PBItems,:PREMIERBALL))
                  pbDisplayPaused(_INTL("I'll throw in a Premier Ball, too.")) 
                end
              end
            end
          end
        end
        @scene.pbEndBuyScene
      end
    =begin  
      def pbSellScreen
        [email protected](@adapter.getInventory,@adapter)
        loop do
          [email protected]
          break if item==0
          [email protected](item)
          [email protected](item)
          if [email protected]?(item)
            pbDisplayPaused(_INTL("{1}?  Oh, no.\r\nI can't buy that.",itemname))
            next
          end
          [email protected](item)
          next if qty==0
          @scene.pbShowMoney
          if qty>1
            [email protected](
               _INTL("{1}?\r\nHow many would you like to sell?",itemname),item,qty)
          end
          if qty==0
            @scene.pbHideMoney
            next
          end
          price/=2
          price*=qty
          if pbConfirm(_INTL("I can pay ${1}.\r\nWould that be OK?",price))
            @adapter.setMoney(@adapter.getMoney()+price)
            for i in 0...qty
              @adapter.removeItem(item)
            end
            pbDisplayPaused(_INTL("Turned over the {1} and received {2} Coins.",itemname,price))
          end
          @scene.pbHideMoney
        end
        @scene.pbEndSellScene
      end
    =end  
    end
    
    =begin
      def pbBuyScreen
        @scene.pbStartBuyScene(@stock,@adapter)
        item=0
        loop do
          [email protected]
          quantity=0
          break if item==0
          [email protected](item)
          [email protected](item)
          if @adapter.getMoney()<price
            pbDisplayPaused(_INTL("You don't have enough coins."))
            next
          end
          if pbIsImportantItem?(item)
            if !pbConfirm(_INTL("Certainly.  You want {1}.\r\nThat will be {2} Coins.  OK?",itemname,price))
              next
            end
            quantity=1
          else
            maxafford=(price<=0) ? BAGMAXPERSLOT : @adapter.getMoney()/price
            maxafford=BAGMAXPERSLOT if maxafford>BAGMAXPERSLOT
            [email protected](
               _INTL("{1}?  Certainly.\r\nHow many would you like?",itemname),item,maxafford)
            if quantity==0
              next
            end
            price*=quantity
            if !pbConfirm(_INTL("{1}, and you want {2}.\r\nThat will be {3} Coins.  OK?",itemname,quantity,price))
              next
            end
          end
          if @adapter.getMoney()<price
            pbDisplayPaused(_INTL("You don't have enough coins."))
            next
          end
          added=0
          quantity.times do
            if [email protected](item)
              break
            end
            added+=1
          end
          if added!=quantity
            added.times do
              if [email protected](item)
                raise _INTL("Failed to delete stored items")
              end
            end
            pbDisplayPaused(_INTL("You have no more room in the Bag."))  
          else
            @adapter.setMoney(@adapter.getMoney()-price)
            for i in 0...@stock.length
              if pbIsImportantItem?(@stock[i]) && $PokemonBag.pbQuantity(@stock[i])>0
                @stock[i]=nil
              end
            end
            @stock.compact!
            pbDisplayPaused(_INTL("Here you are!\r\nThank you!"))
            if $PokemonBag
              if quantity>=10 && isConst?(item,PBItems,:POKEBALL) && 
                 hasConst?(PBItems,:PREMIERBALL)
                if @adapter.addItem(getConst(PBItems,:PREMIERBALL))
                  pbDisplayPaused(_INTL("I'll throw in a Premier Ball, too.")) 
                end
              end
            end
          end
        end
        @scene.pbEndBuyScene
      end
    =end
    
    def pbgamecorner(stock,speech=nil,cantsell=false)
      pbcoinvalue
      for i in 0...stock.length
        if pbIsImportantItem?(stock[i]) && $PokemonBag.pbQuantity(stock[i])>0
          stock[i]=nil
        end
      end
      stock.compact!
      commands=[]
      cmdBuy=-1
      cmdQuit=-1
      commands[cmdBuy=commands.length]=_INTL("Buy")
      commands[cmdQuit=commands.length]=_INTL("Quit")
      cmd=Kernel.pbMessage(
         speech ? speech : _INTL("Welcome!\r\nHow may I serve you?"),
         commands,cmdQuit+1)
      loop do
        if cmdBuy>=0 && cmd==cmdBuy
          scene=GameCornerScene.new
          screen=PokemonMartCoinsScreen.new(scene,stock)
          screen.pbBuyScreen
        else
          Kernel.pbMessage(_INTL("Please come again!"))
          break
        end
        cmd=Kernel.pbMessage(
           _INTL("Is there anything else I can help you with?"),commands,cmdQuit+1)
         end
        pbgoldvalue
    end
    Code:
    pbgamecorner([ 
    PBItems::POKEBALL, 
    PBItems::POTION, 
    PBItems::ANTIDOTE,
    ])
    Reply With Quote

    Relevant Advertising!

      #2    
    Old February 6th, 2014 (12:17 AM).
    Milkvetch Milkvetch is offline
       
      Join Date: Dec 2013
      Gender: Male
      Posts: 20
      How much money does one coin equal?
      Reply With Quote
        #3    
      Old February 6th, 2014 (12:38 AM).
      p.claydon p.claydon is offline
         
        Join Date: Jan 2011
        Gender:
        Posts: 335
        its up to you search for
        return $ItemData[item][ITEMPRICE]
        and ass a sum at the end such as *2
        __________________
        Still learning how to sprite but if you want to look at my progress then here you go
        http://pclaydon.deviantart.com/gallery/
        Reply With Quote
          #4    
        Old February 6th, 2014 (2:07 PM).
        Nickalooose Nickalooose is offline
        --------------------
           
          Join Date: Mar 2008
          Gender: Female
          Posts: 1,309
          I don't quite understand something... Why do you change coins and money around? It's the equivalent of just using one or the other... Couldn't you just remove these:

          Code:
          def pbcoinvalue
            $game_variables[32]=$PokemonGlobal.coins
            $game_variables[31]=$Trainer.money
            $Trainer.money=$game_variables[32]
          end
          
          def pbgoldvalue
            $game_variables[32]=$Trainer.money
            $Trainer.money=$game_variables[31]
            $PokemonGlobal.coins=$game_variables[32]
          end
          Why didn't you just change any $Trainer.money, to $PokemonGlobal.coins? It's simpler.
          Reply With Quote
            #5    
          Old February 6th, 2014 (11:03 PM).
          p.claydon p.claydon is offline
             
            Join Date: Jan 2011
            Gender:
            Posts: 335
            so its changed back again once the shop ends
            __________________
            Still learning how to sprite but if you want to look at my progress then here you go
            http://pclaydon.deviantart.com/gallery/
            Reply With Quote
              #6    
            Old February 7th, 2014 (3:00 AM). Edited February 7th, 2014 by Nickalooose.
            Nickalooose Nickalooose is offline
            --------------------
               
              Join Date: Mar 2008
              Gender: Female
              Posts: 1,309
              I can see that... But if you were to use just coins here, you'd have zero use for those to def's and you free up those 2 variables.

              My point in questioning this btw, is; when a new script is added by members here, I take a look and see what I can learn from it... So I wanted to know what your reason behind this is... In my opinion it seems pointless, so I'm asking you, why... If it's to make it appear as if you're using coins instead of money, then I don't get it... Because you can just use coins instead, there is no need to make your money the coins..
              Reply With Quote
                #7    
              Old February 7th, 2014 (10:02 AM).
              p.claydon p.claydon is offline
                 
                Join Date: Jan 2011
                Gender:
                Posts: 335
                because at the time i didnt know how to change it so it was coins instead of money so that was the only way around it i have since changed the script and now incorporated it into the pokemart script so not to redo any def or anythig like that
                __________________
                Still learning how to sprite but if you want to look at my progress then here you go
                http://pclaydon.deviantart.com/gallery/
                Reply With Quote
                Reply
                Quick Reply

                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 11:43 AM.