Teleportation Script

Started by Sagi007, August 02, 2015, 06:17:03 pm

Previous topic - Next topic

Sagi007

August 02, 2015, 06:17:03 pm Last Edit: August 02, 2015, 07:02:47 pm by KK20
Im looking for a teleportation script for RPG Maker XP
i tried Teleportation from Shdwlink http://forum.chaos-project.com/index.php/topic,2663.0.html
It was good but not totaly to my liking.

Then i came across XS Teleport for VX Ace. http://www.rpgmakervxace.net/topic/829-xs-teleport/
it was Perfect it had everything. So for the last few days ive  altered Shdwlink's script to add
those extra things.(3th window and file from Graphics/Pictures) atleast try to...

Spoiler: ShowHide
 

def add_location(name, map, x, y, face, desc = '', pic = '')
   unless @known_locs == []
     @known_locs.each_index {|i| return if name == @known_locs[i][0] }
   end
   @known_locs.push([name, map, x, y, face, desc, pic = '', true])
 end


Idea is to use pic = ''  as a reference to Graphics/Pictures/ ????

I know this issnt the right code. But it works and show said picture on the right coords and dissapears when i close windows but with this as a location it is stuck on 1 pictureand will never change.
Spoiler: ShowHide
 

class Graphic_Sprite
 def initialize
 @map = Sprite.new
 @map.bitmap = Bitmap.new('Graphics/Pictures/Map_Test')
 @map.x = 264
 @map.y = 80
 @map.z = 103
end



Last spoiler promise :)
contains the modded version of script as im working on altering.
coupple of stuff is blocked by =being =end. those are there from origin but surve no real purpose till done.
Spoiler: ShowHide


#==============================================================================
# Teleportation
# Author: Shdwlink1993
# Version: 1.1
# Type: Game Addon
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Teleport Date 1.0: 2/1/2009
# Teleport Date 1.1: 2/5/2009
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# #  This work is protected by the following license:
# #----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #----------------------------------------------------------------------------
# #
# # Note that if you share this file, even after editing it, you must still
# # give proper credit to shdwlink1993.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
#                                ~= Functions =~
#
# This script allows you to teleport to predefined locations, not unlike RPG
# Maker 2003's similar function.
#
# $game_player.add_location(name, map, x, y, face, description)
#   Adds a location to the list of teleportable locations. You cannot add a
# location if it's name is already in use (limit duplicates). Face refers to
# the direction the player will be facing. If you don't know, look at a number
# pad. 2 is down, 4 left, etc.
#
# $game_player.add_here(name, description)
#   Adds a location to the list where you are with the designated name and
# description.
#
# $game_player.remove_location(name)
#   Removes a location with the name from the list of teleportable locations.
#
# $game_player.disable_location(name)
#   Disallows you to teleport to the location with the name. This should be
#  used only in instances where the teleport is to be temporarily disabled. If
#  it should be permanently disabled, use the remove_location command to free
#  space.
#
# $game_player.enable_location(name)
#   Allows you to teleport to the disabled location with the name.
#
# $game_player.toggle_location(name)
#   Changes if the location with the name can be teleported to or not.
#
# $game_player.backup_locations
#   Makes a backup of all known locations and deletes them.
#
# $game_player.restore_locations
#   Restores the locations from the backup. All locations learned in the backup
#  are added to the list.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
#                               ~= Version History =~
#
# Version 1.0 ------------------------------------------------------ [2/1/2009]
# Version 1.1 ------------------------------------------------------ [2/5/2009]
#  - Added in ability to disable individual teleports.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
#                               ~= Compatability =~
#
# - Should work perfectly with just about anything.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#Added: 3th screen with Map Picture. Functions properly just cant swap picture.


class Game_System
 
 attr_accessor :teleport_disabled
 
 alias teleinit initialize
 def initialize
   teleinit
   @teleport_disabled = false
 end
 
end

