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.

Aleworks Push Events

Aleworks Push Events (APE)
Created by Aleworks (vgvgf)
Version: 1.02
Last Updated: 22-02-2008(day/month/year)


Introduction
This script allow the game player to push events. It has functions for changing the pushing sound, push distance, push directions, and more.

Download links
Demostration
APE(v1.00).rar

Script

Code:
=begin =======================================================================
 â–“ Aleworks Push Events (APE)
==============================================================================
 Created by Aleworks
 Version: 1.02
 Last Update: 22/02/2008 (dd/mm/yyyy)
==============================================================================
                             *** Instructions ***
 For setup an event for being pushable, you need to add a comment with one or
 more of the commands in the comment commands list. The PUSH SPEED #, 
 PUSH DISTANCE #, PUSH SOUND # and PUSH TRIGGER commands, need that the
 PUSHABLE command be added.
==============================================================================
                         *** Comment Commands List *** 
 PUSHABLE
   If the player move in the direction of the event, it will move in the same
   direction the player moves, if the event can't move in that direction, it
   will try to move in other directions.
 PUSHABLE IN DIRECTION
   If the player move in the direction of the event, it will move in the same
   direction the player moves.
 PUSHABLE #
 PUSHABLE IN DIRECTION #
   Change the # with the posible directions that the event can be pushed.
 PUSH SPEED #
   Change the # with the speed that the event will move when pushed.
 PUSH DISTANCE #
   Change the # with the tiles that the event will be pushed.
 PUSH SOUND #
   Change the # with the file name of the sound effect that will be played when
   the event is pushed.
 PUSH TRIGGER
   The event will be pushed, only if the button C is pressed.
 TRASPASABLE
   Make that the player can pass through the event.
==============================================================================
                       *** APE RGSS Classes edits ***
 *** Game_Character ***
alias: update; alias name: aleworks_pushevents_gamecharacter_update
replace: passable?(x, y, d)
replace: screen_z
 *** Game_Event ***
alias: refresh; alias name: aleworks_pushevents_gameevent_refresh
 *** Game_Player ***
replace: update
==============================================================================
=end

#=============================================================================
# â–’ Game_Character
#=============================================================================
class Game_Character
  attr_accessor :move_speed
  alias aleworks_pushevents_gamecharacter_update update
  #===========================================================================
  # â–‘ update
  #===========================================================================
  def update
    if moving? == false and self.is_a?(Game_Event)
      if @left_push == 0
        @pushing = false
        @pushing_direction = 0
      else
        case @pushing_direction
        when 2
          move_down
          Audio.se_play("Audio/SE/" + @push_sound) if @push_sound != nil
        when 4
          move_left
          Audio.se_play("Audio/SE/" + @push_sound) if @push_sound != nil
        when 6
          move_right
          Audio.se_play("Audio/SE/" + @push_sound) if @push_sound != nil
        when 8
          move_up
          Audio.se_play("Audio/SE/" + @push_sound) if @push_sound != nil
        end
        @left_push -= 1
      end
    end
    if @old_speed != nil and @pushing == false
      @move_speed = @old_speed if @move_speed == @push_speed
      @old_speed = nil
    end
    aleworks_pushevents_gamecharacter_update
  end
  #===========================================================================
  # â–‘ passable?
  #===========================================================================
  def passable?(x, y, d)
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    return false unless $game_map.valid?(new_x, new_y)
    return true if @through
    return false unless $game_map.passable?(x, y, d, self)
    return false unless $game_map.passable?(new_x, new_y, 10 - d)
    for event in $game_map.events.values
      if event.x == new_x and event.y == new_y
        next if self == $game_player and event.traspasable
        unless event.through
          return false if event.character_name != ""
        end
      end
    end
    if $game_player.x == new_x and $game_player.y == new_y
      unless $game_player.through
        return false if @character_name != ""
      end
    end
    return true
  end
  #===========================================================================
  # â–‘ screen_z
  #===========================================================================
  def screen_z(height = 0)
    return 999 if @always_on_top
    z = (@real_y - $game_map.display_y + 3) / 4 + 32
    if @tile_id > 0
      return z + $game_map.priorities[@tile_id] * 32
    else
      if self.is_a?(Game_Event)
        if @traspasable == true
          return z + ((height > 32) ? 31 : 0) + 16
        else
          return z + ((height > 32) ? 31 : 0)
        end
      else
        return z + ((height > 32) ? 31 : 0)
      end
    end
  end
