Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Teleportation Script
#1
Teleportation Script
by Digi
May 1 2007

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Before I go on, I should say that I was unsure of which forum to place this in. Please move it if it shouldn't be here. One should certainly credit Silfeed Arks for this script. A minor credit to me would be appreciated, however.

Original script may be found (among others) here.<--(Dead link)

Place the code in a new script above main. I'm uncertain of SDK compatibility. Further instructions are in the script itself.
Code:
#============================================================================#
#                          Teleportation Script
#
#  Written by:              Shiroi Lith (Hopefully I translated that correctly)
#  Found on:                Silfeed Arks (http://squirrel.dragon-breath.net/SilfeedArks/)
#  Translated (messily) by: Digi
#
#============================================================================#
# To use this script, use the "call script" event command, with these snippets:
#
# warp_set( id )       : Adds a teleport point with specified ID
# warp_foget( id )     : Removes a teleport point with specified ID
# warp_cant( true or false )  : If true, teleportation won't work.
#
#==============================================================================
#  Now come the settings.
#==============================================================================
class Game_System
  WARP_ELEMENT_ID       = 18     # Skills with this element will use teleport.
#==============================================================================
#  The structure for defining warp points looks like this:
#
#  when ID#
#
#    name      : The name of the warp point in the menu.
#    map_id    : The ID of the target map.
#    point     : Where the player "lands". Should be in [ x, y ] format.
#    direction : The direction the player is facing upon teleportation.
#                The directions correspond to the numpad.
#                2 = down, 4 = left, 6 = right, 8 = up.
#    switch    : If defined, this switch will be turned on upon teleportation.
#==============================================================================
  def warp_point_data(id)
    switch = nil
    direction = nil
    case id
    when 0
      name   = "A Plain"
      map_id = 1
      point  = [ 5, 4]
    when 1
      name   = "Town"
      map_id = 2
      point  = [12,25]
      direction = 8
      switch = 10
    when 2
      name   = "Town Entrance"
      map_id = 2
      point  = [1,14]
      direction = 2
    else
      return nil
    end
    return [ name, map_id, point, direction, switch ]
  end
# This message is displayed in the help window when you pick a teleport point.
  def warp_mesage
    return "Please choose a destination."
  end
#==============================================================================
#   Some setup and aliasing.
#==============================================================================
  attr_accessor :warp_point               # Destination
  attr_accessor :warp_cant                # Disabler
  alias ws2_initialize initialize
  def initialize
    @warp_point = []
    @warp_cant  = 0
    ws2_initialize
  end
  def warp_element
    return WARP_ELEMENT_ID
  end
  def warp_sprite_lock
    return WARP_SPRITE_LOCK
  end
end
#==============================================================================
# This sticks the methods for warp point management into the event interpreter.
#==============================================================================
class Interpreter
  def warp_set(id)
    unless $game_system.warp_point.include?(id)
      # Basic checks for if a point should be added or not
      c = $game_system.warp_point_data(id)
      unless c == nil
        $game_system.warp_point.push(id)
        $game_system.warp_point.sort!
      end
    end
  end
  def warp_foget(id)
    $game_system.warp_point.delete(id)
  end
  def warp_cant( para )
    if para
      $game_system.warp_cant  = 1
    else
      $game_system.warp_cant  = 0
    end
  end
end
#==============================================================================
# This rearranges the "usable" definitions of items and skills around a bit.
#==============================================================================
class Game_Party
  alias ws2_item_can_use? item_can_use?
  def item_can_use?(item_id)
    if $data_items[item_id].element_set.include?($game_system.warp_element) and $game_system.warp_cant == 1
      return false
    end
    ws2_item_can_use?(item_id)
  end
end
class Game_Actor < Game_Battler
  alias ws2_skill_can_use? skill_can_use?
  def skill_can_use?(skill_id)
    if $data_skills[skill_id].element_set.include?($game_system.warp_element) and $game_system.warp_cant == 1
      return false
    end
    ws2_skill_can_use?(skill_id)
  end
end
#==============================================================================
# ■ Window_Warp
#------------------------------------------------------------------------------
#  This is the destination-picking window.
#==============================================================================

class Window_Warp < Window_Selectable
  #--------------------------------------------------------------------------
  # ● Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 640, 416)
    @column_max = 2
    refresh
    self.index = 0
    self.z += 10
  end
  #--------------------------------------------------------------------------
  # ● Grab item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # ● Refresh the display
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    # Add possible destinations to the array
    for i in 0...$game_system.warp_point.size
      c = $game_system.warp_point_data($game_system.warp_point[i])
      unless c == nil
        @data.push( c )
      end
    end
    # Makes the bitmap, provided the list isn't empty
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● Item display
  #     index : the item's number
  #--------------------------------------------------------------------------
  def draw_item(index)
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(x + 14, y, 226, 32, @data[index][0], 0)
  end
