Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Push Blocks, Create Push Blocks by Comments
Philip
post Jan 29 2012, 01:02 PM
Post #1


Nura (The Jade Ring)
Group Icon

Group: Revolutionary
Posts: 327
Type: Developer
RM Skill: Masterful




~~ PUSH BLOCK SCRIPT ~~


Version: 1.0
Author: Philip
Release Date: 1/29/2012

~~ INTRODUCTION ~~


This script allows you to make push blocks for those dungeon puzzles that require you to push a block on a switch somewhere. It is suggested that you use Biged781's script that memorizes event positions so your push blocks will stay put if you exit the map. His script can be found here. The script will turn a designated switch on or off depending on what you specify.

~~ FEATURES ~~


This is just the basic script for the time being. Although suggestions are very welcome for new features. Critisizm is welcome if done in a polite manner. Alright, I just cleaned up the demo a bit. You MUST have RTP to use the demo.

  • Designate Coordinates
  • Designate Switch
  • Designate True or False


~~ SCRIPT ~~


PUSH BLOCK SCRIPT

CODE
#===============================================================================
# — [VX] — Push Blocks — –
# * A script that allows the user to add push blocks into the
# * game without intricate eventing.
#
# * Feedback on this script is welcomed and wanted. If you think
# * of new features please let me know and I'll think about it. =P
#-------------------------------------------------------------------------------
# — by Philip [philbusiness52@yahoo.com]
# — RPG RPG REVOLUTION
# — Released on: 1/27/2012
# — Version: 1.0
#-------------------------------------------------------------------------------

#===============================================================================
# * HOW TO USE *
#
# * Put a comment in an event set to the look like the one below.
# * The event MUST be same level as player and should have some kind
# * of graphic of a block or boulder and thats it.
#
# [block: x coordinate of where the block must go, y coordinate, switch number, switch true/false]
#
# Example: [block: 5, 20, 1, true]
#
# When the event with this comment is over the map x-y coordinates (5, 20)
# the switch number 1 will be turned to true. When the block is not on
# those coordinates switch 1 will be switched to false.
#
# Example: [block: 18, 31, 29, false]
#
# When the event with this comment is over the map x-y coordinates (18, 31)
# the switch number 29 will be turned to false. When the block is not on
# those coordinates switch 29 will be switched to true.
#
#
# * This script also deals with the movement of the push blocks. Once you
# * put this comment in the event if you step into it the event will push
# * away from you and you will step forward. If you are standing next to
# * it and you press the "ENTER" button the push block will be pulled in
# * the player's direction and the player will take a step back. This is
# * done by default and no work is needed on your part. You do however
# * need to define what sound you wish to be played when you push/pull
# * the block. Define it below in the module. You don't need to define
# * the file extension; just the name. Also you can define your own volume
# * and pitch.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# * CUSTOMIZATION AREA
#-------------------------------------------------------------------------------
module PUSH_BLOCK_SOUND
  PUSH_SOUND = "Push"                  # my own sound name define your own
  
  
  PUSH_VOLUME = 100                    # default for defining volume in event is
                                       # 80 but I moved it up to 100
                                      
  PUSH_PITCH = 100                     # 100 is default
