Help - Search - Members - Calendar
Full Version: A jumping script
RPG RPG Revolution Forums > Scripting > Script Tutorials > RGSS2
Guy2610
Hi everyone! I haven't been here in a while cause my computer is a piece of crap and extremely slow but i'm gonna start posting more. Well anyway, i have this jumping script that is pretty cool. It allows you to set how far you want your hero to jump and what he can jump over. It was made by Huitzilopoctli at rmxp.net but seeing as how the site is gone i thought i would post this because i don't think anyone else has it. well here it is. Insert above main and enjoy. :Smilie6: Oh to get it to work right go into the database to the tileset section and mark anything you want the hero to be able jump over with the terrain tag 1. :Thumbsup1:

Demo at the bottom.

CODE
#==============================================================================
# ■ WallJump Script
#------------------------------------------------------------------------------
# Enables jumping around the map
# Made by: Huitzilopoctli of rmxp.net as part of Interactive World
#------------------------------------------------------------------------------
# Press the A Input (ShiftKey) to jump
# The player will be able to jump over any passable tile, or any tile with a
# TerrainID the same as the JumpID
# The player must land on a passable tile without a solid event blocking it
# If the player can't jump the full 2 tiles, it will go 1 or, failing that, none
# To stop the player from jumping over a particular event, make the first
# command for the event a comment, containing this word: \Tall
# To create a 'tall' tile that will stop the player from jumping over it even if
# the tile below is jumpable, set the tile's id to not the JumpID or 0
# To lock the player's facing while moving, hold down CTRL
#==============================================================================

#==============================================================================
# ● Customisation
#==============================================================================

JumpID = 1 # The terrain ID of the tiles which can be jumped over
MaxJump = 2 # The longest jump that can be made by the player

#==============================================================================
# ● Game_Player
#==============================================================================

class Game_Player < Game_Character

# forces Game_Character's passable method to be used, so CTRL no longer makes
# the hero able to walk through walls
def passable?(x, y, d)
super(x, y, d)
end

def leap
# finds the increases to x & y for the current direction
xdir = (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
ydir = (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

# Ow!
unless $game_map.terrain_tag(@x + xdir, @y + ydir) == JumpID or
$game_map.passable?(@x + xdir, @y + ydir, @direction, self)
# make the player jump
route = RPG::MoveRoute.new
route.list.clear
route.list.push(RPG::MoveCommand.new(37))
route.list.push(RPG::MoveCommand.new(14, [0, 0]))
route.list.push(RPG::MoveCommand.new(38))
route.list.push(RPG::MoveCommand.new(0))
route.repeat = false
$game_player.force_move_route(route)

# shake the screen
$game_screen.start_shake(7, 7, 5)

# display an "Ouch!" message
$game_temp.message_text = "Ouch!"
return
end

# finds the jumpable distance
dist = jumpable_distance

# wall jump
if dist.between?(1, MaxJump - 1) and
!$game_map.passable?(@x + (dist + 1) * xdir, @y + (dist + 1) * ydir, @direction, self) and
!($game_map.terrain_tag(@x + (dist + 1) * xdir, @y + (dist + 1) * ydir) == JumpID)
# finds the reverse direction
bounce_dir = @direction == 2 ? 8 : (@direction == 4 ? 6 : (@direction == 6 ? 4 : 2))

# finds the wall-jump distance
b_dist = jumpable_distance(bounce_dir, MaxJump + 2, @x + dist * xdir, @y + dist * ydir)

# finds the additions to x and y made by the reverse direction
b_xdir = (bounce_dir == 6 ? 1 : bounce_dir == 4 ? -1 : 0)
b_ydir = (bounce_dir == 2 ? 1 : bounce_dir == 8 ? -1 : 0)

# create the move_route
route = RPG::MoveRoute.new
route.list.clear
route.list.push(RPG::MoveCommand.new(37))
# add the normal jump
route.list.push(RPG::MoveCommand.new(14, [xdir * dist, ydir * dist]))
# add the wall jump
route.list.push(RPG::MoveCommand.new(14, [b_xdir * b_dist, b_ydir * b_dist]))
route.list.push(RPG::MoveCommand.new(38))
route.list.push(RPG::MoveCommand.new(0))
route.repeat = false

$game_player.force_move_route(route)

return
end

# creates a route for a normal jump and forces the player to follow it
route = RPG::MoveRoute.new
route.list.clear
route.list.push(RPG::MoveCommand.new(37))
route.list.push(RPG::MoveCommand.new(14, [xdir * dist, ydir * dist]))
route.list.push(RPG::MoveCommand.new(38))
route.list.push(RPG::MoveCommand.new(0))
route.repeat = false

$game_player.force_move_route(route)
end

alias update_primary update
def update
# calls the normal update method
update_primary

# locks the facing if CTRL is pressed, else unlocks it
@direction_fix = Input.press?(Input::CTRL)

# leaps if Input::A is triggered
leap if Input.trigger?(Input::A) && !moving?
end

def jumpable_distance(dir = @direction, max_dist = MaxJump, x = @x, y = @y)
xdir = (dir == 6 ? 1 : dir == 4 ? -1 : 0)
ydir = (dir == 2 ? 1 : dir == 8 ? -1 : 0)

jumpable_tiles = []

for i in 0..max_dist
check_x = x + i * xdir
check_y = y + i * ydir

e = $game_map.events[$game_map.check_event(check_x, check_y)]
if e
if e.list[0].parameters[0] =~ "\Tall"
break
end
if not e.through
next
end
end

if $game_map.passable?(check_x, check_y, dir, self) or
$game_map.terrain_tag(check_x, check_y) == JumpID
jumpable_tiles.push(i)
end
end

jumpable_tiles.reverse.each do |i|
check_x = x + i * xdir
check_y = y + i * ydir

return i if $game_map.passable?(check_x, check_y, dir, self)
end

return 0
end

end


DEMO :Smilie6:
CERU
Jumping down doesn't work ..
Guy2610
What do you mean? Jumping in all directions worked for me. Did you make sure to go in the database and give all the jumpable tiles the terrain tag it says in the script?
Master WGS
Is there any way to disable the "Ouch!" message that pops up?
Night_Runner
About a third of the way in to the script, you'll find the line
CODE
$game_temp.message_text = "Ouch!"

(You can just Ctrl + F for in in the script editor), if you put a # at the start of that line then it will stop showing the message smile.gif
carnie_natas
QUOTE (Night_Runner @ Jul 23 2011, 06:21 AM) *
About a third of the way in to the script, you'll find the line
CODE
$game_temp.message_text = "Ouch!"

(You can just Ctrl + F for in in the script editor), if you put a # at the start of that line then it will stop showing the message smile.gif

Hey night runner figured you'd know, what would i use in the script part of eventing to call this script for say a minigame or just one specific map as well as disable the script when i want.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.