Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Jump By A Button

I Want To Get A Script That Lets Me Press A Button And Make My Character Jump That Is Out Of Battle And CutScene On The Map

If This Is Impossible Tell Me In The Reply :biggrin: :biggrin: :biggrin: :biggrin: :biggrin: :biggrin: :biggrin:
 
How about a two-for-one package! Both of these were designed to work together, but they're each stand-alone so its not like you need one to run the other. Basically, if you hold the [run button], then you press the [jump button] you jump an extra [run modifier] tiles, thats the only reason why I included both. Please refer to the constants in the very top of the script, as they're the settings and they're pretty self-explainitory.

Code:
#===============================================================================

# ** Run

#===============================================================================

 

module Run

  #-----------------------------------------------------------------------------

  # * Run::Speed        = [Numeric, Numeric]

  #-----------------------------------------------------------------------------

  Speed       = [3.5, 4.5]

  #-----------------------------------------------------------------------------

  # * Run::Frequency    = [Numeric, Numeric]

  #-----------------------------------------------------------------------------

  Frequency   = [3.5, 4.5]

  #-----------------------------------------------------------------------------

  # * Run::Xclude_Maps  = [map_id, map_id(,...)]

  #-----------------------------------------------------------------------------

  Xclude_Maps = []

  #-----------------------------------------------------------------------------

  # * Run::Button       = Input::???

  #-----------------------------------------------------------------------------

  Button      = Input::C

end

 

#===============================================================================

# ** Game_Player

#===============================================================================

 

class Game_Player < Game_Character

  #-----------------------------------------------------------------------------

  # * Attribute Accessors

  #-----------------------------------------------------------------------------

  attr_accessor :move_speed

  attr_accessor :move_frequency

  #-----------------------------------------------------------------------------

  # * Alias Listing

  #-----------------------------------------------------------------------------

  alias_method :run_gmplayer_update,        :update

  #-----------------------------------------------------------------------------

  # * Disable Run?

  #-----------------------------------------------------------------------------

  def disable_run?

    if Run::Xclude_Maps.is_a?(Array)

      return Run::Xclude_Maps.include?($game_map.map_id)

    end

    return false

  end

  #-----------------------------------------------------------------------------

  # * Is Running?

  #-----------------------------------------------------------------------------

  def running?

    return false if disable_run?

    return Input.press?(Run::Button)

  end

  #-----------------------------------------------------------------------------

  # * Update Method

  #-----------------------------------------------------------------------------

  def update

    run_gmplayer_update

    if running?

      @move_speed     = Run::Speed[1]

      @move_frequency = Run::Frequency[1]

    else

      @move_speed     = Run::Speed[0]

      @move_frequency = Run::Frequency[0]

    end

  end

end
Code:
#===============================================================================

# ** Jump

#===============================================================================

 

module Jump

################################################################################

# ~**                CUSTOMIZABLE CONSTANTS - BEGIN                        **~ #

################################################################################

  #-----------------------------------------------------------------------------

  # * IDs of Maps which you aren't allowed to jump

  #-----------------------------------------------------------------------------

  Xclude_Maps   = []

  #-----------------------------------------------------------------------------

  # * Distance (in tiles) that you regularly jump

  #-----------------------------------------------------------------------------

  Distance      = 3

  #-----------------------------------------------------------------------------

  # * Are you able to jump over objects with Counter tags on them?

  #-----------------------------------------------------------------------------

  Counter_Pass  = false

  #-----------------------------------------------------------------------------

  # * Jump Bonus gained from running (If using Run Script)

  #-----------------------------------------------------------------------------

  Run_Modifier  = 1

  #-----------------------------------------------------------------------------

  # * Audiofile to be played when you jump

  #-----------------------------------------------------------------------------

  SE_Jump       = RPG::AudioFile.new("015-Jump01", 80, 90)

  #-----------------------------------------------------------------------------

  # * Audofile to be played when you land

  #-----------------------------------------------------------------------------

  SE_Land       = RPG::AudioFile.new("016-Jump02", 80, 90)

  #-----------------------------------------------------------------------------

  # * Input/Key to be used to trigger the player to jump

  #-----------------------------------------------------------------------------

  Button        = Input::A

  #-----------------------------------------------------------------------------

  # * Does jumping repeat when you hold the Button?

  #-----------------------------------------------------------------------------

  Repeat        = false

