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.

Disallow creation of event on non-passable tiles?

Xelzor

Member

Hey everyone,

I'm putting together a game in which you can pick up objects on the ground with the action button, carry them around, and then put them down wherever you want... I've got that part figured out, but the issue I'm running into is that you can indeed put the objects down WHEREVER you want (in the water, on top of buildings, etc.)

Is there any way (presumably with scripting) to create a check to see if the tile directly in front of the hero is passable?

And then, from there, is there a way to disallow the un-equippiing of shields (which is currently the slot I'm using for carried items) IF that check says that the terrain is not passable?

Any help would be greatly appreciated!

~ Nicholai
 
To check passability you use the passable? method in game_map.

This script when run will store a value in variable number; if the value is 1 then the tile in front of the hero is passable. if its 2 then its impassable.
I'm sure you can figure out how to modify your lift and drop event using fork conditions based on that variable.

Code:
#----------------------------------------
# This adds a method to the game_player class to check 
# if the tile infront is passable and store it in a variable
# to use simoply Call Script:
# $game_player.check_front
# The value of variable[1] wwill tell you the outcome
# if it = 1 then the tiles passable.
# if it = 2 then its not
#-----------------------------------------

class Game_Player
  def check_front
    # Get x + y coords and facing
    x = $game_player.x
    y = $game_player.y
    direction = $game_player.direction
    
    # Modify coordinates to compensate for direction
    case direction
    when 2
      # Down 
      y += 1
    when 4
      # Left
      x -= 1
    when 6
      # Right
      x += 1
    when 8
      # Up
      y -= 1
    end
    
    # Check if passable
    temp = $game_map.passable?(x, y, 0)
    
    # Save as variable
    if temp == true
      $game_variables[1] = 1
    else
      $game_variables[1] = 2
    end
  end
end

To use simply call script: $game_mao.check_front
 

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