The PokéCommunity Forums Fan Games Game Development Scripts, Tutorials & Tools
Essentials Script Duel "Win" "Lose" or "Tie"

Scripts, Tutorials & Tools 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 8th, 2014 (5:55 PM). Edited January 9th, 2014 by ShadowFiendZX.
ShadowFiendZX's Avatar
ShadowFiendZX ShadowFiendZX is offline
Gym Leader
     
    Join Date: Jan 2013
    Location: Hamden Connecticut
    Age: 21
    Gender: Male
    Nature: Serious
    Posts: 59
    This is basically the original script provided with Essentials, but slightly edited to have ties.

    Open "PokemonMinigameDuel"
    and replace it with this

    Spoiler:

    Code:
    ################################################################################
    # "Duel" mini-game
    # Based on the Duel minigame by Alael
    ################################################################################
    begin
    
    class DuelWindow < Window_AdvancedTextPokemon # :nodoc:
      attr_accessor :hp
      attr_accessor :name
      attr_accessor :enemy
    
      def duelRefresh
        color= @isenemy ? "<ar><c2=043c3aff>" : "<c2=65467b14>"
        self.text=_INTL("{1}{2}<c2=06644bd2>\r\nHP: {3}",color,fmtescape(@name),@hp)
      end
    
      def initialize(name,isenemy)
        @hp=10
        @name=name
        @isenemy=isenemy
        super("")
        self.width=160
        self.height=96
        duelRefresh
      end
    
      def hp=(value)
        @hp=value
        duelRefresh
      end
    
      def name=(value)
        @name=value
        duelRefresh
      end
    
      def isenemy=(value)
        @isenemy=value
        duelRefresh
      end
    end
    
    
    
    class PokemonDuel
      def pbStartDuel(opponent,event)
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        @sprites={}
        @event=event
        @sprites["player"]=IconSprite.new(-128-32,96,@viewport)
        @sprites["opponent"]=IconSprite.new(Graphics.width+32,96,@viewport)
        @sprites["playerwindow"]=DuelWindow.new($Trainer.name,false)
        @sprites["opponentwindow"]=DuelWindow.new(opponent.name,true)
        @sprites["playerwindow"][email protected]["playerwindow"].width
        @sprites["opponentwindow"].x=Graphics.width
        @sprites["playerwindow"][email protected]
        @sprites["opponentwindow"][email protected]
        @sprites["player"].setBitmap(
           sprintf("Graphics/Characters/trainer%03d",$Trainer.trainertype))
        @sprites["opponent"].setBitmap(
           sprintf("Graphics/Characters/trainer%03d",opponent.trainertype))
        pbWait(20)
        while @sprites["player"].x<0
          @sprites["player"].x+=4
          @sprites["playerwindow"].x+=4
          @sprites["opponent"].x-=4
          @sprites["opponentwindow"].x-=4
          Graphics.update
          Input.update
          pbUpdateSceneMap
        end
        @oldmovespeed=$game_player.move_speed
        @oldeventspeed=event.move_speed
        pbMoveRoute($game_player,[
           PBMoveRoute::ChangeSpeed,2,
           PBMoveRoute::DirectionFixOn
        ])
        pbMoveRoute(event,[
           PBMoveRoute::ChangeSpeed,2,
           PBMoveRoute::DirectionFixOn
        ])
        pbWait(30)
      end
    
      def pbRefresh
        @sprites["playerwindow"][email protected][0]
        @sprites["opponentwindow"][email protected][1]
        pbWait(10)
      end
    
      def pbFlashScreens(player,opponent)
        i=0
        8.times do
          i+=1
          if player
            @sprites["player"].color=Color.new(255,255,255,i*64)
            @sprites["playerwindow"].color=Color.new(255,255,255,i*64)
          end
          if opponent
            @sprites["opponent"].color=Color.new(255,255,255,i*64)
            @sprites["opponentwindow"].color=Color.new(255,255,255,i*64)
          end
          Graphics.update
          Input.update
          pbUpdateSceneMap
        end
        8.times do
          i-=1
          if player
            @sprites["player"].color=Color.new(255,255,255,i*64)
            @sprites["playerwindow"].color=Color.new(255,255,255,i*64)
          end
          if opponent
            @sprites["opponent"].color=Color.new(255,255,255,i*64)
            @sprites["opponentwindow"].color=Color.new(255,255,255,i*64)
          end
          Graphics.update
          Input.update
          pbUpdateSceneMap
        end
        pbWait(16) if !player || !opponent
      end
    
      def pbEndDuel
        pbWait(30)
        pbMoveRoute($game_player,[
           PBMoveRoute::DirectionFixOff, 
           PBMoveRoute::ChangeSpeed,@oldmovespeed
        ])
        pbMoveRoute(@event,[
           PBMoveRoute::DirectionFixOff, 
           PBMoveRoute::ChangeSpeed,@oldeventspeed
        ])
        16.times do
          @sprites["player"].opacity-=16
          @sprites["opponent"].opacity-=16
          @sprites["playerwindow"].contents_opacity-=16
          @sprites["opponentwindow"].contents_opacity-=16
          @sprites["playerwindow"].opacity-=16
          @sprites["opponentwindow"].opacity-=16
          Graphics.update
          Input.update
          pbUpdateSceneMap  
        end
        pbDisposeSpriteHash(@sprites)
        @viewport.dispose
      end
    
      def pbDuel(opponent,event,speeches)
        pbStartDuel(opponent,event)
        @hp=[10,10]
        @special=[false,false]
        decision=nil
        loop do
          @hp[0]=[@hp[0],0].max
          @hp[1]=[@hp[1],0].max
          pbRefresh
          if @hp[0]<=0
            if @hp[1]<=0
              decision=3
              break
            else
              decision=2
              break
            end
          elsif @hp[1]<=0
            decision=1
            break
            end
          #if @hp[0]<=0
          #  decision=1
           # break
         # end
         # if @hp[1]<=0
         #   decision=2
         #   break
        #  end
        #  if @hp[0]<=0 && @hp[1]<=0
        #    decision=3
        #    break
        #    end
          action=0
          scores=[3,4,4,2]
          choices=(@special[1]) ? 3 : 4
          scores[3]=0 if @special[1]
          total=scores[0]+scores[1]+scores[2]+scores[3]
          if total<=0
            action=rand(choices)
          else
            num=rand(total)
            cumtotal=0
            for i in 0...4
              cumtotal+=scores[i]
              if num<cumtotal
                action=i
                break
              end
            end
          end
          @special[1]=true if action==3
          Kernel.pbMessage(_INTL("{1}: {2}",opponent.name,speeches[action*3+rand(3)]))
          command=rand(4)
          list=[
             _INTL("DEFEND"),
             _INTL("PRECISE ATTACK"),
             _INTL("FIERCE ATTACK")
          ]
          if [email protected][0]
            list.push(_INTL("SPECIAL ATTACK"))
          end
          command=Kernel.pbMessage(_INTL("Choose a command."),list,0)
          if command==3
            @special[0]=true
          end
          if action==0 && command==0
            pbMoveRoute($game_player,[
               PBMoveRoute::ScriptAsync,"moveRight90",
               PBMoveRoute::ScriptAsync,"moveLeft90",
               PBMoveRoute::ScriptAsync,"moveLeft90",
               PBMoveRoute::ScriptAsync,"moveRight90"
            ])
            pbMoveRoute(event,[
               PBMoveRoute::ScriptAsync,"moveLeft90",
               PBMoveRoute::ScriptAsync,"moveRight90",
               PBMoveRoute::ScriptAsync,"moveRight90",
               PBMoveRoute::ScriptAsync,"moveLeft90"
            ])
            pbWait(10*2)
            Kernel.pbMessage(_INTL("You study each other's movements..."))
          elsif action==0 && command==1
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::Forward
            ])
            pbWait(8*2)
            pbShake(9,9,8)
            pbFlashScreens(false,true)
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Backward
            ])
            @hp[1]-=1
            Kernel.pbMessage(_INTL("Your attack was not blocked!"))
          elsif action==0 && command==2
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::ScriptAsync,"jumpForward"])
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::Backward])
            pbWait(20*2)
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Backward])
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Forward])   
            Kernel.pbMessage(_INTL("Your attack was evaded!"))
          elsif (action==0 || action==1 || action==2) && command==3
            pbMoveRoute($game_player,[
            PBMoveRoute::ChangeSpeed,4, 
            PBMoveRoute::ScriptAsync,"jumpForward"])
            pbWait(8*2)
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,5,
               PBMoveRoute::Backward,
               PBMoveRoute::ChangeSpeed,2])
            pbWait(10*2)
            pbShake(9,9,8)
            pbFlashScreens(false,true)
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Backward])
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Forward])
            @hp[1]-=3
            Kernel.pbMessage(_INTL("You pierce through the opponent's defenses!"))
          elsif action==1 && command==0
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::Forward
            ])
            pbWait(8*2)
            pbShake(9,9,8)
            pbFlashScreens(true,false)
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Backward
            ])
            @hp[0]-=1
            Kernel.pbMessage(_INTL("You fail to block the opponent's attack!"))
          elsif action==1 && command==1
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::Forward])
            pbWait(12*2)
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Backward])
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Forward])
            pbWait(12*2)
            pbMoveRoute(event,[PBMoveRoute::Backward])
            pbMoveRoute($game_player,[PBMoveRoute::Forward])
            pbWait(12*2)
            pbMoveRoute($game_player,[PBMoveRoute::Backward])
            Kernel.pbMessage(_INTL("You cross blades with the opponent!"))
          elsif (action==1 && command==2) ||
                (action==2 && command==1) ||
                (action==2 && command==2)
            pbMoveRoute($game_player,[
               PBMoveRoute::Backward,
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::ScriptAsync,"jumpForward"])
            pbWait(16*2)
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,4,
               PBMoveRoute::Forward])
            pbWait(8*2)
            pbWait(10*2)
            pbShake(9,9,8)
            pbFlashScreens(true,true)
            pbMoveRoute($game_player,[
               PBMoveRoute::Backward,
               PBMoveRoute::ChangeSpeed,2])    
            pbMoveRoute(event,[
               PBMoveRoute::Backward,
               PBMoveRoute::Backward,
               PBMoveRoute::ChangeSpeed,2]) 
            pbWait(20*2)
            pbMoveRoute(event,[PBMoveRoute::Forward])
            pbMoveRoute($game_player,[PBMoveRoute::Forward])
            @hp[0]-=action # Enemy action
            @hp[1]-=command # Player command
            Kernel.pbMessage(_INTL("You hit each other!"))
          elsif action==2 && command==0
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::Forward])
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::ScriptAsync,"jumpBackward"])
            pbWait(20*2)
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Forward])
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Backward])   
            Kernel.pbMessage(_INTL("You evade the opponent's attack!"))
          elsif action==3 && (command==0 || command==1 || command==2)
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,4, 
               PBMoveRoute::ScriptAsync,"jumpForward"])
            pbWait(8*2)
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,5,
               PBMoveRoute::Backward,
               PBMoveRoute::ChangeSpeed,2])
            pbWait(10*2)
            pbShake(9,9,8)
            pbFlashScreens(true,false)
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Forward])
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,2, 
               PBMoveRoute::Backward])
            @hp[0]-=3
            Kernel.pbMessage(_INTL("The opponent pierces through your defenses!"))
          elsif action==3 && command==3
            pbMoveRoute($game_player,[PBMoveRoute::Backward])
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,4,
               PBMoveRoute::ScriptAsync,"jumpForward"
            ])
            pbMoveRoute(event,[
               PBMoveRoute::Wait,15,
               PBMoveRoute::ChangeSpeed,4,
               PBMoveRoute::ScriptAsync,"jumpForward"
            ])
            pbWait(20*2)
            pbMoveRoute(event,[
               PBMoveRoute::ChangeSpeed,5,
               PBMoveRoute::Backward,
               PBMoveRoute::ChangeSpeed,2
            ])
            pbMoveRoute($game_player,[
               PBMoveRoute::ChangeSpeed,5,
               PBMoveRoute::Backward,
               PBMoveRoute::ChangeSpeed,2
            ])
            pbShake(9,9,8)
            pbFlash(Color.new(255,255,255,255),20)
            pbFlashScreens(true,true)
            pbMoveRoute($game_player,[PBMoveRoute::Forward])
            @hp[0]-=4
            @hp[1]-=4
            Kernel.pbMessage(_INTL("Your special attacks collide!"))
          end
        end
        pbEndDuel
        #return decision
        pbSet(1,decision)
      end
    end
    
    
    
    # Starts a duel.
    # trainerid - ID of the opponent's trainer type.
    # trainername - Name of the opponent
    # event - Game_Event object for the character's event
    # speeches - Array of 12 speeches
    def pbDuel(trainerid,trainername,event,speeches)
      duel=PokemonDuel.new
      opponent=PokeBattle_Trainer.new(
         pbGetMessageFromHash(MessageTypes::TrainerNames,trainername),
         trainerid)
      speechtexts=[]
      for i in 0...12
        speechtexts.push(_I(speeches[i]))
      end
      duel.pbDuel(opponent,event,speechtexts)
    end
    
    
    
    rescue Exception
    if $!.is_a?(SystemExit) || "#{$!.class}"=="Reset"
      raise $!
    else
    end
    
    end


    The event should look like this, instead of the variable decision being true or false, it is now 1,2, or 3.



    the cutoff Kernel.pbDuel thing looks like this:

    Code:
    Kernel.pbDuel(PBTrainers::LEADER_Eliot,"Eliot",get_character(0),$speeches)
    The setup for it hasn't been changed, so you can refer to the wiki for that.

    You don't really need to credit me, since I only changed a few things, but it'd be cool if you did.

    If you have any problems just comment.
    Happy game making :)

    Edit:
    I've written my own set of scripts for being able to harvest items from Pokémon, IE you deposit a Pokémon into the "harvester" (for lack of a better word) and you get certain items after a while, such as Clamperl gets big pearls, or pearls. There are rare harvests, and common harvests. Just comment saying you'd like me to post that script, and I will edit it to make it a bit more user friendly then post it.
    __________________
    BEHOLD THE FLOPPY MAGIKARP IN ALL ITS GLORY AND WISDOM

    Reply With Quote
      #2    
    Old January 11th, 2014 (7:41 AM).
    ShadowFiendZX's Avatar
    ShadowFiendZX ShadowFiendZX is offline
    Gym Leader
       
      Join Date: Jan 2013
      Location: Hamden Connecticut
      Age: 21
      Gender: Male
      Nature: Serious
      Posts: 59
      Am I the only one who wanted to be able to have a draw/tie instead of just win or lose?
      __________________
      BEHOLD THE FLOPPY MAGIKARP IN ALL ITS GLORY AND WISDOM

      Reply With Quote
        #3    
      Old 2 Weeks Ago (7:23 AM).
      Linkarnation's Avatar
      Linkarnation Linkarnation is offline
      Salyhin
         
        Join Date: Apr 2014
        Gender: Male
        Posts: 2
        Why do I get this error?
        Untitled.png
        __________________
        I'm an elitist.
        Reply With Quote
          #4    
        Old 2 Weeks Ago (1:43 PM).
        komaoto's Avatar
        komaoto komaoto is offline
           
          Join Date: Mar 2014
          Location: Brazil
          Gender: Male
          Posts: 125
          You probably didn't use extendtext. It's a program inside essentials folder that enlarges text boxes.

          Go to essentials folder and open your project.
          While open, go to essentials folder (again) and double-click the icon that says "extendtext" Theres a program and theres a .txt, open the program.
          Done.

          It will NOT show up in the task bar, but it's already running. No need to do anything anymore.
          You will notice that, when you use the "show text" and the "script" event command, they'll have enlarged text boxes. This should be your main method to input script commands. It can fix a bunch of sintax errors you might find while making your game.
          Reply With Quote
            #5    
          Old 2 Weeks Ago (3:31 PM).
          Vendily's Avatar
          Vendily Vendily is offline
             
            Join Date: Aug 2015
            Gender: Female
            Nature: Calm
            Posts: 772
            The problem isn't the extendtext, you forgot the commas!
            Code:
            $speeches.push(
            "special 1",
            "special 2",
            "special 3")
            __________________
            Resources for ROM hackers has moved.

            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 1:07 AM.