################################################################################

# ~**                 CUSTOMIZABLE CONSTANTS - END                         **~ #

################################################################################

  #-----------------------------------------------------------------------------

  # * Jump.play_audiofile

  #-----------------------------------------------------------------------------

  def self.play_audiofile(se)

    case se.class.to_s

    when "RPG::AudioFile"

      unless se.name.include?("Audio/SE/")

        se.name = "Audio/SE/" + se.name

      end

      Audio.se_play(se.name, se.volume, se.pitch)

    when "String"

      unless se.include?("Audio/SE/")

        se = "Audio/SE/" + se

      end

      Audio.se_play(se, 100, 100)

    when "Array"

      n = se.size > 0 ? se[0] : ""

      v = se.size > 1 ? se[1] : 100

      p = se.size > 2 ? se[2] : 100

      unless n.include?("Audio/SE/")

        n = "Audio/SE/" + n

      end

      Audio.se_play(n, v, p)

    end

  end

  #-----------------------------------------------------------------------------

  # * Jump.se_jump

  #-----------------------------------------------------------------------------

  def self.se_jump

    return play_audiofile(SE_Jump)

  end

  #-----------------------------------------------------------------------------

  # * Jump.se_land

  #-----------------------------------------------------------------------------

  def self.se_land

    return play_audiofile(SE_Land)

  end

  #-----------------------------------------------------------------------------

  # * Jump.xclude_map?

  #-----------------------------------------------------------------------------

  def self.xclude_map?

    xclude = Xclude_Maps.is_a?(Array) ? Xclude_Maps : []

    return xclude.include?($game_map.map_id)

  end

  #-----------------------------------------------------------------------------

  # * Jump.run_modifier

  #-----------------------------------------------------------------------------

  def self.run_modifier

    return Run_Modifier.is_a?(Numeric) ? Run_Modifier : 0

  end

end

 

#===============================================================================

# ** Game_Map

#===============================================================================

 

class Game_Map

  #-----------------------------------------------------------------------------

  # * Tile Blank?

  #-----------------------------------------------------------------------------

  def no_tile?(x, y)

    [2, 1, 0].each do |i|

      return true if data[x, y, i].nil?

    end

    return data[x, y, 2].zero? && data[x, y, 1].zero? && data[x, y, 0].zero?

  end

  #-----------------------------------------------------------------------------

  # * Disable Dash?

  #-----------------------------------------------------------------------------

  def disable_jump?

    return Jump::XcludeMaps.include?(@map_id)

  end

end

 

#===============================================================================

# ** Game_Character

#===============================================================================

 

class Game_Character

  #-----------------------------------------------------------------------------

  # * Alias Listings

  #-----------------------------------------------------------------------------

  alias_method :character_jump,         :jump

  alias_method :character_update_jump,  :update_jump

  alias_method :no_tile_passable?,      :passable?

  #-----------------------------------------------------------------------------

  # * Jump

  #-----------------------------------------------------------------------------

  def jump(x_plus, y_plus)

    Jump.se_jump

    character_jump(x_plus, y_plus)

  end

  #-----------------------------------------------------------------------------

  # * Update Jump

  #-----------------------------------------------------------------------------

  def update_jump

    character_update_jump

    if @jump_count.zero?

      Jump.se_land

    end

  end

  #-----------------------------------------------------------------------------

  # * Passable?

  #-----------------------------------------------------------------------------

  def passable?(x, y, d)

    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

    return $game_map.no_tile?(new_x, new_y) ? false : no_tile_passable?(x, y, d)

  end

