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.

Adjusting a jump script

Hello all,

Below is a sample code of a jumping script.

It works great however I just want to be able to change one little thing...

If a player can Jump the distance (In my example 6 tiles) but can do it 4 or 3 because that's where the closes landing point is, then I'd like my character to be able to do that, instead of jumping the full 6 squares. Or if it can't jump 6 but can jump 4 it can still jump.

I've looked though a number of Jumping Scripts and did a pretty wide google search and found nothing...

Any support would mean the world to me

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

# Simple Jump System by Nathmatt

# Version: 1.03

# Type: Custom Movement System

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#   

#  This work is protected by the following license:

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

# #  

# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported

# #  ( [url=http://creativecommons.org/licenses/by-nc-sa/3.0/]http://creativecommons.org/licenses/by-nc-sa/3.0/[/url] )

# #  

# #  You are free:

# #  

# #  to Share - to copy, distribute and transmit the work

# #  to Remix - to adapt the work

# #  

# #  Under the following conditions:

# #  

# #  Attribution. You must attribute the work in the manner specified by the

# #  author or licensor (but not in any way that suggests that they endorse you

# #  or your use of the work).

# #  

# #  Noncommercial. You may not use this work for commercial purposes.

# #  

# #  Share alike. If you alter, transform, or build upon this work, you may

# #  distribute the resulting work only under the same or similar license to

# #  this one.

# #  

# #  - For any reuse or distribution, you must make clear to others the license

# # terms of this work. The best way to do this is with a link to this web

# # page.

# #  

# #  - Any of the above conditions can be waived if you get permission from the

# # copyright holder.

# #  

# #  - Nothing in this license impairs or restricts the author's moral rights.

# #  

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

# 

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#

# This is the config: 

#

#   (Jump_Distance) is how far you want to jump.

#   

#   (Cant_Jump) is the terrain tag that you cant jump on.

#

#   (Off_Switch_id) is the swith id used to turn off the jump.

#

#   (Jump_key) is the key used to jump if using tons ads custom controls.

#

#   (Jump_Animation) is if you want a speacial graphic for jumping

#   add _jmp  so 001-Fighter01 would be 001-Fighter01_jmp.

#  

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

module Nathmatt_Config

   Jump_Distance = 2

   Jump_Animation = false

   Off_Switch_id = 50

   Jump_Key = 'Space'

    # Terrain_Tags

    Cant_Jump = 1

end

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#

# This is the update method: 

#

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

  

class  Game_Player < Game_Character

  

    

  alias nathmatt_update update

  def update 

    nathmatt_update

    actor = $game_party.actors[0] unless actor == $game_party.actors[0]

    if $tons_version != nil && $tons_version >= 5.40 && 

      TONS_OF_ADDONS::CUSTOM_CONTROLS

      if Input.trigger?(Input::Key[Nathmatt_Config::Jump_Key]) 

        unless jumping? || 

          $game_switches [Nathmatt_Config::Off_Switch_id]

          c =  Nathmatt_Config::Cant_Jump

          d =  Nathmatt_Config::Jump_Distance

          case direction

            when 2 then jump(0,d) unless check_terrain(0,d,c)

            when 4 then jump(-d,0) unless check_terrain(-d,0,c)

            when 6 then jump(d,0) unless check_terrain(d,0,c)

            when 8 then jump(0,-d) unless check_terrain(0,-d,c)

          end

        end

      end

    else

       if Input.trigger?(Input::A)  

        unless jumping? || 

          $game_switches [Nathmatt_Config::Off_Switch_id]

          c =  Nathmatt_Config::Cant_Jump

          d =  Nathmatt_Config::Jump_Distance

          case direction

            when 2 then jump(0,d) unless check_terrain(0,d,c)

            when 4 then jump(-d,0) unless check_terrain(-d,0,c)

            when 6 then jump(d,0) unless check_terrain(d,0,c)

            when 8 then jump(0,-d) unless check_terrain(0,-d,c)

          end

        end

      end

    end

    if jumping? && Nathmatt_Config::Jump_Animation

       @character_name_org = actor.character_name

       @character_name = @character_name_org+'_jmp'

    end

    if @character_name != actor.character_name

       @character_name = actor.character_name unless jumping?

     end

  end

  

  def check_terrain(x,y,condition)

    px = $game_player.x + x

    py = $game_player.y + y

    if $game_map.terrain_tag(px,py) == condition

      return true

    else

      return false

    end

  end

 

end
 
Ruby:
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

# Simple Jump System by Nathmatt

# Version: 1.03

# Type: Custom Movement System

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#  

#  This work is protected by the following license:

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

# #  

# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported

# #  ( [url=http://creativecommons.org/licenses/by-nc-sa/3.0/]http://creativecommons.org/licenses/by-nc-sa/3.0/[/url] )

# #  

# #  You are free:

# #  

# #  to Share - to copy, distribute and transmit the work

# #  to Remix - to adapt the work

# #  

# #  Under the following conditions:

# #  

# #  Attribution. You must attribute the work in the manner specified by the

# #  author or licensor (but not in any way that suggests that they endorse you

# #  or your use of the work).

# #  

# #  Noncommercial. You may not use this work for commercial purposes.

# #  

# #  Share alike. If you alter, transform, or build upon this work, you may

# #  distribute the resulting work only under the same or similar license to

# #  this one.

# #  

# #  - For any reuse or distribution, you must make clear to others the license

# # terms of this work. The best way to do this is with a link to this web

# # page.

# #  

# #  - Any of the above conditions can be waived if you get permission from the

# # copyright holder.

# #  

# #  - Nothing in this license impairs or restricts the author's moral rights.

# #  

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

#

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#

# This is the config:

#

#   (Jump_Distance) is how far you want to jump.

#   

#   (Cant_Jump) is the terrain tag that you cant jump on.

#

#   (Off_Switch_id) is the swith id used to turn off the jump.

#

#   (Jump_key) is the key used to jump if using tons ads custom controls.

#

#   (Jump_Animation) is if you want a speacial graphic for jumping

#   add _jmp  so 001-Fighter01 would be 001-Fighter01_jmp.

#  

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

module Nathmatt_Config

   Jump_Distance = 4

   Jump_Animation = false

   Off_Switch_id = 50

   Jump_Key = 'Space'

    # Terrain_Tags

    Cant_Jump = 1

end

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#

# This is the update method:

#

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

 

class  Game_Player < Game_Character

 

  alias nathmatt_update update

  def update

    nathmatt_update

    actor = $game_party.actors[0] unless actor == $game_party.actors[0]

    if $tons_version != nil && $tons_version >= 5.40 &&

      TONS_OF_ADDONS::CUSTOM_CONTROLS

      if Input.trigger?(Input::Key[Nathmatt_Config::Jump_Key])

        unless jumping? ||

          $game_switches [Nathmatt_Config::Off_Switch_id]

          c =  Nathmatt_Config::Cant_Jump

          d =  Nathmatt_Config::Jump_Distance

          case direction

            when 2 then jump(0,d) unless check_terrain(0,d,c)

            when 4 then jump(-d,0) unless check_terrain(-d,0,c)

            when 6 then jump(d,0) unless check_terrain(d,0,c)

            when 8 then jump(0,-d) unless check_terrain(0,-d,c)

          end

        end

      end

    else

       if Input.trigger?(Input::A)  

        unless jumping? ||

          $game_switches [Nathmatt_Config::Off_Switch_id]

          c =  Nathmatt_Config::Cant_Jump

          d =  Nathmatt_Config::Jump_Distance

          case direction

            when 2 then jump_script(0,d) unless check_terrain(0,d,c)

            when 4 then jump_script(-d,0) unless check_terrain(-d,0,c)

            when 6 then jump_script(d,0) unless check_terrain(d,0,c)

            when 8 then jump_script(0,-d) unless check_terrain(0,-d,c)

          end

        end

      end

    end

    if jumping? && Nathmatt_Config::Jump_Animation

       @character_name_org = actor.character_name

       @character_name = @character_name_org+'_jmp'

    end

    if @character_name != actor.character_name

       @character_name = actor.character_name unless jumping?

     end

   end

   

  def jump_script(x_distance, y_distance)

    loop do

      break if x_distance == 0 and y_distance == 0

      break if passable?(self.x + x_distance, self.y + y_distance, 0)

      x_distance -= 1 if x_distance > 0

      x_distance += 1 if x_distance < 0

      y_distance -= 1 if y_distance > 0

      y_distance += 1 if y_distance < 0

    end

    jump(x_distance, y_distance)

  end

 

  def check_terrain(x,y,condition)

    px = $game_player.x + x

    py = $game_player.y + y

    if $game_map.terrain_tag(px,py) == condition

      return true

    else

      return false

    end

  end

 

end
 
Thanks for trying,

I updated my script, however the character still jumps 6 tiles in a jump that could be done in at least 3 tiles. Basically I don't want my character jumping any further than he needs to.
 
What I want is if a player needs to jump 4 Tiles
and the Jump_Distance = 8
Instead of jumping all 8 Tiles
He should only Jump 4 because that's where the closest land place is.

Basically what I want to do is check the passiblity of each of the 8 tiles in front of character on all 3 layers and if there is an event there. Then I want the character to jump to the closest option. In example...

---Example 1----
(start) x x x o o x o o (max jump length*) *8 tiles

*x = can't pass *o = passable ground. (*each represent a tile)

If the Example 1 The player is jumping to the right, because the 4th tile is available to land on then the player should land there instead of the 8th tile because that's the max jump length.

The only time a player should jump 8 tiles is when a situation like this comes up as shown in Example 2.
---Example 2----
(start) x x x x x x x o (finish)

If also possible can it be defined within that code that the minimum jump length is 2 tiles?

I hope my explanation above helps.
 
Ruby:
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

# Simple Jump System by Nathmatt

# Version: 1.03

# Type: Custom Movement System

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#  

#  This work is protected by the following license:

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

# #  

# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported

# #  ( [url=http://creativecommons.org/licenses/by-nc-sa/3.0/]http://creativecommons.org/licenses/by-nc-sa/3.0/[/url] )

# #  

# #  You are free:

# #  

# #  to Share - to copy, distribute and transmit the work

# #  to Remix - to adapt the work

# #  

# #  Under the following conditions:

# #  

# #  Attribution. You must attribute the work in the manner specified by the

# #  author or licensor (but not in any way that suggests that they endorse you

# #  or your use of the work).

# #  

# #  Noncommercial. You may not use this work for commercial purposes.

# #  

# #  Share alike. If you alter, transform, or build upon this work, you may

# #  distribute the resulting work only under the same or similar license to

# #  this one.

# #  

# #  - For any reuse or distribution, you must make clear to others the license

# # terms of this work. The best way to do this is with a link to this web

# # page.

# #  

# #  - Any of the above conditions can be waived if you get permission from the

# # copyright holder.

# #  

# #  - Nothing in this license impairs or restricts the author's moral rights.

# #  

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

#

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#

# This is the config:

#

#   (Jump_Distance) is how far you want to jump.

#   

#   (Cant_Jump) is the terrain tag that you cant jump on.

#

#   (Off_Switch_id) is the swith id used to turn off the jump.

#

#   (Jump_key) is the key used to jump if using tons ads custom controls.

#

#   (Jump_Animation) is if you want a speacial graphic for jumping

#   add _jmp  so 001-Fighter01 would be 001-Fighter01_jmp.

#  

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

module Nathmatt_Config

   Jump_Distance = 4

   Jump_Animation = false

   Off_Switch_id = 50

   Jump_Key = 'Space'

    # Terrain_Tags

    Cant_Jump = 1

end

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#

# This is the update method:

#

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

 

class  Game_Player < Game_Character

 

  alias nathmatt_update update

  def update

    nathmatt_update

    actor = $game_party.actors[0] unless actor == $game_party.actors[0]

    if $tons_version != nil && $tons_version >= 5.40 &&

      TONS_OF_ADDONS::CUSTOM_CONTROLS

      if Input.trigger?(Input::Key[Nathmatt_Config::Jump_Key])

        unless jumping? ||

          $game_switches [Nathmatt_Config::Off_Switch_id]

          c =  Nathmatt_Config::Cant_Jump

          d =  Nathmatt_Config::Jump_Distance

          case direction

            when 2 then jump(0,d) unless check_terrain(0,d,c)

            when 4 then jump(-d,0) unless check_terrain(-d,0,c)

            when 6 then jump(d,0) unless check_terrain(d,0,c)

            when 8 then jump(0,-d) unless check_terrain(0,-d,c)

          end

        end

      end

    else

       if Input.trigger?(Input::A)  

        unless jumping? ||

          $game_switches [Nathmatt_Config::Off_Switch_id]

          c =  Nathmatt_Config::Cant_Jump

          d =  Nathmatt_Config::Jump_Distance

          case direction

            when 2 then jump_script(0,d) unless check_terrain(0,d,c)

            when 4 then jump_script(-d,0) unless check_terrain(-d,0,c)

            when 6 then jump_script(d,0) unless check_terrain(d,0,c)

            when 8 then jump_script(0,-d) unless check_terrain(0,-d,c)

          end

        end

      end

    end

    if jumping? && Nathmatt_Config::Jump_Animation

       @character_name_org = actor.character_name

       @character_name = @character_name_org+'_jmp'

    end

    if @character_name != actor.character_name

       @character_name = actor.character_name unless jumping?

     end

   end

   

  def jump_script(max_x_distance, max_y_distance)

    x_distance, y_distance = 0, 0

    loop do

      break if x_distance == max_x_distance and y_distance == max_y_distance

      break if passable?(self.x + x_distance, self.y + y_distance, 0)

      x_distance += 1 if max_x_distance > 0

      x_distance -= 1 if max_x_distance < 0

      y_distance += 1 if max_y_distance > 0

      y_distance -= 1 if max_y_distance < 0

    end

    return if !passable?(self.x + x_distance, self.y + y_distance, 0)

    jump(x_distance, y_distance)

  end

 

  def check_terrain(x,y,condition)

    px = $game_player.x + x

    py = $game_player.y + y

    if $game_map.terrain_tag(px,py) == condition

      return true

    else

      return false

    end

  end

 

end
 

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