The PokéCommunity Forums Fan Games Game Development Scripts & Tutorials
Essentials Script Asynchronous co-op multiplayer

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 21st, 2015 (4:57 PM).
Badhaas's Avatar
Badhaas Badhaas is offline
     
    Join Date: Jul 2013
    Gender: Male
    Posts: 119
    This scripts adds the functionality of an asynchronous co-op system similar to that in the "tales of" games. This means that player 2 can control the partner trainer during combat. The basics are controls for two players, player 2 controlling the partner trainer who can attack, switch Pokémon, and use items from player 1's bag. How to implement this is explained below. Besides that there will be some add-ons added in the future (i.e. no auto healing after battle, instead at a PokéCenter; player 2 also gaining experience and leveling). When used credits would be appreciated.

    Controls:
    Turning on the co-op controls moves player 1's controls to the right side of the keyboard and sets player 2's controls at the left side. Note that while co-op is disabled the player can still use the controls at the right side of the keyboard (the same as when co-op is enabled). The controls are:
    Spoiler:
    Player 1:
    - Arrow keys = move
    - numpad 1 = Accept
    - numpad 2 = Cancel/Menu
    - Numpad 3 = run
    - Numpad 4/5/6 = Z/Y/X (rmxp input)
    - Numpad 0 and Period = L and R

    Player 2:
    - WASD = move
    - F = Accept
    - G = Cancel/Menu
    - H = run
    - R/T/Y = Z/Y/X (rmxp input)
    - Q/E = L and R

    Note: If you'd like to change the controls you'll have to change the script in PokemonControls. For the key codes I recommend looking in FLs "set the input" script.


    The Basics
    Make the following changes to the PokemonControls script:
    Spoiler:
    Search for the following section;
    Code:
        case button
          when Input::DOWN
            return [0x28] # Down
          when Input::LEFT
            return [0x25] # Left
          when Input::RIGHT
            return [0x27] # Right
          when Input::UP
            return [0x26] # Up
          when Input::A
            return [0x5A,0x10] # Z, Shift
          when Input::B
            return [0x58,0x1B] # X, ESC 
          when Input::C
            return [0x43,0x0d,0x20] # C, ENTER, Space
          when Input::X
            return [0x41] # A
          when Input::Y
            return [0x53] # S
          when Input::Z
            return [0x44] # D
          when Input::L
            return [0x51,0x21] # Q, Page Up
          when Input::R
            return [0x57,0x22] # W, Page Down
    And replace it by the code below;
    Code:
        $PokemonSystem.multiplayer = 0 if $PokemonSystem.multiplayer == nil
        $PokemonSystem.cur_player = 0 if $PokemonSystem.cur_player == nil
        case button
          when Input::DOWN                                      # DOWN
            if $PokemonSystem.multiplayer == 1 && $PokemonSystem.cur_player == 1
              return [0x53] # S (Only for player 2 when co-op)
            else  # Player 1, or solo
              return [0x28] # Down
            end
          when Input::LEFT                                      # LEFT
            if $PokemonSystem.multiplayer == 1 && $PokemonSystem.cur_player == 1
              return [0x41] # A
            else
              return [0x25] # Left
            end
          when Input::RIGHT                                     # RIGHT
            if $PokemonSystem.multiplayer == 1 && $PokemonSystem.cur_player == 1
              return [0x44] # D
            else
              return [0x27] # Right
            end
          when Input::UP                                        # UP
            if $PokemonSystem.multiplayer == 1 && $PokemonSystem.cur_player == 1
              return [0x57] # W
            else
              return [0x26] # Up
            end
          when Input::A                                     # MENU / Start
            if $PokemonSystem.multiplayer == 0  # Solo
              return [0x5A,0x10,0x63] # Z, Shift, Num 3
            else
              if $PokemonSystem.cur_player == 0 # Player 1
                return [0x63] # Num 3
              else                              # Player 2
                return [0x48] # H
              end
            end
          when Input::B                                     # B / Cancel
            if $PokemonSystem.multiplayer == 0
              return [0x58,0x1B,0x62] # X, ESC , Num 2
            else
              if $PokemonSystem.cur_player == 0
                return [0x62] # Num 2
              else
                return [0x47] # G
              end
            end
          when Input::C                                     # A / Accept
            if $PokemonSystem.multiplayer == 0
              return [0x43,0x0d,0x20,0x61] # C, ENTER, Space, Num 1
            else
              if $PokemonSystem.cur_player == 0
                return [0x61,0x0d] # Num 1 (,Enter)
              else
                return [0x46] # F
              end
            end
          when Input::X
            if $PokemonSystem.multiplayer == 0
              return [0x41,0x66] # A, Num 6
            else
              if $PokemonSystem.cur_player == 0
                return [0x66] # Num 6
              else
                return [0x59] # Y
              end
            end
          when Input::Y
            if $PokemonSystem.multiplayer == 0
              return [0x53,0x65] # S, Num 5
            else
              if $PokemonSystem.cur_player == 0
                return [0x65] # Num 5
              else
                return [0x54] # T
              end
            end
          when Input::Z
            if $PokemonSystem.multiplayer == 0
              return [0x44,0x64] # D, Num 4
            else
              if $PokemonSystem.cur_player == 0
                return [0x64] # Num 4
              else
                return [0x52] # R
              end
            end
          when Input::L                                     # L
            if $PokemonSystem.multiplayer == 0
              return [0x51,0x21,0x60] # Q, Page Up, Num 0
            else
              if $PokemonSystem.cur_player == 0
                return [0x60] # Num 0
              else
                return [0x51] # Q
              end
            end
          when Input::R                                     # R
            if $PokemonSystem.multiplayer == 0
              return [0x57,0x22,0x6E] # W, Page Down, Decimal
            else
              if $PokemonSystem.cur_player == 0
                return [0x6E] # Num Decimal
              else
                return [0x45] # E
              end
            end


    Make the following changes to the PokemonOptions script:
    Spoiler:
    - Search for "attr_accessor :language" and add "attr_accessor :multiplayer" on the line below, and "attr_accessor :cur_player" on the line below that.
    - Then find "@language = 0 # Language (see also LANGUAGES in script PokemonSystem)" and add "@multiplayer = 0 # if 0 = solo controls, 1 = co-op controls" on the line below, and "@cur_player = 0 # Player which can currently give input" on the line below that.
    - Finally find "NumberOption.new(_INTL("Speech Frame"),_INTL("Type %d"),1,$SpeechFrames.length," and add the following code above that line;
    Code:
           EnumOption.new(_INTL("Players"),[_INTL("Solo"),_INTL("Co-op")],
              proc { $PokemonSystem.multiplayer },
              proc {|value|  $PokemonSystem.multiplayer=value
              }
           ),


    Make the following changes to the PokeBattle_Battle script:
    Spoiler:
    - Find "return false if @player.is_a?(Array) && index==2" and replace it by the following code:
    Code:
        if @player.is_a?(Array) #If has partner trainer, yet no curtrainer id
          return false if index==2 && $PokemonSystem.multiplayer == 0
        end
    - Search for "def pbSecondPartyBegin(battlerIndex)" and add the following code on the empty line above it:
    Code:
      def pbPartyExact(index)
        return party1 if index==0
        return party1 if index==2 && [email protected]_a?(Array)
        return party2 if index==1
        return party2 if index==3 && [email protected]_a?(Array)
        if index==2 && @player.is_a?(Array)
          party = []
          for i in 0...6; party.push(party1[6+i]); end
        elsif index==3 && @opponent.is_a?(Array)
          party = []
          for i in 0...6; party.push(party2[6+i]); end
        end
        return party
      end
      
      def pbController(index) #returns 0 if player 1, 1 if partner, etc.
        ret = 0
        if @player.is_a?(Array) && index==2 && $PokemonSystem.multiplayer == 1
          ret = 1   #if partner trainer and co-op is turned on
        end
        return ret
      end
      
      def SetInputPlayer(index)
        # Single player is always P1
    	  if $PokemonSystem.multiplayer == 0
    	    $PokemonSystem.cur_player = 0
    	  else	# Co-op controls are enabled
    	    # Player 1:
          if @player.is_a?(Array) && index==0
            $PokemonSystem.cur_player = 0
    	    # Player 2:
          elsif @player.is_a?(Array) && index==2
            $PokemonSystem.cur_player = 1
          end
    	  end
        return
      end
    - Find "return pbSwitchPlayer(index,lax,cancancel)" and add "SetInputPlayer(index)" above that line, then add "SetInputPlayer(0)" below that line.
    - Search for "if !pbOwnedByPlayer?(i) || @controlPlayer" and add "SetInputPlayer(i)" above that line.
    - Finally search for "break if commandDone" then add "SetInputPlayer(0)" before the last 'end' below that line.


    Make the following changes to the PokeBattle_ActualScene script:
    Spoiler:
    - Search for "itemscene.pbStartScene($PokemonBag)" and add "[email protected]le.pbPartyExact(index)" below that, followed by "offset = 6 * @battle.pbController(index)" below that.
    - Find "modparty.push(@battle.party1[@battle.partyorder[i]])" and replace it by "modparty.push(party[i])".
    - Search for "[email protected][activecmd]" and replace it by "[email protected][activecmd]+offset".
    - Find "[email protected](index)" and "[email protected]". Then remove these lines and replace with the following code:
    Code:
        [email protected](index)
        whichpart= 6 * @battle.pbController(index)
    - Replace "modparty.push(party[partypos[i]])" by "modparty.push(party[i])".
    - Replace "pkmnindex=partypos[activecmd]" by "pkmnindex=activecmd".
    - Replace "canswitch=lax ? @battle.pbCanSwitchLax?(index,pkmnindex,true) :" by "canswitch=lax ? @battle.pbCanSwitchLax?(index,pkmnindex+whichpart,true) :".
    - Replace "@battle.pbCanSwitch?(index,pkmnindex,true)" by "@battle.pbCanSwitch?(index,pkmnindex+whichpart,true)".
    - Finally Replace "ret=pkmnindex" by "ret=pkmnindex+whichpart".


    Add-ons
    Will add the following in the future;
    - No healing after battle, instead the partner's Pokémon are also healed at a Pokémon Center.
    - The partner's Pokémon gaining xp.
    __________________

    View my profile page for scripts/tutorials made by me, even ones which aren't posted yet.
    Currently working on a demo for Tales from the Pokémon World (based on the World of Pokémon project)
    Reply With Quote

    Relevant Advertising!

      #2    
    Old January 21st, 2015 (7:00 PM).
    Zeak6464's Avatar
    Zeak6464 Zeak6464 is offline
    Zeak #3205 - Discord
       
      Join Date: Mar 2013
      Location: USA
      Age: 25
      Gender: Male
      Nature: Calm
      Posts: 806
      Wow looks really cool ! Now to think of way for this co-op system to work over internet...
      __________________
      Looking for a team to help me finish Pokemon Green Remix

      DM please
      Reply With Quote
        #3    
      Old April 3rd, 2018 (11:18 PM).
      HarmonyConcept HarmonyConcept is offline
         
        Join Date: Sep 2015
        Gender: Female
        Posts: 207
        For the record, this is still working great in v17.1. Thanks!
        Reply With Quote
          #4    
        Old May 13th, 2018 (8:39 PM).
        Dfox44's Avatar
        Dfox44 Dfox44 is offline
           
          Join Date: Apr 2018
          Location: Ontario,Canada
          Gender: Male
          Nature: Quiet
          Posts: 13
          This would be amazing if it somehow had online abilities due to probably won't be as often for me at least to see my friends in person to play a fan game then it would be online. I do play fan games with a friend over team viewer which could definitely work but it has a delay so that maybe could cause issues but it's an option at least.
          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 2:57 PM.