end
#-------------------------------------------------------------------------------
# * END CUSTOMIZATION AREA -- WARNING!! -- DO NOT MODIFY BELOW THIS LINE -------
#-------------------------------------------------------------------------------
class Game_Character
  
  include PUSH_BLOCK_SOUND
  #-----------------------------------------------------------------------------
  # * This portion includes the necessary code to return the comment.
  #-----------------------------------------------------------------------------
  def comment?(comment, return_data = false)
    if !@list.nil?
      for i in 0...@list.size
        next if @list[i].code != 108
        if @list[i].parameters[0].include?(comment)
          if return_data
            return @list[i].parameters[0]
          else
            return true
          end
        end
      end
    end
    return return_data == true ? nil : false
  end
  #-----------------------------------------------------------------------------
  # * ALIAS INITIALIZE FOR GAME_CHARACTER
  #-----------------------------------------------------------------------------
  alias phils_ini initialize unless $@
  def initialize
    phils_ini
    @block = []
    @comment = false
    @wait_one = false
    @wait_two = false
    @wait_three = false
    @stop_fix = false
  end
  #-----------------------------------------------------------------------------
  # * ALIAS UPDATE FOR GAME_CHARACTER
  #-----------------------------------------------------------------------------
  alias push_blocks update unless $@
  def update
    #---------------------------------------------------------------------------
    # * This portion handles parsing the comment in the event.
    #---------------------------------------------------------------------------
    if !@comment
      if comment?('[block: ')
        @tag = comment?('[block: ', true)
        @tag.scan(/\[block:[ ]*([\+\-]?\d+)[ ]*,[ ]*([\+\-]?\d+)[ ]*,[ ]*([\+\-]?\d+),[ ]*(\w+)]/i)
        @block.push([$1.to_i, $2.to_i, $3.to_i, $4.to_s])
        @comment = true
      end
    end
    #---------------------------------------------------------------------------
    # * This portion handles button input for pulling and pushing the blocks.
    #---------------------------------------------------------------------------
    if @block != nil && !@block.empty?
      if $game_player.pos?($game_map.events[@id].x, $game_map.events[@id].y - 1) && $game_map.passable?($game_player.x, $game_player.y + 2)
        if Input.press?(Input::DOWN) && !$game_player.moving?
          block_pushing
        end
      end
      if $game_player.pos?($game_map.events[@id].x + 1, $game_map.events[@id].y) && $game_map.passable?($game_player.x - 2, $game_player.y)
        if Input.press?(Input::LEFT) && !$game_player.moving?
          block_pushing
        end
      end
      if $game_player.pos?($game_map.events[@id].x - 1, $game_map.events[@id].y) && $game_map.passable?($game_player.x + 2, $game_player.y)
        if Input.press?(Input::RIGHT) && !$game_player.moving?
          block_pushing
        end
      end
      if $game_player.pos?($game_map.events[@id].x, $game_map.events[@id].y + 1) && $game_map.passable?($game_player.x, $game_player.y - 2)
        if Input.press?(Input::UP) && !$game_player.moving?
          block_pushing
        end
      end
      if Input.press?(Input::C) && !$game_player.moving?
        if $game_player.pos?($game_map.events[@id].x, $game_map.events[@id].y - 1) && $game_map.passable?($game_player.x, $game_player.y - 1)
          @stop_fix = true
        end
        if $game_player.pos?($game_map.events[@id].x + 1, $game_map.events[@id].y) && $game_map.passable?($game_player.x + 1, $game_player.y)
          @stop_fix = true
        end
        if $game_player.pos?($game_map.events[@id].x - 1, $game_map.events[@id].y) && $game_map.passable?($game_player.x - 1, $game_player.y)
          @stop_fix = true
        end
        if $game_player.pos?($game_map.events[@id].x, $game_map.events[@id].y + 1) && $game_map.passable?($game_player.x, $game_player.y + 1)
          @stop_fix = true
        end
      end
      #-------------------------------------------------------------------------
      # * This portion handles the block PULLING.
      #-------------------------------------------------------------------------
      if @stop_count > 5 * (5 - @move_frequency) && @stop_fix
        $game_player.direction_fix = true
        $game_player.walk_anime = false
        $game_player.move_backward
        $game_player.walk_anime = true
        $game_player.direction_fix = false
        RPG::SE.new(PUSH_SOUND, PUSH_VOLUME, PUSH_PITCH).play
        $game_map.events[@id].turn_toward_player
        $game_map.events[@id].move_toward_player
        @pulling = false
        @stop_fix = false
      end
    end
    #---------------------------------------------------------------------------
    # * This portion handles turning the switches on and off.
    #---------------------------------------------------------------------------
    if @block != nil && !@block.empty?
      for pushing in @block
        if check_location(pushing[0], pushing[1])
          if !@wait_two
            @wait_count = 31
            @wait_two = true
          end
          if !$game_map.interpreter.running? && @wait_count <= 1
            case pushing[3]
            when /(?:TRUE|ON)/i
              if !$game_switches[pushing[2]]
                $game_switches[pushing[2]] = true
                $game_map.need_refresh = true
              end
            when /(?:FALSE|OFF)/i
              if $game_switches[pushing[2]]
                $game_switches[pushing[2]] = false
                $game_map.need_refresh = true
              end
            end
            @wait_two = false
          end
        else
          if !@wait_two
            @wait_count = 31
            @wait_two = true
          end
          if !$game_map.interpreter.running? && @wait_count <= 1
            case pushing[3]
            when /(?:TRUE|ON)/i
              if $game_switches[pushing[2]]
                $game_switches[pushing[2]] = false
                $game_map.need_refresh = true
              end
            when /(?:FALSE|OFF)/i
              if !$game_switches[pushing[2]]
                $game_switches[pushing[2]] = true
                $game_map.need_refresh = true
              end
            end
            @wait_two = false
          end
        end
      end
    end
    push_blocks
  end
  #-----------------------------------------------------------------------------
  # * This portion checks the position of the event and the coordinates you
  # * designated for where the switch is.
  #-----------------------------------------------------------------------------
  def check_location(a, b)
    if $game_map.events[@id].x == a && $game_map.events[@id].y == b
      return true
    elsif $game_player.x == a && $game_player.y == b
      return true
    else
      return false
    end
  end
  #-----------------------------------------------------------------------------
  # * This portion handles the block PUSHING.
  #-----------------------------------------------------------------------------
  def block_pushing
    if @stop_count > 5 * (5 - @move_frequency)
      RPG::SE.new(PUSH_SOUND, PUSH_VOLUME, PUSH_PITCH).play
      $game_map.events[@id].turn_toward_player
      $game_map.events[@id].move_away_from_player
    end
    if !@wait_one
      @wait_count = 3
      @wait_one = true
    end
    if !$game_map.interpreter.running? && @wait_count <= 1
      if @stop_count > 5 * (5 - @move_frequency)
        $game_player.move_forward
        @wait_one = false
      end
    end
  end
end
#-------------------------------------------------------------------------------
# * END OF SCRIPT
#-------------------------------------------------------------------------------



~~ CUSTOMIZATION ~~


You can customize the name of the sound that plays when a block is pushed, it's volume, and pitch.

~~ COMPATIBILITY ~~


This doesn't overwrite any methods it only aliases them so it shouldn't have a problem with any scripts.

~~ SCREENSHOT ~~


None necessary.

~~ DEMO ~~




~~ INSTALLATION ~~


Place the script below the Materials section and above Main.

~~ TERMS AND CONDITIONS ~~


None on this one. Free to use on any project you desire. Just put me in the credits please.

This post has been edited by Philip: Feb 1 2012, 11:51 AM


__________________________
"If your mind goes blank don't forget to turn off the sound." Unknown Author

Phil


Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 12:56 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker