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.

Script Request for Forum Game!

Kraft

Sponsor

Hey everyone, I am here to request a simple script (at least, what it does is simple) for the Forum game that Myself, Linkin_T, and Green Raven are currently leading.

If you have ever played golden sun, you will know that when you are able to move blocks around, on the floor around it is a border that the crate/block can not move out of, but the player can.

I have thought this out, and I had the idea of having a script that, when a event has a comment of like "Impassable" or something, that event can not move off of any tile that is set (in the database) to have a terrain ID of 3 (or any number). the player can move on and off of them, but the event can not.

Another example, if there was NPC set to random walking, and it had the comment, it could not go off of any tile that is set to terrain ID of 3.

Thanks, and great credit will be given to anyone who helps (and a spot in out game) for more info about this game, click here

Thanks!

Kraft
 
I will handle This one!

Edit: Here it is!

Code:
#==============================================================================
# ** Constants Defenitions
#------------------------------------------------------------------------------
#The Impassable Tag
Impassable_tag = 3    
#The Trigger to be checked
Trigger  = "Impassable"
#==============================================================================
# ** Game_Character (part 3)
#------------------------------------------------------------------------------
#  This class deals with characters. It's used as a superclass for the
#  Game_Player and Game_Event classes.
#==============================================================================

class Game_Character
  alias cg1_game_character_edit_intialize        initialize
  alias cg1_game_character_edit_move_down        move_down
  alias cg1_game_character_edit_move_left        move_left
  alias cg1_game_character_edit_move_right       move_right
  alias cg1_game_character_edit_move_up          move_up
  alias cg1_game_character_edit_move_lower_left  move_lower_left
  alias cg1_game_character_edit_move_lower_right move_lower_right
  alias cg1_game_character_edit_move_upper_right move_upper_right
  alias cg1_game_character_edit_move_upper_left  move_upper_left
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :tagged
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @tagged = false
    cg1_game_character_edit_intialize
  end
  #--------------------------------------------------------------------------
  # * Move Down
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_down(turn_enabled = true)
    return turn_down if $game_map.terrain_tag(self.x,self.y + 1) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_down
  end
  #--------------------------------------------------------------------------
  # * Move Left
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_left(turn_enabled = true)
    return turn_left if $game_map.terrain_tag(self.x-1,self.y) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_left
  end
  #--------------------------------------------------------------------------
  # * Move Right
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_right(turn_enabled = true)
    return turn_right if $game_map.terrain_tag(self.x+1,self.y) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_right
  end
  #--------------------------------------------------------------------------
  # * Move up
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_up(turn_enabled = true)
    return turn_up if $game_map.terrain_tag(self.x,self.y-1) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_up
  end
  #--------------------------------------------------------------------------
  # * Move Lower Left
  #--------------------------------------------------------------------------
  def move_lower_left
    return turn_left  if $game_map.terrain_tag(self.x-1,self.y+1) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_lower_left
  end
  #--------------------------------------------------------------------------
  # * Move Lower Right
  #--------------------------------------------------------------------------
  def move_lower_right
    return turn_right if $game_map.terrain_tag(self.x+1,self.y+1) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_lower_right
  end
  #--------------------------------------------------------------------------
  # * Move Upper Left
  #--------------------------------------------------------------------------
  def move_upper_left
    return turn_left if $game_map.terrain_tag(self.x-1,self.y-1) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_upper_left
  end
  #--------------------------------------------------------------------------
  # * Move Upper Right
  #--------------------------------------------------------------------------
  def move_upper_right
    return turn_right if $game_map.terrain_tag(self.x+1,self.y-1) == Impassable_tag && @tagged == true 
    cg1_game_character_edit_move_upper_right
  end
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  This class deals with events. It handles functions including event page 
#  switching via condition determinants, and running parallel process events.
#  It's used within the Game_Map class.
#==============================================================================
class Game_Event < Game_Character
  alias cg1_game_event_edit_refresh   initialize
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def initialize(map_id, event)
    cg1_game_event_edit_refresh(map_id, event)   
    @tagged = true if has_trigger?(Trigger)
  end  
  #--------------------------------------------------------------------------
  # * Returns true if text is in an event's comments
  #--------------------------------------------------------------------------
  def has_trigger?(text)
    list = self.list
    trigger = text
    return nil if list == nil
    return nil unless list.is_a?(Array)
    for item in list
      next if item.code != 108
      if item.parameters[0] == trigger
        return true
      end
    end
    return false
  end
end
 

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