Help - Search - Members - Calendar
Full Version: Elevtion passability
RPG RPG Revolution Forums > Scripting > Script Tutorials > RGSS2
breadlord
This script solves the problem of how to stop the player stepping from one tile to the next when you've mapped them to look like there a few tiles away hieght wise. Instuctions in the script and if you need help with something just ask.

[Show/Hide] Screenies

Now these arn't very clear but..


Oh no, he cant miracously jump between things at differnt hieghts, what will he do..


Use the stairs



Demo : http://www.mediafire.com/?sharekey=ac3e536...e018c8114394287

CODE

###################### Breadlords Elavation Passability ########################
## This script solves the problem of how to stop the player stepping from one ##
## tile to the next when you've mapped them to look like there a few tiles ##
## away hieght wise. To set up the different areas of 'elevation', while ##
## making the map in the editor, make an area named level:?, where ? is the ##
## elevation level you want it to have, and have the area cover the parts you ##
## want to be 'elevated'. You can have as many areas as you want with what - ##
## ever level of 'elavation' you want. Note : You can only have POSITIVE ##
## levels of elavation. Note : All parts of the map not in an area with level ##
## :whatever are counted as having a level of 0. To make a player be able to ##
## cross from 1 elavation level to an other use $game_player.level = whatever ##
## were whatever is whatever elavation level you want the player to go on, ##
## this must be put in an event directly before the place were the eleavation ##
## is what you've just set the player to go on, so say if |1| is an area with ##
## level 1 elavation and |2| is an area with level 2 elavation and |E| is an ##
## event with the command $game_player.level = 2 you would put the event like ##
## this : |1||E||2|. To set an events elavation level use $game_map.events[id]##
## .level = whatever, were id is the events id and whatever is the elavation ##
## you want it to have. ##
################################################################################

##### DO NOT EDIT # DO NOT EDIT # DO NOT EDIT # DO NOT EDIT # DO NOT EDIT #####

class Game_Character
alias init initialize
attr_accessor :level

def initialize
init
@level = 0
end

def in_area?(area)
return false if @area == nil
return false if $game_map.map_id != area.map_id
return false if @x < area.rect.x
return false if @y < area.rect.y
return false if @x >= area.rect.x + area.rect.width
return false if @y >= area.rect.y + area.rect.height
@area = area
return true
end

def in_areaxy?(area,x,y)
return false if area == nil
return false if $game_map.map_id != area.map_id
return false if x < area.rect.x
return false if y < area.rect.y
return false if x >= area.rect.x + area.rect.width
return false if y >= area.rect.y + area.rect.height
return true
end

def map_passable?(x, y)
a = nil
b = nil
for area in $data_areas.values
if in_area?(area)
c = area.name
c.split(/[\r\n]+/).each do |line|
if line.split(/[:]/)[0] == 'level'
data = line.split(/[:]/)[1]
a = data.to_i
end
end
end
if in_areaxy?(area,x,y)
c = area.name
c.split(/[\r\n]+/).each do |line|
if line.split(/[:]/)[0] == 'level'
data = line.split(/[:]/)[1]
b = data.to_i
end
end
end
end
if a != nil and b != nil
if @level != b and a != b
return false
end
@level = b
elsif a == nil and b != nil
if @level == 0
return false
end
@level = 0
elsif b == nil and a != nil
if @level != 0
return false
end
@level = 0
else
@level = 0
end
return $game_map.passable?(x, y)
end

end

class Game_Player
attr_accessor :level

def in_area?(area)
return false if area == nil
return false if $game_map.map_id != area.map_id
return false if @x < area.rect.x
return false if @y < area.rect.y
return false if @x >= area.rect.x + area.rect.width
return false if @y >= area.rect.y + area.rect.height
@area = area
return true
end

def map_passable?(x, y)
case @vehicle_type
when 0 # Boat
return $game_map.boat_passable?(x, y)
when 1 # Ship
return $game_map.ship_passable?(x, y)
when 2 # Airship
return true
else # Walking
a = nil
b = nil
for area in $data_areas.values
if in_area?(area)
c = area.name
c.split(/[\r\n]+/).each do |line|
if line.split(/[:]/)[0] == 'level'
data = line.split(/[:]/)[1]
a = data.to_i
end
end
end
if in_areaxy?(area,x,y)
c = area.name
c.split(/[\r\n]+/).each do |line|
if line.split(/[:]/)[0] == 'level'
data = line.split(/[:]/)[1]
b = data.to_i
end
end
end
end
if a != nil and b != nil
if @level != b and a != b
return false
end
@level = b
elsif a == nil and b != nil
if @level == 0
return false
end
@level = 0
elsif b == nil and a != nil
if @level != 0
return false
end
@level = 0
else
@level = 0
end
return $game_map.passable?(x, y)
end
end