class Game_Player
 
 attr_reader :known_locs
 
 alias teleinit initialize
 def initialize
   teleinit
   @known_locs = []
   @backup_locs = []
 end
=begin
 def add_here(name, desc = '')
   return add_location(name, $game_map.map_id, @x, @y, @direction, desc)
 end
=end
 def add_location(name, map, x, y, face, desc = '', pic = '')
   unless @known_locs == []
     @known_locs.each_index {|i| return if name == @known_locs[i][0] }
   end
   @known_locs.push([name, map, x, y, face, desc, pic = '', true])
 end
=begin
 def remove_location(name)
   @known_locs.each_index {|i|
     if name == @known_locs[i][0]
       @known_locs.delete(@known_locs[i])
       return
     end}
 end

 def disable_location(name)
   @known_locs.each_index {|i|
     if name == @known_locs[i][0]
       @known_locs[i][6] = false
       return
     end}
 end

 def enable_location(name)
   @known_locs.each_index {|i|
     if name == @known_locs[i][0]
       @known_locs[i][6] = true
       return
     end}
 end

 def toggle_location(name)
   @known_locs.each_index {|i|
     if name == @known_locs[i][0]
       @known_locs[i][6] = !@known_locs[i][6]
       return
     end}
 end
   
 def backup_locations
   @backup_locs = @known_locs
   @known_locs = []
 end
 
 def restore_locations
   @known_locs & @backup_locs
   @backup_locs = []
 end
=end
end

class Window_Teleport < Window_Selectable
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------

 def initialize
   super(0, 64, 250, 416)
   refresh
   self.index = 0
 end
 #--------------------------------------------------------------------------
 # * Get Item
 #--------------------------------------------------------------------------
 def item
   return @data[self.index]
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   if self.contents != nil
     self.contents.dispose
     self.contents = nil
   end
   @data = []
   $game_player.known_locs.each {|t| @data.push(t) }
   # If item count is not 0, make a bit map and draw all items
   @item_max = @data.size
   if @item_max > 0
     self.contents = Bitmap.new(width - 32, height - 32)
     @item_max.times {|i| draw_item(i) }
   end
 end
 #--------------------------------------------------------------------------
 # * Draw Item
 #     index : item number
 #--------------------------------------------------------------------------
 def draw_item(index)
   item = @data[index]
   if item[6]
     self.contents.font.color = normal_color
   else
     self.contents.font.color = disabled_color
   end
   x = 4
   y = index * 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, y, 228, 32, item[0], 0)
 end
 #--------------------------------------------------------------------------
 # * Help Text Update
 #--------------------------------------------------------------------------
 def update_help
   @help_window.set_text(self.item == nil ? '' : self.item[5])
 end
end

#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays amount of gold.
#==============================================================================

class Window_Map_Picture < Window_Selectable
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
def initialize
super(250, 64, 390, 416)
refresh
end

 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
  def refresh
  end
end

class Graphic_Sprite
 def initialize
 @map = Sprite.new
 @map.bitmap = Bitmap.new('Graphics/Pictures/Map_Test')
 @map.x = 264
 @map.y = 80
 @map.z = 103
end

def update
end
 def dispose
   @map.dispose
   end
end




class Scene_Teleport
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 def main
   # Make help window, item window
   @help_window = Window_Help.new
   @teleport_window = Window_Teleport.new
   @map_picture = Window_Map_Picture.new
   
   @map = Graphic_Sprite.new

 
   # Associate help window
   @teleport_window.help_window = @help_window
   # Execute transition
   Graphics.transition
   # Main loop
   loop {
     # Update game screen
     Graphics.update
     # Update input information
     Input.update
     # Frame update
     update
     # Abort loop if screen is changed
     break if $scene != self
   }
   # Prepare for transition
   Graphics.freeze
   # Dispose of windows
   @help_window.dispose
   @teleport_window.dispose
   @map_picture.dispose
   @map.dispose
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   # Update windows
   @help_window.update
   @teleport_window.update
   @map_picture.update
   update_tele
 end
 #--------------------------------------------------------------------------
 # * Frame Update (when item window is active)
 #--------------------------------------------------------------------------
 def update_tele
   # If B button was pressed
   if Input.trigger?(Input::B)
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Switch to menu screen
     $scene = Scene_Menu.new(0)
     return
   end
   # If C button was pressed
   if Input.trigger?(Input::C)
     # Get currently selected data on the item window
     @item = @teleport_window.item
     # If you can't teleport, then you don't!
     unless @item[6]
       $game_system.se_play($data_system.buzzer_se)
       return
   end
     # Play decision SE
     $game_system.se_play($data_system.decision_se)
     $game_temp.player_transferring = true
     # Set player move destination
     $game_temp.player_new_map_id = @item[1]
     $game_temp.player_new_x = @item[2]
     $game_temp.player_new_y = @item[3]
     $game_temp.player_new_direction = @item[4]
     $scene = Scene_Map.new
     return
   end
 end
end




If someone could help me with this i would realy appreciate it.

KK20

*added code tags*

I whipped this up fairly quick. It's an updated Window_Map_Picture and Scene_Teleport, so go ahead and replace the ones in your project with these:
Spoiler: ShowHide

#==============================================================================
# ** Window_Map_Picture
#==============================================================================
class Window_Map_Picture < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(250, 64, 390, 416)
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    @map_filename = ''
  end
 
  def update(picture_filename)
    if @map_filename != picture_filename
      if picture_filename == ''
        self.contents.clear
      else
        bmap = RPG::Cache.picture(picture_filename)
        #drect = Rect.new(0,0,self.width - 32, self.height - 32)
        #self.contents.stretch_blt(drect,bmap, Rect.new(0,0,bmap.width,bmap.height))
        self.contents.blt(0,0,bmap, Rect.new(0,0,bmap.width,bmap.height))
      end
      @map_filename = picture_filename
    end
    super()
  end

end


class Scene_Teleport
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window, item window
    @help_window = Window_Help.new
    @teleport_window = Window_Teleport.new
    @map_picture = Window_Map_Picture.new

    # Associate help window
    @teleport_window.help_window = @help_window
    # Execute transition
    Graphics.transition
    # Main loop
    loop {
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      break if $scene != self
    }
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @help_window.dispose
    @teleport_window.dispose
    @map_picture.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @help_window.update
    @teleport_window.update
    @map_picture.update(@teleport_window.item[6])
    update_tele
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_tele
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @teleport_window.item
      # If you can't teleport, then you don't!
      unless @item[7]
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      $game_temp.player_transferring = true
      # Set player move destination
      $game_temp.player_new_map_id = @item[1]
      $game_temp.player_new_x = @item[2]
      $game_temp.player_new_y = @item[3]
      $game_temp.player_new_direction = @item[4]
      $scene = Scene_Map.new
      return
    end
  end
end

Also, in your add_location method, change this line

@known_locs.push([name, map, x, y, face, desc, pic = '', true])

to

@known_locs.push([name, map, x, y, face, desc, pic, true])


Now for the explanation. Originally you had Window_Map_Picture as a child of Window_Selectable--I immediately removed this and turned it back to Window_Base since we are not really selecting anything in it; its sole purpose is to display an image. I create a variable @map_filename to keep track of what image file we are currently showing the player.

The update method takes in a picture filename. If it's not the same as what we are currently showing the player, we change the image and set @map_filename to the now current filename.

In Scene_Teleport, under the update method, I pass along @teleport_window.item[6] to @map_picture.update. item[6] refers to the image filename according to this

                       0     1   2  3   4     5     6    7
    @known_locs.push([name, map, x, y, face, desc, pic, true])


So every frame, we are constantly passing the image filename the player's cursor is currently pointing to on the teleport list. Our window will then draw the image if necessary.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Sagi007