end

#=============================================================================
# â–’ Game_Event
#=============================================================================
class Game_Event
  attr_reader :pushable
  attr_reader :push_speed
  attr_reader :push_distance
  attr_reader :traspasable
  attr_reader :push_in_diretion
  attr_reader :push_direction
  attr_reader :push_sound
  attr_reader :push_trigger
  attr_accessor :pushing
  attr_accessor :old_speed
  attr_accessor :left_push
  attr_accessor :pushing_direction
  alias aleworks_pushevents_gameevent_refresh refresh
  #===========================================================================
  # â–‘ refresh
  #===========================================================================
  def refresh
    @pushable = false
    @push_speed = nil
    @push_distance = 1
    @pushing = false
    @old_speed = nil
    @left_push = 0
    @push_direction = []
    @pushing_direction = 0
    @traspasable = false
    @push_in_diretion = false
    @push_sound = nil
    @push_trigger = false
    aleworks_pushevents_gameevent_refresh
    return if @page.nil? or @page.list.nil?
    for i in @page.list
      if i.code == 108 or i.code == 408
        if i.parameters[0].upcase[/PUSHABLE/] != nil
          @pushable = true
          @push_in_diretion = true if i.parameters[0].upcase[/IN DIRECTION/] != nil
          @push_direction.push(2) if i.parameters[0][/2/] != nil
          @push_direction.push(4) if i.parameters[0][/4/] != nil
          @push_direction.push(6) if i.parameters[0][/6/] != nil
          @push_direction.push(8) if i.parameters[0][/8/] != nil
        end
        if i.parameters[0].upcase[/PUSH SPEED/] != nil
          @push_speed = i.parameters[0].split[2].to_i
        end
        if i.parameters[0].upcase[/PUSH DISTANCE/] != nil
          @push_distance = i.parameters[0].split[2].to_i
        end
        if i.parameters[0].upcase[/PUSH SOUND/] != nil
          @push_sound = i.parameters[0].split[2]
        end
        if i.parameters[0].upcase[/PUSH TRIGGER/] != nil
          @push_trigger = true
        end
        if i.parameters[0].upcase[/TRASPASABLE/] != nil
          @traspasable = true
        end
      end
    end
  end
end