end
#==============================================================================
#  This Scene_Item mod handles teleportation items.
#==============================================================================
class Scene_Item
  alias ws2_main main
  alias ws2_update_item update_item
  alias ws2_update update
  def main
    ws2_main
    if @warp_window != nil
      @warp_window.dispose
    end
  end
  def update
    if @warp_window != nil
      @warp_window.update
      update_warp
      return
    end
    ws2_update
  end

  def update_item
    # When C is pressed
    if Input.trigger?(Input::C)
      # Check if it's a teleporter item
      @item = @item_window.item
      unless @item == nil
        if @item.element_set.include?($game_system.warp_element) and @item.is_a?(RPG::Item)
          if $game_system.warp_cant == 1
            # Play the error SE
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          # Play the confirm SE
          $game_system.se_play($data_system.decision_se)
          # Open the destination window
          @item_window.active = false
          @item_window.visible = false
          @warp_window = Window_Warp.new
          @help_window.set_text( $game_system.warp_mesage )
          return
        end
      end
    end
    ws2_update_item
  end

  def update_warp
    # When B is pressed
    if Input.trigger?(Input::B)
      # Play the cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Kill the destination window
      @item_window.active = true
      @item_window.visible = true
      @warp_window.dispose
      @warp_window = nil
      return
    end
    # When C is pressed
    if Input.trigger?(Input::C)
      if @warp_window.item == nil
        # Play the error SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play the item's SE.
      $game_system.se_play(@item.menu_se)
      # If the item is consumable...
      if @item.consumable
        # ...consume it
        $game_party.lose_item(@item_window.item.id, 1)
      end
      # Grab the data from the selected item
      @item = @warp_window.item
      # Turn on the warp point's switch (if defined)
      if @item[4] != nil
        $game_switches[@item[4]] = true
      end
      # If the warp point's target isn't the same as the current map...
      if $game_map.map_id != @item[1]
        # Change the current map.
        $game_map.setup( @item[1] )
      end
      $game_player.moveto( @item[2][0], @item[2][1])
      case @item[3]
      when 2  # Down.
        $game_player.turn_down
      when 4  # Left.
        $game_player.turn_left
      when 6  # Right.
        $game_player.turn_right
      when 8  # Up.
        $game_player.turn_up
      end
      # Set the animation step back to idle
      $game_player.straighten
      # Wake the new map up
      $game_map.refresh
      $game_map.update
      # Play the map's music
      $game_map.autoplay
      # Reset the frame
      Graphics.frame_reset
      $scene = Scene_Map.new
      return
    end
  end
end
#==============================================================================
#  The Skill equivalent of the mod above.
#==============================================================================
class Scene_Skill
  alias ws2_main main
  alias ws2_update_skill update_skill
  alias ws2_update update
  def main
    ws2_main
    if @warp_window != nil
      @warp_window.dispose
    end
  end
  def update
    if @warp_window != nil
      @warp_window.update
      update_warp
      return
    end
    ws2_update
  end

  def update_skill
    # When C is pressed
    if Input.trigger?(Input::C)
      # Grab the data from the selected skill
      @skill = @skill_window.skill
      unless @skill == nil
        # Check if it's a teleporter skill
        if @skill.element_set.include?($game_system.warp_element) and  @actor.skill_can_use?(@skill.id)
          if $game_system.warp_cant == 1
            # Play the error SE
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          # Play the confirm SE
          $game_system.se_play($data_system.decision_se)
          # Open the destination window
          @skill_window.active = false
          @skill_window.visible = false
          @warp_window = Window_Warp.new
          @help_window.set_text( $game_system.warp_mesage )
          return
        end
      end
    end
    ws2_update_skill
  end

  def update_warp
    # When B is pressed
    if Input.trigger?(Input::B)
      # Play the cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Kill the destination window
      @skill_window.active = true
      @skill_window.visible = true
      @warp_window.dispose
      @warp_window = nil
      return
    end
    # When C is pressed
    if Input.trigger?(Input::C)
      if @warp_window.item == nil
        # Play the error SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play the skill's SE
      $game_system.se_play(@skill.menu_se)
      # If it costs SP, subtract it now
      @actor.sp -= @skill.sp_cost
      # Grab the warp point info
      @item = @warp_window.item
      # Set the warp point's switch, if defined
      if @item[4] != nil
        $game_switches[@item[4]] = true
      end
      # If the current map is different from the warp point's...
      if $game_map.map_id != @item[1]
        # Go there
        $game_map.setup( @item[1] )
      end
      $game_player.moveto( @item[2][0], @item[2][1])
      case @item[3]
      when 2  # Down.
        $game_player.turn_down
      when 4  # Left.
        $game_player.turn_left
      when 6  # Right.
        $game_player.turn_right
      when 8  # Up.
        $game_player.turn_up
      end
      # Return to idle frame
      $game_player.straighten
      # Wake the map up
      $game_map.refresh
      $game_map.update
      # Play the new map's music
      $game_map.autoplay
      # Frame reset
      Graphics.frame_reset
      $scene = Scene_Map.new
      return
    end
  end
end
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Modified Audio Encryption Script avatarmonkeykirby 0 2,264 07-28-2008, 01:00 PM
Last Post: avatarmonkeykirby
  Rotimikid's Enemy level Script ShockWave 0 2,357 08-24-2007, 01:00 PM
Last Post: ShockWave
  Script switch management GubiD 0 2,133 08-19-2007, 01:00 PM
Last Post: GubiD
  Nice game over script Moghunter 0 2,217 07-18-2007, 01:00 PM
Last Post: Moghunter
  Animated Options Script Samo the thief 0 2,193 06-18-2007, 01:00 PM
Last Post: Samo the thief
  Luck Script Darklord3652 0 2,156 04-10-2007, 01:00 PM
Last Post: Darklord3652
  GameOver Menu Script sasuke89 0 2,097 06-08-2006, 01:00 PM
Last Post: sasuke89
  Weapon Levelling Script GoldenShadow 0 2,102 07-05-2005, 01:00 PM
Last Post: GoldenShadow
  Ammo Script Dubealex 0 2,123 05-27-2005, 01:00 PM
Last Post: Dubealex
  Item Detail Script jackatrades 0 2,248 05-19-2005, 01:00 PM
Last Post: jackatrades



Users browsing this thread: