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.

My First Script - Jump on Command

This is my first script... I know its probably been done before but here it is...

Insert this into Game_Player
Code:
if Input.trigger?(Input::ALT)
     keyjump
end
Directly after this
Code:
unless moving? or $game_system.map_interpreter.running? or
       @move_route_forcing or $game_temp.message_window_showing
  # Move player in the direction the directional button is being pressed
  case Input.dir4
  when 2
    move_down
  when 4
    move_left
  when 6
    move_right
  when 8
    move_up
  end

Next insert this
Code:
#--------------------------------------------------------------------------
  # * Jump
  #--------------------------------------------------------------------------
  def keyjump
      # If passable
      case @direction
      when 2
        if jumpable?(@x, @y, @direction)
          @y += 2
          jump(0, 0)
        end
      when 4
        if jumpable?(@x, @y, @direction)
          @x -= 2
          jump(0, 0)
        end
      when 6
        if jumpable?(@x, @y, @direction)
          @x += 2
          jump(0, 0)
        end
      when 8
        if jumpable?(@x, @y, @direction)
          @y -= 2
          jump(0, 0)
        end
      end
    end
and this
Code:
#--------------------------------------------------------------------------
  # * Determine if Jump Passable
  #     x : x-coordinate
  #     y : y-coordinate
  #     d : direction (0,2,4,6,8)
  #         * 0 = Determines if all directions are impassable (for jumping)
  #--------------------------------------------------------------------------
  def jumpable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 2 : d == 4 ? -2 : 0)
    new_y = y + (d == 2 ? 2 : d == 8 ? -2 : 0)
    # If coordinates are outside of map
    unless $game_map.valid?(new_x, new_y)
      # impassable
      return false
    end
    # If through is ON
    if @through
      # passable
      return true
    end
    # If unable to leave first move tile in designated direction
    unless $game_map.passable?(x, y, d, self)
      # impassable
      return false
    end
    # If unable to enter move tile in designated direction
    unless $game_map.passable?(new_x, new_y, 10 - d)
      # impassable
      return false
    end
    # Loop all events
    for event in $game_map.events.values
      # If event coordinates are consistent with move destination
      if event.x == new_x and event.y == new_y
        # If through is OFF
        unless event.through
          # If self is event
          if self != $game_player
            # impassable
            return false
          end
          # With self as the player and partner graphic as character
          if event.character_name != ""
            # impassable
            return false
          end
        end
      end
    end
    # If player coordinates are consistent with move destination
    if $game_player.x == new_x and $game_player.y == new_y
      # If through is OFF
      unless $game_player.through
        # If your own graphic is the character
        if @character_name != ""
          # impassable
          return false
        end
      end
    end
    # passable
    return true
  end
under Move_Up in Game_Character3
Then Enjoy!
Please report any bugs!

Demo - http://www.megaupload.com/?d=3BTT1VUG
Includes multiple objects to jump...

-Edit-
Here are some screens...
http://img108.imageshack.us/img108/8940/beforekeyrs4.th.png[/IMG]
Before Alt is pressed

http://img99.imageshack.us/img99/2338/midairbt0.th.png[/IMG]
In Midair

http://img99.imageshack.us/img99/7008/landingrp6.th.png[/IMG]
After Landing
 

Anonymous

Guest

Mmm... Terribly sorry, but this is easily done with common events. What would make this worth it, though, is if you made cretain tiles unjumpable, or if you can't jump two tiles, jump one tile. :) Sorry if I seem offensive, I really just want to help, and I hope I did. And, I mean, it's great for your first script - mine was one that outlines text :P
 
I agree with you there smartguy. But a good idea to make it seem more better in my opinion, would be to like hmmmmm how should I say this. OK probably in certain areas having to jump is te only option. Or you could try to make it like the reaction commands in KH2. Hope that gives you a better idea for your next script = ).
 
Hey, is there any chance that you could make it into one whole script, I tryed myself but was unable to do as im only a rookie! Thanks :D
 

Vash

Member

The above jump command in one cut and paste above main script, for anyone who still wants it:
Code:
#==============================================================================
# ** Jump Command
#==============================================================================

class Game_Player < Game_Character
  alias vash_jump_update update
  def update
   vash_jump_update
     if Input.trigger?(Input::ALT)
     keyjump
    end
  end
end

class Game_Character
#--------------------------------------------------------------------------
# * Jump
#--------------------------------------------------------------------------
  def keyjump
      # If passable
      case @direction
      when 2
        if jumpable?(@x, @y, @direction)
          @y += 2
          jump(0, 0)
        end
      when 4
        if jumpable?(@x, @y, @direction)
          @x -= 2
          jump(0, 0)
        end
      when 6
        if jumpable?(@x, @y, @direction)
          @x += 2
          jump(0, 0)
        end
      when 8
        if jumpable?(@x, @y, @direction)
          @y -= 2
          jump(0, 0)
        end
      end
    end
    
#--------------------------------------------------------------------------
# * Determine if Jump Passable
#     x : x-coordinate
#     y : y-coordinate
#     d : direction (0,2,4,6,8)
#         * 0 = Determines if all directions are impassable (for jumping)
#--------------------------------------------------------------------------
  def jumpable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 2 : d == 4 ? -2 : 0)
    new_y = y + (d == 2 ? 2 : d == 8 ? -2 : 0)
    # If coordinates are outside of map
    unless $game_map.valid?(new_x, new_y)
      # impassable
      return false
    end
    # If through is ON
    if @through
      # passable
      return true
    end
    # If unable to leave first move tile in designated direction
    unless $game_map.passable?(x, y, d, self)
      # impassable
      return false
    end
    # If unable to enter move tile in designated direction
    unless $game_map.passable?(new_x, new_y, 10 - d)
      # impassable
      return false
    end
    # Loop all events
    for event in $game_map.events.values
      # If event coordinates are consistent with move destination
      if event.x == new_x and event.y == new_y
        # If through is OFF
        unless event.through
          # If self is event
          if self != $game_player
            # impassable
            return false
          end
          # With self as the player and partner graphic as character
          if event.character_name != ""
            # impassable
            return false
          end
        end
      end
    end
    # If player coordinates are consistent with move destination
    if $game_player.x == new_x and $game_player.y == new_y
      # If through is OFF
      unless $game_player.through
        # If your own graphic is the character
        if @character_name != ""
          # impassable
          return false
        end
      end
    end
    # passable
    return true
  end
end
 
Hey, could you add a couple of features:

1. Not able to jump over an event that has a comment saying "\NotJump" eg
2. Not able to jump over a tile that has a tile id of 1
3. Ive there is 1 tile in front of you, you can jump one tile rather than not jumping at all!

Thanks :D
 

Tensa

Member

I remember that before my compute crashed (and you guys apparently lost your old domain,) there was an advanced jumping script let you set the jump length and would automatically adjust that distance if the tile you would have landed on was impassable.
It also had the 'nojump' thing trebor just mentioned and some fancy conditions to decide if the player had the jump ability or not (the only one I remember was that you could have them equip an item to enable it.)

It would be really nice to have that again ;_;
 

Tensa

Member

Well, I think it's more of a bad explanation of what it's supposed to do. As it stands you can jump anywhere that has appropriate passability and over impassible spots if the length is right which is pretty much what it ought to do.
Ptting a bunch of /tall commented events where you don't want them jumping doesn't seem like too big of a hassle.
 
Alright, the only problem i found with this is that, if you hold down your jump key, you can walk over anything.
Kind of a big problem >_>
 

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