#=============================================================================
# â–’ Game_Player
#=============================================================================
class Game_Player
  #===========================================================================
  # â–‘ update
  #===========================================================================
  def update
    last_moving = moving?
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      case Input.dir4
      when 2
        dir = 2
        alt_dir = [4,6,8]
        push_x = 0
        push_y = 1
      when 4
        dir = 4
        alt_dir = [2,6,8]
        push_x = -1
        push_y = 0
      when 6
        dir = 6
        alt_dir = [2,4,8]
        push_x = 1
        push_y = 0
      when 8
        dir = 8
        alt_dir = [2,4,6]
        push_x = 0
        push_y = -1
      else
        dir = 0
        push_x = 0
        push_y = 0
      end
      if passable?(@x, @y, dir) and dir != 0
        case dir
        when 2
          move_down
        when 4
          move_left
        when 6
          move_right
        when 8
          move_up
        end
      elsif dir != 0
        case dir
        when 2
          turn_down
          check_event_trigger_touch(@x, @y+1)
        when 4
          turn_left
          check_event_trigger_touch(@x-1, @y)
        when 6
          turn_right
          check_event_trigger_touch(@x+1, @y)
        when 8
          turn_up
          check_event_trigger_touch(@x, @y-1)
        end
        if $game_map.passable?(@x, @y, dir)
          for event in $game_map.events.values
            if event.x == @x + push_x and event.y == @y + push_y
              next if event.through == true
              next if event.pushable == false
              next if event.moving? == true
              next if event.push_trigger == true
              next if event.push_direction.size >= 1 and 
                      !event.push_direction.include?(dir)
              if event.passable?(event.x, event.y, dir)
                event.pushing = true
              else
                if !event.push_in_diretion
                  if event.passable?(event.x, event.y, alt_dir[0])
                    dir = alt_dir[0]
                    event.pushing = true
                  elsif event.passable?(event.x, event.y, alt_dir[1])
                    dir = alt_dir[1]
                    event.pushing = true
                  elsif event.passable?(event.x, event.y, alt_dir[2])
                    dir = alt_dir[2]
                    event.pushing = true
                  end
                end
              end
              if event.pushing == true
                case dir
                when 2
                  event.move_down
                when 4
                  event.move_left
                when 6
                  event.move_right
                when 8
                  event.move_up
                end
                if event.push_speed != nil
                  event.old_speed = event.move_speed
                  event.move_speed = event.push_speed
                end
                if event.push_distance > 1
                  event.left_push = event.push_distance
                  event.pushing_direction = dir
                end
                if event.push_sound != nil
                  Audio.se_play("Audio/SE/" + event.push_sound)
                end
              end
            end
          end
        end
      end
    end
    last_real_x = @real_x
    last_real_y = @real_y
    super
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      $game_map.scroll_down(@real_y - last_real_y)
    end
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      $game_map.scroll_left(last_real_x - @real_x)
    end
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      $game_map.scroll_right(@real_x - last_real_x)
    end
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      $game_map.scroll_up(last_real_y - @real_y)
    end
    unless moving?
      if last_moving
        result = check_event_trigger_here([1,2])
        if result == false
          unless $DEBUG and Input.press?(Input::CTRL)
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      if Input.trigger?(Input::C)
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
        case @direction
        when 2
          dir = 2
          alt_dir = [4,6,8]
          push_x = 0
          push_y = 1
        when 4
          dir = 4
          alt_dir = [2,6,8]
          push_x = -1
          push_y = 0
        when 6
          dir = 6
          alt_dir = [2,4,8]
          push_x = 1
          push_y = 0
        when 8
          dir = 8
          alt_dir = [2,4,6]
          push_x = 0
          push_y = -1
        else
          dir = 0
          push_x = 0
          push_y = 0
        end
        for event in $game_map.events.values
          if event.x == @x + push_x and event.y == @y + push_y
            next if event.through == true
            next if event.pushable == false
            next if event.push_trigger == false
            next if event.moving? == true
            next if event.push_direction.size >= 1 and 
                    !event.push_direction.include?(dir)
            if event.passable?(event.x, event.y, dir)
              event.pushing = true
            else
              if !event.push_in_diretion
                if event.passable?(event.x, event.y, alt_dir[0])
                  dir = alt_dir[0]
                  event.pushing = true
                elsif event.passable?(event.x, event.y, alt_dir[1])
                  dir = alt_dir[1]
                  event.pushing = true
                elsif event.passable?(event.x, event.y, alt_dir[2])
                  dir = alt_dir[2]
                  event.pushing = true
                end
              end
            end
            if event.pushing == true
              case dir
              when 2
                event.move_down
              when 4
                event.move_left
              when 6
                event.move_right
              when 8
                event.move_up
              end
              if event.push_speed != nil
                event.old_speed = event.move_speed
                event.move_speed = event.push_speed
              end
              if event.push_distance > 1
                event.left_push = event.push_distance
                event.pushing_direction = dir
              end
              if event.push_sound != nil
                Audio.se_play("Audio/SE/" + event.push_sound)
              end
            end
          end
        end
      end
    end
  end
end

* Please give me credit if you use my script.                                  
* Help me to continue developing this script                                  
    Send the errors that you find and your ideas to vgvgvgf@gmail.com or post here
 

KazeN

Member

I think this looks great too. It will be much easier to use when doing puzzles in dungeons and such. I will probably use it in my game (with credit of course).

Noticed that when I tried to implement it in my game, I got an error message.
" Script 'Aleworks Push Events' line 179: NoMethodError occured. undefined method `list' for nil:NilClass"
 