end
Twilight
Probably useful for some people but you can hold shift down in the editor to accomplish the same effect. It might mess with the engine when your trying to make a wall on the same level as well
Also not much of an issue but the tile you used to walk on is the wrong one.

Edit:
I was able to do this in a few minutes, a little time consuming but more or less the same thing you did with the script
Octople Threat
QUOTE (Twilight @ Jun 28 2009, 11:25 AM) *
Probably useful for some people but you can hold shift down in the editor to accomplish the same effect. It might mess with the engine when your trying to make a wall on the same level as well
Also not much of an issue but the tile you used to walk on is the wrong one.

Edit:
I was able to do this in a few minutes, a little time consuming but more or less the same thing you did with the script


Yeah that doesn't work... Unless you left a step out, that is.

Anyways, Breadlord, see if you can't work together with Onidsouza to incorporate this into his jump system... as it is, you can jump over walls and that's not good...
Twilight
Nothing left out, you just have to plan ahead, particularly for the areas that appear elevated.
You have to leave it blank, else VX will not recognize you holding down shift.
deffenex
This is my dream script, I had even requested it, thanks breadlord!!!!
breadlord
Octuple - For the jump system, don't use CTRL and put this script below.

Twilight - I think your missundertanding what this script does, It doesn't make itlook like that, it
makes it so the player, lets say on the example map, can't walk from the top of one on
to the other one like there was no hieght difference.

Deffenex - Lucky you biggrin.gif



Octople Threat
Using control isn't the problem... At least I don't think... What I mean is when you're in a house, you can jump over the walls if they're one less tile than your jump length... It would be fantastic if you could make it so any height more than two elevations up was unjumpable... sorry if that didn't make much sense... I'll try and clarify if you don't understand...
breadlord
Yea, I'll try that. I thought you ment that the jump script was messing up the passability. Wich can happen when using control.

Edit : Got the jump script working with this, the player can jump between things with 1 level difference. To do this replace the jump script with
this edited one :
CODE
#==================================================
# ** Onidsouza Jump System
#--------------------------------------------------
# Autor // Author : Onidsouza
# Data // Date : 17 de Maio de 2009 // 5/17/2009
# Versão // Version : 1.4
#==================================================

module OJS

OnOffSwitch = 1 # Switch que desliga ou liga os pulos
# Switch that turns on and off the jumps

Input = Input::C # Constante do módulo Input. Control é o default
# Input module constant. Control is the default

Sound = true # Tocar som quando não se pode pular
# Play Sound when can't jump

Long = 3 # Distância que o jogador pode pular, em tiles
# How long the player can jump, in tiles.

UseVariable = false # Jump length is controlled by a variable
# Distância do pulo é controlada por uma variavél

VariableID = 1 #Id da Variável
# Variavle ID.

Cooldown = 30 # Tempo de cooldown do pulo, em frames
# Jump cooldown time, in frames

end

class Game_Player

alias ojsinitialize initialize
attr_accessor :jump_cooldown

def height_pass(x,y,direction)
b = height
c = heightxy(x,y)
if b != c
return true
else
return true
end
end

def height
a = 0
for area in $data_areas.values
if in_area?(area)
c = area.name
c.split(/[\r\n]+/).each do |line|
if line.split(/[:]/)[0] == 'level'
data = line.split(/[:]/)[1]
a = data.to_i
end
end
end
return a
end
end

def heightxy(x,y)
a = 0
for area in $data_areas.values
if in_areaxy?(area,x,y)
c = area.name
c.split(/[\r\n]+/).each do |line|
if line.split(/[:]/)[0] == 'level'
data = line.split(/[:]/)[1]
a = data.to_i
end
end
end
return a
end
end

def initialize
ojsinitialize
@jump_cooldown = OJS::Cooldown
end

def jump_direction
direcao = []
if OJS::UseVariable
long = $game_variables[OJS::VariableID]
else
long = OJS::Long
end
case @direction
when 2 # Para Trás / Back
direcao[0] = 0; direcao[1] = 1
when 4 # Esquerda / Left
direcao[0] = -1; direcao[1] = 0
when 6 # Direita / Rigth
direcao[0] = 1; direcao[1] = 0
when 8 # Frente / Up
direcao[0] = 0; direcao[1] = -1
end
direcao[0] = direcao[0] * long; direcao[1] = direcao[1] * long
return direcao
end

def jump_higth_pass?
dire = jump_direction
to_verify = []
case @direction
when 2
to_verify = [@x, @y]
when 4
to_verify = [@x - 1, @y - 1]
when 6
to_verify = [@x + 1, @y - 1]
when 8
to_verify = [@x, @y - 2]
end

