The PokéCommunity Forums Fan Games Game Development Scripts & Tutorials
Essentials Script Mach and Acrobike help needed

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 November 18th, 2017 (1:59 AM). Edited November 18th, 2017 by Auroran.
Auroran's Avatar
Auroran Auroran is offline
     
    Join Date: Feb 2013
    Gender: Male
    Posts: 23
    So I've been trying to implement the Acro and Mach Bikes into a vanilla version of 17.2 Essentials. The script I'm using is quite an old one I found for essentials v14 (Kudos to REI) and I've performed a little cleanup to make it compatible with v17.2, and everything seems to work fine, the animations and terrain tags all work as are supposed to (though I am using placeholder graphics at the moment for the acro bike wheelies).

    My issue is that bridges are completely broken, and the character is able to walk on the edge tile of a lake (though strangely not the ocean tiles). The player cannot walk further into the water, and surfing still functions normally.

    I get the following error on attempting to navigate a bridge from above or underneath:



    I believe the error lies in this portion of script (see spoiler tag for full script)

    Code:
        
    for i in [2, 1, 0]
          tile_id = data[x, y, i]
          next if tile_id && @terrain_tags[tile_id]==PBTerrain::Bridge &&
                  $PokemonMap && $PokemonMap.bridge==0
          if tile_id == nil
            return false
          # Make water tiles passable if player is surfing
          elsif PBTerrain.isPassableWater?(@terrain_tags[tile_id]) &&
             $PokemonGlobal.surfing #&& self_event==$game_player
            return true
          elsif @terrain_tags[tile_id]==PBTerrain::TallGrass &&
             $PokemonGlobal.bicycle && self_event==$game_player
            return false
          elsif @terrain_tags[tile_id]==PBTerrain::Bridge && $PokemonMap &&
                $PokemonMap.bridge>0
            if @passages[tile_id] & bit != 0 ||
               @passages[tile_id] & 0x0f == 0x0f
              return false
            else
              return true
            end
    I could be completely wrong, but from what I can see, from my limited understanding and the error above that the metadata doesn't define the player being on a 'bridge' so removing that condition does stop the crash from happening, however, bridges then become impassable from the top (though are passable underneath) and attempts to do the same for surfing just results in all water tiles becoming passable. Due to my lack of experience, I am unsure of what these checks are actually checking for in setting the passibility, so I could really use some help in dissecting this problem to ensure any solution keeps feature functioning as intended.

    Here is my full script. I inserted it above main.

    Spoiler:
    Code:
    ################################################################################
    # Mach & Acro Bike Script
    # By Hansiec
    # Credits required
    ################################################################################
    # * Adds the Support for Acro Bikes and Mach Bikes!
    #
    # * How To Use (Acro Bike):
    #    - Insert Script
    #    - Edit the AcroBikeFileName Setting to what your Acro Bike Graphics would be
    #    - ADD THE GRAPHICS INTO THE CHARACTERS FOLDER
    #    - ADD THE ITEM "ACROBIKE" (The internal name must be ACROBIKE at the very
    #       least)
    #
    # * How To Use (Mach Bike):
    #   - ADD THE ITEM "MACHBIKE" (The internal name must be MACHBIKE at the very
    #       least)
    #
    # * How to create Acro Bike Rails:
    #   - Go into the Tileset Editor (through DEBUG mode or Essentials)
    #   - Find your desired Acro Bike Rails and set their Terrain Tag to 16
    #   - Go into RMXP's tileset editor and set the passages (4dir) of the rails
    #     to what it would normally be to pass (EG: Rails left and right need the
    #     left and right passages open but the top and bottom closed)
    #
    #
    # * How to create Acro Bike Stepping Stones:
    #   - Go into the Tileset Editor (through DEBUG mode or Essentials)
    #   - Find your desired Acro Bike Stepping Stones and set their Terrain Tag to 17
    #   - Go into RMXP's tileset editor and set the passages of the stepping stones
    #     to impassable (the script will allow you to move on them while hopping)
    #
    # * How to create Mach Bike Slopes:
    #   - Go into the Tileset Editor (through DEBUG mode or Essentials)
    #   - Find your desired Mach Bike Slopes and set their Terrain Tag to 18
    #   - Go into RMXP's tileset editor and set the passages of the slope to passable
    #
    #
    # * Updates:
    #    - Fixed Where you can turn to incorrect directions on rails
    #    - Fixed Where you need to do a wheelie on an Acro Bike to access rails
    #    - Fixed Where there is a few frame skips between running/biking animations
    #    - Fixed When you switch from the Acro Bike to a regular Bike, that the
    #       regular bike has the settings of the Acro Bike
    #    - Added Rail to Rail Jumping on Acro Bikes
    #    - Added Mach Bike Support
    #
    ################################################################################
    
    module Settings
      AcroBikeFileName = [
      "boy_run", # Player A
      "girl_run", # Player B
      "", # Player C
      "", # Player D
      "", # Player E
      "", # Player F
      ]
    end
    
    
    module PBTerrain
      ACROBIKE = 17
      ACROBIKEHOP = 18
      MACHBIKE = 19
    end
    
    
    class Game_Map
      attr_accessor :acrobike
      attr_accessor :acrobike_held
      attr_accessor :forceacro
      attr_accessor :machbike_speed
      
      alias initialize_ab initialize
      def initialize
        @acrobike = 0
        @acrobike_held = 0
        @forceacro = 0
        @machbike_speed = 0
        initialize_ab
      end
      
      def passable?(x, y, d, self_event = nil)
        return false if !valid?(x, y)
        bit = (1 << (d / 2 - 1)) & 0x0f
        for event in events.values
          if event.tile_id >= 0 and event != self_event and
             event.x == x and event.y == y and not event.through
            return false if @passages[event.tile_id] & bit != 0
            return false if @passages[event.tile_id] & 0x0f == 0x0f
            return true if @priorities[event.tile_id] == 0
          end
        end
        for i in [2, 1, 0]
          tile_id = data[x, y, i]
          next if tile_id && @terrain_tags[tile_id]==PBTerrain::Bridge &&
                  $PokemonMap && $PokemonMap.bridge==0
          if tile_id == nil
            return false
          # Make water tiles passable if player is surfing
          elsif PBTerrain.isPassableWater?(@terrain_tags[tile_id]) &&
             $PokemonGlobal.surfing #&& self_event==$game_player
            return true
          elsif @terrain_tags[tile_id]==PBTerrain::TallGrass &&
             $PokemonGlobal.bicycle && self_event==$game_player
            return false
          elsif @terrain_tags[tile_id]==PBTerrain::Bridge && $PokemonMap &&
                $PokemonMap.bridge>0
            if @passages[tile_id] & bit != 0 ||
               @passages[tile_id] & 0x0f == 0x0f
              return false
            else
              return true
            end
          elsif @terrain_tags[tile_id]==PBTerrain::MACHBIKE
            return self_event==$game_player || self_event==nil
          elsif @terrain_tags[tile_id]==PBTerrain::ACROBIKE && self_event==$game_player &&
          $PokemonGlobal.acrobike && (@passages[tile_id] & bit == 0)
            return true
          elsif (@terrain_tags[tile_id]==PBTerrain::ACROBIKEHOP || @terrain_tags[tile_id]==PBTerrain::ACROBIKE) && 
            @acrobike==2 && self_event==$game_player && $PokemonGlobal.acrobike
            return true
          elsif @terrain_tags[tile_id]==PBTerrain::ACROBIKE && !$PokemonGlobal.acrobike
            return false
          elsif @terrain_tags[tile_id]==PBTerrain::ACROBIKEHOP && !$PokemonGlobal.acrobike
            return false
          elsif @passages[tile_id] & bit != 0
            return false
          elsif @passages[tile_id] & 0x0f == 0x0f
            return false
          elsif @priorities[tile_id] == 0
            return true
          end
        end
        return true
      end
      
      alias update_ab update
      def update
        @acrobike_held += 1 if !$game_player.moving?
        @acrobike_held = 0 if !Input.press?(Input::A) || !$PokemonGlobal.acrobike
        @acrobike_held = 1 if Input.press?(Input::A) && $game_player.moving? &&
                              @acrobike < 2 && @acrobike != 0
        tag = pbGetTerrainTag($game_player)
        @forceacro = 0
        @forceacro = 1 if tag == PBTerrain::ACROBIKEHOP
        @acrobike = @forceacro
        @acrobike = 1 if @acrobike_held > 0
        if acrobike_held >= Graphics.frame_rate * 2
          @acrobike = 2
        end
        
        
        if $game_player.passableEx?($game_player.x, $game_player.y,
          $game_player.direction) && $PokemonGlobal.machbike && Input.dir4 != 0
          @machbike_speed += 0.1
          @machbike_speed = 3 if @machbike_speed > 3
        else
          @machbike_speed = 0
        end
        
        ### Graphical things
        graphic = Settings::AcroBikeFileName[$PokemonGlobal.playerID]
        if FileTest.image_exist?("Graphics/Characters/" + graphic) && Input.press?(Input::A) &&
          $PokemonGlobal.acrobike
          $game_player.character_name = graphic
        elsif Input.release?(Input::A)
          Kernel.pbUpdateVehicle
        end
        if @acrobike > 1
          if !$game_player.jumping?
            Kernel.pbJumpToward(0)
            pbSEPlay("jump")
          end
        end
        update_ab
      end
      
    end
    
    class Game_Player
      alias update_ab update
      def update
        dir = @direction
        update_ab
        dir2 = @direction
        # Make it so you can't turn incorrectly on rails
        if $PokemonGlobal.acrobike && terrain_tag == PBTerrain::ACROBIKE
          if !passableEx?(x, y, @direction, false)
            @direction=dir
          end
        end
    
        # Do a jump onto another rail
        if !passableEx?(x, y, dir2, false) && Input.trigger?(Input::A) && $PokemonGlobal.acrobike
          dir = @direction
          if (dir2 == 2) # Down
            tag = $game_map.terrain_tag(x, y + 1, false)
            if tag == PBTerrain::ACROBIKE
              $game_player.jump(0,1)
              pbSEPlay("jump")
            end
          elsif (dir2 == 4) # Left
            tag = $game_map.terrain_tag(x - 1, y, false)
            if tag == PBTerrain::ACROBIKE
              $game_player.jump(-1,0)
              pbSEPlay("jump")
            end
          elsif (dir2 == 6) # Right
            tag = $game_map.terrain_tag(x + 1, y, false)
            if tag == PBTerrain::ACROBIKE
              $game_player.jump(1,0)
              pbSEPlay("jump")
            end
          elsif (dir2 == 8) # Up
            tag = $game_map.terrain_tag(x, y - 1, false)
            if tag == PBTerrain::ACROBIKE
              $game_player.jump(0,-1)
              pbSEPlay("jump")
            end
          end
          @direction = dir
        end
        
        #### Mach Bike
        if $PokemonGlobal.machbike
          @move_speed = 3 + $game_map.machbike_speed.floor
        end
        if $game_map.machbike_speed < 2 && terrain_tag == PBTerrain::MACHBIKE
          move_down(false)
          $game_map.machbike_speed = 0
        end
      end
    end
    
    class PokemonGlobalMetadata
      attr_accessor :acrobike
      attr_accessor :machbike
    end
    
    ItemHandlers::UseInField.add(:BICYCLE,proc{|item|
        if pbBikeCheck
         $PokemonGlobal.machbike = false
         $PokemonGlobal.acrobike = false
         if $PokemonGlobal.acrobike
           Kernel.pbDismountBike
           $PokemonGlobal.bicycle = false
         else
           Kernel.pbMountBike 
           $PokemonGlobal.bicycle = true
         end
       end
    })
    
    # Add Acro Bike Property
    ItemHandlers::UseInField.add(:ACROBIKE,proc{|item|
       if pbBikeCheck
         $PokemonGlobal.machbike = false
         if $PokemonGlobal.acrobike
           Kernel.pbDismountBike
           $PokemonGlobal.acrobike = false
         else
           Kernel.pbMountBike 
           $PokemonGlobal.acrobike = true
         end
       end
    })
    
    # Add Mach Bike Property
    ItemHandlers::UseInField.add(:MACHBIKE,proc{|item|
       if pbBikeCheck
         $PokemonGlobal.acrobike = false
         if $PokemonGlobal.machbike
           Kernel.pbDismountBike
           $PokemonGlobal.machbike = false
         else
           Kernel.pbMountBike 
           $PokemonGlobal.machbike = true
         end
       end
    })
    Reply With Quote

    Relevant Advertising!

      #2    
    Old November 19th, 2017 (6:22 PM).
    ☆Rei☆'s Avatar
    ☆Rei☆ ☆Rei☆ is offline
     
    Join Date: Aug 2009
    Location: Nearby my feet.
    Age: 21
    Gender: Female
    Nature: Calm
    Posts: 1,747
    change any instance of
    Code:
    $PokemonMap.bridge
    to
    Code:
    $PokemonGlobal.bridge
    problem solved.
    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 6:16 AM.