Noticed that when I tried to implement it in my game, I got an error message.
" Script 'Aleworks Push Events' line 179: NoMethodError occured. undefined method `list' for nil:NilClass"
Maybe another script make some trouble, or there is a event with no event commands.

Try overwriting the Game_Event refresh method with this:
Code:
  #===========================================================================
  # â–‘ refresh
  #===========================================================================
  def refresh
    @pushable = false
    @push_speed = nil
    @push_distance = 1
    @pushing = false
    @old_speed = nil
    @left_push = 0
    @push_direction = []
    @pushing_direction = 0
    @traspasable = false
    @push_in_diretion = false
    @push_sound = nil
    @push_trigger = false
    aleworks_pushevents_gameevent_refresh
    if @page != nil and @page != []
      for i in @page.list
        if i.code == 108 or i.code == 408
          if i.parameters[0].upcase[/PUSHABLE/] != nil
            @pushable = true
            @push_in_diretion = true if i.parameters[0].upcase[/IN DIRECTION/] != nil
            @push_direction.push(2) if i.parameters[0][/2/] != nil
            @push_direction.push(4) if i.parameters[0][/4/] != nil
            @push_direction.push(6) if i.parameters[0][/6/] != nil
            @push_direction.push(8) if i.parameters[0][/8/] != nil
          end
          if i.parameters[0].upcase[/PUSH SPEED/] != nil
            @push_speed = i.parameters[0].split[2].to_i
          end
          if i.parameters[0].upcase[/PUSH DISTANCE/] != nil
            @push_distance = i.parameters[0].split[2].to_i
          end
          if i.parameters[0].upcase[/PUSH SOUND/] != nil
            @push_sound = i.parameters[0].split[2]
          end
          if i.parameters[0].upcase[/PUSH TRIGGER/] != nil
            @push_trigger = true
          end
          if i.parameters[0].upcase[/TRASPASABLE/] != nil
            @traspasable = true
          end
        end
      end
    end
  end

Do all events have to move instantly when you touch them though?
I can't understand well, what do you say...
Please, can you especify a bit more?
 
i think he what he means is when you go to push an event he wants to make it so that you have to wait a bit before the object moves so that it seems like its heavy
 
I will add a new option for wait some seconds before pushing for the next release, and others like for changing the player graphic, or events that move jointly when pushing one of them, for logs, or big rocks.
 
Hey, this script is really good.. :D but.. why is it that when i put some "control switch" events in the map, the game crashes?

it says:

Script 'Aleworks Push Events' line 179: NoMethodError occured.

undefined method `list' for nil:NilClass
 
Wow, this sounds like a good script. Pity I can't test it out, due to a lack of RPGXP on this computer. Will save people a lot of eventing.

EDIT: Tried it, works well. Gives me a strong urge to make a number of events in the middle of a map, and walk straight through them. XD
 

phlee

Member

i think there is a bug when the script is active,
any SOLID* events with "Player Touch" trigger ON becomes malfunction..
"Player Touch" effect becomes "Action Button" effect

this bug happened in both demo and my project

*cannot walk through
 

phlee

Member

jbrist":1xfd8jvp said:
Umm, phlee, the last post was in November, thats called Necroposting and shouldn't be done.

if the definition of necroposting = do not post ANYTHING after 2 months

i am sorry
 

Jason

Awesome Bro

Necroposting is when you post in a thread after a month of no posts. So if the last post is 1st Jan, and you post, say, 1st Feb, that counts, although it isn't as bad as posting 3 months after, someone even posted after 2 years, haha.
 
Do all scripts go into the  database when released? if not... after a month of not being posted in... the script goes BYEBYE! and some potentially good scripts vanish...
 

Nachos

Sponsor

It's a GREAT script. But you could Simply reduct that into 2 event lines.

On-Player tocuch

@This event: Move foward

and you can configuere speed, and distance...
 
true... But if you want giant puzzles set up... This just cuts down time...

I was also looking through it and the script allows you do make different sound effects per different direction things are pressed XP not sure how you could harness that though
 

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