id = $game_map.data[to_verify[0], to_verify[1], 2]
pass = $game_map.passages[id]
if pass == 22
return false
end

return true
end

def event_passable?(x, y)
for event in $game_map.events_xy(x, y)
pass = event.page.priority_type
return false if pass == 1
end
return true
end

def jump_foward
if @jump_cooldown == 30
@jump_cooldown = 0
direcao = jump_direction
jump(direcao[0], direcao[1])
end
end

end

class Scene_Map

alias ojsupdate update

def update
ojsupdate
unless $game_message.visible
update_jump_player
end
unless $game_player.jump_cooldown == 30
$game_player.jump_cooldown += 1
end
end

def update_jump_player
player = $game_player
direct = player.jump_direction
x = player.x + direct[0]
y = player.y + direct[1]
if $game_switches[OJS::OnOffSwitch] == true
if player.map_passable?(x, y) && player.jump_higth_pass? && player.event_passable?(x, y) && player.height_pass(x,y,direct)
if Input.trigger?(OJS::Input)
$game_player.jump_foward
$game_party.steps += OJS::Long
end
else
player.level += 1
if player.map_passable?(x, y) && player.jump_higth_pass? && player.event_passable?(x, y) && player.height_pass(x,y,direct)
if Input.trigger?(OJS::Input)
$game_player.jump_foward
$game_party.steps += OJS::Long
end
else
player.level -= 2
if player.map_passable?(x, y) && player.jump_higth_pass? && player.event_passable?(x, y) && player.height_pass(x,y,direct)
if Input.trigger?(OJS::Input)
$game_player.jump_foward
$game_party.steps += OJS::Long
end
elsif Input.trigger?(OJS::Input)
if OJS::Sound == true
Sound.play_buzzer
end
end
end
end
player.level += 1
end
end

end

class Game_Party

attr_accessor :steps

end

class Game_Map

attr_reader :map

end

class Game_Event < Game_Character

attr_reader :event
attr_reader :page

end
Octople Threat
NI-ICE! That is epic! You are really coming along as a scripter, buddy, and I can't wait to see what else you crank out!
breadlord
Thanks biggrin.gif

tofuman
This is great script.. So I tried it and...

It didn't work... and there was no other script when I tested it..

Maybe I did something wrong....

Can you upload a demo please?
breadlord
Demo uploaded.

tofuman
Wow! Thank you! I don't know what was wrong before but now its working perfectly fine!:p
breadlord
Nice to hear happy.gif
tofuman
Um.. sorry to post again... but.

When I used demo, it worked fine...

but when I move it to new project and did exactly same as your demo...

when I stand on the event where change the elevation of the player..

It shows "Syntax Error occured while running script"...

I used only this script so it is not a compatibility problem...

other functions are working perfectly fine...

