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.

Checking the Terrain Tag...(new Question)

Ok, so right off the top, I'm using XP. Now my question. I'm attempting to make a "jump" system so that when you say, press right and your facing some water on your right, you'll jump the water. Now, I figured that the easiest way to do this would be through terrain tags. I have most of what I need but to even attempt to test it, I ran into a problem. How do you check the terrain tag of a tile in front of you with a script. I know that it's not possible with events (or at least in the conditional branch it wasn't there...) so I'm guessing that this is going to need that little snippet of code. Can anyone help me here? I seem to remember a system that using terrain tags for stuff (I think it was the poccil's pokemon starter kit...) but I doubt I could find the tiny line (or group of lines  :dead: ) in that mess of coding... Any and all help is greatly appreciated!

So, new question to add to this... How would I make a player use the jump command, but with a script? I'm just looking for the little line (or lines as it most likely is).

Thanks in Advance!
~xgamexfreakx
 
Code:
class Game_Player
  def terrain_in_front
    x = @x
    y = @y
    case @direction
    when 2; y += 1
    when 4; x += -1
    when 6; x += 1
    when 8; y += -1
    end
    return $game_map.terrain_tag(x, y)
  end
end

This would return the terrain tag in front of you with $game_player.terrain_in_front

The Game_Map function terrain_tag(x, y) gets the tag at the given x,y location. Set up the x and y based on the player's location and direction and you can give it the tile you're facing.
 
sweet thanks. Well, since I posted yesterday, I've decided to go completely with a script and effectively write my first script. However, I need some help with some minor snippets of code. The main thing that I need to be able to do is use the jump command from the events, but in a script. So, basically, what is the line of code (or lines as it may be) to make the player jump a square or two?
 
I wrote the following, you can use it if you want.
Place anywhere above main

Code:
class Game_Player
  def jump_2(t)
    x_orginal = @x
    y_orginal = @y
    x_face = direct_calc_x(@direction)
    y_face = direct_calc_y(@direction)
    modi = t - 1
     for i in 1..t
       if $game_map.no_jump(@x + (i * x_face), @y + (i * y_face), 1)
         Audio.se_play("Audio/SE/" + "057-Wrong01", 90, 100)
         return
       end
     end
     jump(t * x_face, t * y_face)
     self.update
     if x_orginal != @x or y_orginal != @y
        Audio.se_play("Audio/SE/" + "015-Jump01", 90, 100)
     else
        Audio.se_play("Audio/SE/" + "057-Wrong01", 90, 100)
     end
 end

def direct_calc_x(d)
    case d
    when 6
      return 1
    when 4
      return -1
    when 2
      return 0
    when 8
      return 0
    end
  end
  
  def direct_calc_y(d)
    case d
    when 6
      return 0
    when 4
      return 0
    when 2
      return 1
    when 8
      return -1
    end
 end
end

class Game_Map
 def no_jump(x, y)
    if self.valid?(x ,y) == true
      for i in 0..2
        tile = data[x, y, i]
        return true if @terrain_tags[tile] == 2
      end
    else
      return true
    end
    return false
  end
end

If use the script option from an event and put $game_player.jump_2(x) it will make the player jump x squares in their current direction. If any tile in the jump path has terrain tag 2 it will not allow the player to jump(prevents jumping over trees, etc.) Finally, if the square the player will land on is unpassable, the jump will be denied. If you want to make the player have a jump ability, you can do the following
pick a variable, say variable 255. Go into Scene_Map and at the end of the update loop add

Code:
if Input.trigger?(Input::A)
  $game_player.jump($game_variables[255]) unless $game_system.map_interpreter.running?
end

Then whenever you press the A button your character will jump a distance equal to the of variable 255. If you have any questions, PM me:)
 
hmmm...I like it. However, I'm not going to use it,however, for two reasons. The first is it doesn't quite fit what I'm trying to do. The second is that I'm attempting to write my own script for this (my first complete one). It's a new thing for me and I'm really hoping to get this. However, I will be looking through your script and using different pieces of your script to complete mine. I'll be sure to ask about any questions that I have (which is sure to be a lot.. )
 
Not a problem, it's definitely always better to write your own scripts; you can get the most out of them that way. If you need any help, or have any questions PM me and I'd be happy to help :)
 

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