end

 

#===============================================================================

# ** Game_Player

#===============================================================================

 

class Game_Player < Game_Character

  #-----------------------------------------------------------------------------

  # * Alias Listings

  #-----------------------------------------------------------------------------

  alias_method :jump_player_update,         :update

  #-----------------------------------------------------------------------------

  # * Update

  #-----------------------------------------------------------------------------

  def update

    jump_player_update

    unless Jump.xclude_map? || jumping? || !jump_valid?

      if Jump::Repeat ? Input.press?(Jump::Button) : Input.trigger?(Jump::Button)

        case @direction

        when 2 # Jump Down  / Down-Left || Down-Right

          if    attempt_lower_left?   ; jump(-(jump_dist-1), (jump_dist-1))

          elsif attempt_lower_right?  ; jump((jump_dist-1), (jump_dist-1))

          else                        ; jump(0, jump_dist)

          end

        when 4 # Jump Left  / Up-Left   / Down-Left

          if    attempt_upper_left?   ; jump(-(jump_dist-1), -(jump_dist-1))

          elsif attempt_lower_left?   ; jump(-(jump_dist-1), (jump_dist-1))

          else                        ; jump(-jump_dist, 0)

          end

        when 6 # Jump Right / Up-Right  / Down-Right

          if    attempt_upper_right?  ; jump((jump_dist-1), -(jump_dist-1))

          elsif attempt_lower_right?  ; jump((jump_dist-1), (jump_dist-1))

          else                        ; jump(jump_dist, 0)

          end

        when 8 # Jump Up    / Up-Left   / Up-Right

          if    attempt_upper_left?   ; jump(-(jump_dist-1), -(jump_dist-1))

          elsif attempt_upper_right?  ; jump((jump_dist-1), -(jump_dist-1))

          else                        ; jump(0, -jump_dist)

          end

        end

      end

    end

  end

  #-----------------------------------------------------------------------------

  # * Jump Valid ?

  #-----------------------------------------------------------------------------

  def jump_valid?

    return $DEBUG if Input.press?(Input::CTRL)

    case move_direction

    when 1

      return false if self.y > $game_map.height - Jump::Distance

      return false if self.x < Jump::Distance

    when 3

      return false if self.y > $game_map.height - Jump::Distance

      return false if self.x > $game_map.width  - Jump::Distance

    when 7

      return false if self.y < Jump::Distance

      return false if self.x > $game_map.width  - Jump::Distance 

    when 9

      return false if self.y < Jump::Distance

      return false if self.x < Jump::Distance

    end

    case @direction

    when 2 ; return false if self.y > $game_map.height - Jump::Distance

    when 4 ; return false if self.x < Jump::Distance

    when 6 ; return false if self.x > $game_map.width  - Jump::Distance

    when 8 ; return false if self.y < Jump::Distance

    end

    unless Jump::Counter_Pass == true

      0.upto(Jump::Distance) do |i|

        case move_direction

        when 1 ; return false if $game_map.counter?(self.x-i, self.y+i)

        when 3 ; return false if $game_map.counter?(self.x+i, self.y+i)

        when 7 ; return false if $game_map.counter?(self.x-i, self.y-i)

        when 9 ; return false if $game_map.counter?(self.x+i, self.y-i)

        end

        case @direction

        when 2 ; return false if $game_map.counter?(self.x, self.y+i)

        when 4 ; return false if $game_map.counter?(self.x-i, self.y)

        when 6 ; return false if $game_map.counter?(self.x+i, self.y)

        when 8 ; return false if $game_map.counter?(self.x, self.y-i)

        end

      end

    end

    return true

  end

  #-----------------------------------------------------------------------------

  # * Jump Dist

  #-----------------------------------------------------------------------------

  def jump_dist

    spaces = Array.new

    (Jump::Distance).downto(0) do |i|

      if SDK.enabled?('Player.Run') && Object.const_defined?(:Run)

        i += Jump.run_modifier if $game_player.running?

      end

      i -= 1 if attempt_diagonal? || moving_diagonal?

      j = i + 1

      case move_direction

      when 1 ; spaces.push(j) if passable?(self.x-i, self.y+i, 0)

      when 3 ; spaces.push(j) if passable?(self.x+i, self.y+i, 0)

      when 7 ; spaces.push(j) if passable?(self.x-i, self.y-i, 0)

      when 9 ; spaces.push(j) if passable?(self.x+i, self.y-i, 0)

      end

      case @direction

      when 2 ; spaces.push(j) if passable?(self.x,   self.y+i, @direction)

      when 4 ; spaces.push(j) if passable?(self.x-i, self.y,   @direction)

      when 6 ; spaces.push(j) if passable?(self.x+i, self.y,   @direction)

      when 8 ; spaces.push(j) if passable?(self.x,   self.y-i, @direction)

      end

    end

    return spaces.empty? ? 0 : spaces.first

  end