I just don't get why this happens...
breadlord
If it says that, then that means there was a problem with your event. Please can you post the thing youve put in your event?
tofuman
I can't post it right now cause I'm currently working..(I'm in Korea right now)

But the thing is that I copied the event you made and pasted it into my project...

So it is exactly same as your demo's event. (I adjusted the number of the elevation though...)

I'll post it when I'm done with the work here...
breadlord
Ok. I'm a bit baffled though by why it wont work.

Edit : Wait, did you insert the first script or the second one (In this topic).
tofuman
Here is link

http://www.mediafire.com/download.php?rtydryywmkd

I used one in your demo.

breadlord
I'm sorry to say this but the only reason I can think of that this doen't work is that you have a japanes version and I think thats causing the problem. sleep.gif

tofuman
geez... I also thought that was the problem... (Actually it's Korean version though...)

Well... there were no scripts that cause an error because of the language-version..

That's really weired....

Anyway.. thanks for looking at it...

I guess I gotta find another way... sad.gif
breadlord
Well I'm not deffinete about it, but I don't really know were the error is coming from..
Twilight
QUOTE (breadlord @ Jul 1 2009, 08:38 AM) *
I'm sorry to say this but the only reason I can think of that this doen't work is that you have a japanes version and I think thats causing the problem. sleep.gif


The japanese version has the exact same scripts as the american version. The only differences is the language the editor/comments in the script files are in.
breadlord
Then I have absoulotely no idea what is causing the problem. Because I've done exactly what he has done and it worked. sad.gif
332211
I have a suggestion. Instead of events, if areas were allowed to have two levels (as 3 & 4) or in beween like 3.5, and could be accessed by both 3 and 4 areas, there would be no need to create events to change the player height/level.
Ex
level 1 --- (stairs: level 1&2) --- level 2

Also, there is a 'bug' with the regular events (for event/player touch triggers) as they won't update while you're standing on them. Which makes it impossible to go up and then go immediately down.

Great script, btw. Keep up the good work!
breadlord
Thanks, and I'll try to do the .5 thing, though I'm not sure if I will be able to, as for the player touch events, thats a problem allready in vx, so I'm not sure how to fix that.
FireRMVX
hey can some1 help me. somethin in wrong with rmvx! like i cant save it when i try to exit. like i will try to playtest it and it will say : will you like to save changes to Wavelike Flames?" and i will press yes and it will just do nothing! HELP ME ermm.gif sad.gif
breadlord
Ok,wrong place, and it sounds like your just gonna have to use close it down with task manager and not save it.

Khev
Wow, that worked perfectly fine for me!

There still is that little bug that when you go from, let's say, level 2 to stairs (to level 1) and then try going back up you can't. And then you have to go down to level 1 and then up the stairs to level 2.

I don't really mind it, cause it only takes like half a second, but if you're a perfectionist it's always good to mention.

Great work there, much apreciated!
DestinMancer
For some reason, I copied the two events leading from the base level to the second level, but can't get up the ladder except with the control key. I have no first level, only the base and second level.
SikAnTwisted
Hell yeah!
Awesome script... Thanks a ton:D
Automaton
i just used alot of eventing to do this, but this is much better smile.gif
Dyanova
Hello. I'm not sure if anyone ever uses this thread anymore, but in any case, I'm a newbie at RPGVX, and since RPG VX does not have the directional passage settings like in RPG 2003, I am currently using Breadlord's Elevation Script.

As for the player's passage, it works mostly fine (except one small problem), but my major concern now is regarding the elevation settings for events (eg. NPCs, monsters, etc.). May I request for more detailed instructions on how to set elevation settings for Events? I know that this is touched on in the instructions that came with the script (ie. game_map.events[id].level = whatever), however it is not mentioned where I should use this script. So far I've tried putting it in the "monster" event itself, which obviously doesn't work, so I put it in a Parallel Process event in the same map, which now works.

HERE IS THE PROBLEM: my monster events (those with their elevation levels set to level 1) can now traverse across level 1 elevation smoothly, BUT they can also cross from level 1 to level 0 elevation areas even on areas WITHOUT the "stair events" that the player would normally use. I'm not sure if the script is made such that once event elevation levels are set, they are allowed to traverse to any area with that elevation level AND below (ie. my spider set with elevation level of 1 can traverse on areas level 1 and areas level 0), OR if this is a problem due to me not using the script correctly.

As for monster events without any elevation level settings (ie. they use the default of elevation level 0), these monsters are unable to traverse to level 1 areas (so these are working fine).

Can someone please provide me some help on this? Thanks very much.

Since I'm posting here anyway, I'll just describe the other small problem with the "stairs event" that I mentioned above. When a player walks up a stairs to the point where he touches the event that changes the elevation level, and he stops there and faces the right or left, then tries to walk up again, he is unable to. Of course, he can turn back and walk down one step, then walk up directly again, so this is NOT a game-breaking bug. It's just a little flaw, so I was wondering if Breadlord could refine the script to get around it.

Finally, I would like to thank Breadlord for this amazing script, which I must say, albeit it is more troublesome to use (having to create so many elevation areas, and having the risk of missing out some areas), it is definitely more powerful that what RPG 2003 could do with its directional pass system (well, that is, if the bug above about the monster events can be fixed).
Fonstw

How did you make the line between the different platforms?
When i do the same, they are attached to each other...
Dyanova
QUOTE (Fonstw @ Jan 6 2012, 05:44 PM) *
How did you make the line between the different platforms?
When i do the same, they are attached to each other...


Yea good point. I get the same issue too.
Shaddow
to separate them, you need to keep an open space between the two 'higher' platforms, keep it grass or such, then when you go to build the 'lower' platform hold the shift key down while drawing it. That should give you the look of separation that is shown in that screen shot.
Fonstw
QUOTE (Dyanova @ Jan 8 2012, 01:17 AM) *
QUOTE (Fonstw @ Jan 6 2012, 05:44 PM) *
How did you make the line between the different platforms?
When i do the same, they are attached to each other...


Yea good point. I get the same issue too.


Apperantly when you hold Shift while copying a tile(right click) and keep holding the shift while placing it also gets the line!

QUOTE (shaddowval @ Jan 8 2012, 01:51 AM) *
to separate them, you need to keep an open space between the two 'higher' platforms, keep it grass or such, then when you go to build the 'lower' platform hold the shift key down while drawing it. That should give you the look of separation that is shown in that screen shot.

Oops, found that out myself, but thnks ^^
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.