end

Basically, with this system I made it check for the farthest passable tile (within jump range), and jump to it. It supports diagonal jumping as well, if you happen to have an 8 Directional Movement script it might work, you can tell me if you need a patch for it to work with somebody else's 8 Dir movement script. If you jump diagonally, it'll minus one point for the [jump distance] to make up for the extra tile gained from jumping diagonal vs jumping standard.

Both systems are rather old and haven't been updated in a long ass time, but effective for easy running and jumping. There is a bug in the jump system I shouldn't forget to tell you about; if you try to jump in certain spaces surrounded by impassible tiles, you might not be able to jump in it... this is a small bug I haven't figured out how to fix.

Another thing to note is jumping passability is different than normal passability

  • Normal passability is changed; you can't walk/jump on a blank tile (all 3 layers using the 1/1 tile, ie the 'blank' tile of the tileset). Those tiles are automatically considered non-passable, so you can't in example jump into your panorama.
  • Tiles you can't jump over are notified by marking the Counter tag in the Tileset tab of your database. IE, you don't want the player jumping through a gate, mark it with a counter tag.
  • I didn't put anything special in the script for it to recongize not to jump over certain events, so all events are considered passable.

Lastly, I do try to support all my released scripts the best I can, this script I'll answer general questions about but please, if you need something changed in actual coding, post it in Script Support. I'm revamping my entire "Test Bed", which I plan on re-writting this script entirely, so I'm not gonna be able to help with this version much anymore.
 
I really think that post should be edited or deleted...there is no need for that many smilies in one post. Please edit that post...Just ask your question without all of those there.

And I am assuming that you are new here...so, an event is what you can use to make the game do different things. They are kind of like scripts, but easier for the non-scripters, and does not allow as much as scripts can for people. Why don't you search the forum for this script first rather than asking for it to be made; I know that this script is out there because I even made one...

EDIT: Anyways, I don't know why you couldn't just do this...*Points to the search button at the top*

Look what I found!
http://rmxp.org/forums/viewtopic.php?f=11&t=65568&hilit=Jumping
 
RadethDart":p3e4kgtk said:
I really think that post should be edited or deleted...there is no need for that many smilies in one post. Please edit that post...Just ask your question without all of those there.

And I am assuming that you are new here...so, an event is what you can use to make the game do different things. They are kind of like scripts, but easier for the non-scripters, and does not allow as much as scripts can for people. Why don't you search the forum for this script first rather than asking for it to be made; I know that this script is out there because I even made one...

EDIT: Anyways, I don't know why you couldn't just do this...*Points to the search button at the top*

Look what I found!
http://rmxp.org/forums/viewtopic.php?f=11&t=65568&hilit=Jumping


I Did But nout Came Up
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top