Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
World Map & Teleporter
#1
World Map & Teleporter
by SephirothSpawn
Sep 16 2005


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.


Information on this Script:

The scripts basic function is to scroll through a World Map (In a Rotating Globe Format), a select your location. You can then teleport to your location if you desire.

Ive added in 3 Different ways to Select your locations:
1 - Move a Cursor over the location
2 - Auto-Scroll through your locations (Suggested By Makeamidget)
3 - Select through a Command Window (Suggested By Viskar)

Once, you Select a Location, You can Teleport to it. IF, you have the data setup correctly...

Setting up your Worlds!
This Script Supports Infinite World Possiblities with Inifinite Locations Within each world. :alright:

First, go into Scene_Title under def command_new_game, and in the $Game_blah loading section, add this:


Code:
$Game_Globe = Game_Globe.new



Now, I suggest Imidately, you add a World to this. (NOTE: If you dont need multiple Worlds, You'll only have to do this once) So right under that, add this:


Code:
$Game_Globe.add_world("Name of your World")



Now I also suggest adding your first location there. So under that, add this:


Code:
$Game_Globe.add_location(0, ["Name", rel_x, rel_y, id, x, y])



Heres where a little work on your part comes in (I cant do it all ;-)).

Replace Name with the Name of your location.
Replace Rel_x and Rel_y with the actuall x, y locations on your map, the scene will interpret. My suggestion is to open paint, move the cursor over where you want the location to appear, and copy those coordinates.

IF you want to be able to teleport to that location, Change the "id, x, y" to the Map Id and the x, y locations on the map you wish to be teleported to.

You will also have to take a screenshot (Alt + Prtscrn) of your locations, and scale it down to 320 * 240 Dimensions.

Now your ready to start your game. Open the Scene with this:


Code:
$scene = Scene_Globe.new(world_id)


Replace world_id with whatever id your world was stored in. Note: If your selecting the First world (one world users), you dont need to include (world_id) in the call script.

Your scene is there. Yah. Just follow Scene Instructions In the Controls Box.

Adding Locations
Now, "I want another Location!" Its easy. Just use a call script like this:


Code:
$Game_Globe.add_location(0, ["Name", rel_x, rel_y, id, x, y])


Look Familar? Same deal, just repeat instructions for your new location.


Removing Locations
"Oh no! Sephiroth Destroyed my town with Rataime's Destruction Engineā„¢." Now, you can remove your location with just as much ease.


Code:
$Game_Globe.remove_location(map, id)


Now again, youll have to do a little thinking. Replace map with the world your deleting the world from. And replace id, with the id location your removing it from. Note: You use Indexing postins for this, as in arrays!


The Demo

.zip   Globe_Map___Teleport_Script.zip (Size: 298.5 KB / Downloads: 2)

The Script
Code:
#================================
#Class Game_Globe
#Written by SephirothSpawn
#Defines your Worlds (@worlds)
#And Your Locations (@locatoins)
#================================
class Game_Globe
  attr_accessor :worlds, :locations
  def initialize
    @worlds = [];@locations = []
  end
  #---------------------------------------------------------------
  #Def Add_World (Adds World to your worlds list)
  #---------------------------------------------------------------
  def add_world(name)
    @worlds.push(name);@locations.push( [] )
  end
  #---------------------------------------------------------------
  #Def Remove_World (Removes a World)
  #---------------------------------------------------------------
  def remove_world(id)
    @worlds.delete_at(id);@locations.delete_at(id)
  end
  #---------------------------------------------------------------
  #Def Add_Location (Adds a locaction to a world)
  #Setup: (map, info)
  #Map = the id in your arrays  Example: @worlds = ["Spira", "Zanarkand"]
  #                                       To add "Besaid" to Spira, map would equal 0
  #Info = information of the Location
  #Info = ["Name of location", x, y, map_id, x2, y2]
  #"Name of Location = the Name of your location that will appear in the scene
  #x and y are the locations relative to the Top-Left corner of your screen
  #  To get x and y, Open Paint and your map. Move the cursor of the area
  #     on the map where your location will appear.
  #  The x & y coordinates will appear on the Bottom-Right Corner
  #map_id is the map id of the map to teleport to
  #x2 & y2 are the locations on the map where you will be teleported to
  #   If you dont want to make a location Teleportable, leave map_id, x2 & y2 = to nil (["Name", x, y])
  #---------------------------------------------------------------
  def add_location(map, info)
    @locations[map].push(info)
  end
  #---------------------------------------------------------------
  #Def Remove_Location (Removes a location from you loactions list)
  #map = World, Id is the location to delete  
  #     Example: @locations = [ [ ["Besaid", 5, 5, 0, 3, 10], ["Luca", 25, 30, 1, 10, 3] ], [World 2 Bios] ]
  #     Say Luca is destroyed by Sin. To remove, use (0, 1); 0 being your first world, 1 being your second location
  #---------------------------------------------------------------
  def remove_location(map, id)
    @locations[map].delete_at(id)
  end
end
#================================
#End of Game_Globe
#Start Scene_Globe
#================================
class Scene_Globe
  #------Sets Up Instance Varaibles------
  def initialize(world_id = 0)
    @world_id = world_id
    @locations = $Game_Globe.locations[world_id]
  end
  #------Sets Up Scene------
  def main
    #------Variable Setup------
    @x =320
    @y = 240
    @anim_curs = 0
    @dir = 1
    @phase = 0
    @temp_phase = 0
    @loc = 0
    @toggle = true
    commands = []
    for i in 0...@locations.size
      commands.push(@locations[i][0])
    end
    if commands.size >= 14
      height = 416
    else
      height = commands.size*32+32
    end
    #------Sprite Setup------
    bitmap = RPG::Cache.picture("Maps/"+$Game_Globe.worlds[@world_id])
    @map1 = Sprite.new
      @map1.bitmap = bitmap
    @map2 = Sprite.new
      @map2.bitmap = bitmap
    @globe = Sprite.new
      @globe.bitmap =  RPG::Cache.picture("Maps/Globe")
      @globe.z =  10
    @border = Window_Base.new(8, 232, 320, 240)
      @border.z = 16
      @border.back_opacity = 0
      @border.visible = false
    @tele_map = Sprite.new
      @tele_map.x = 8
      @tele_map.y = 232
      @tele_map.z = 15
    @cursor = Sprite.new
      @cursor.bitmap = RPG::Cache.picture("Maps/Cursor0")
      @cursor.x = @x - 16
      @cursor.y = @y - 16
      @cursor.z = 5
    #------Window Setup------
    @tele_cmd = Window_Command.new(160, ["Teleport", "Cancel"])
      @tele_cmd.x = 472
      @tele_cmd.y = 376
      @tele_cmd.z = 15
      @tele_cmd.opacity = 150
      @tele_cmd.active = @tele_cmd.visible = false
    @exit_cmd = Window_Command.new(200, ["Return to Menu", "Return to Map", "Cancel"])
      @exit_cmd.x = 432
      @exit_cmd.y = 344
      @exit_cmd.z = 15
      @exit_cmd.opacity = 150
      @exit_cmd.active = @exit_cmd.visible = false
    @list_cmd = Window_Command.new(196, commands)
      @list_cmd.height = height
      @list_cmd.x = 8
      @list_cmd.y = 240 - (height/2)
      @list_cmd.z = 15
      @list_cmd.opacity = 150
      @list_cmd.visible = @list_cmd.active = false
    @title = Window_Help.new
      @title.opacity, = 0
      @title.set_text($Game_Globe.worlds[@world_id], 1)
    @location = Window_Help.new
      @location.y = 416
      @location.opacity = 0
      @location.visible = false
    @controls = Window_Controls.new
      @controls.opacity = 150
      controls = ["Y -> Auto Mode", "Z -> List Mode", "A ->Toggle Control Window", "B -> Exit",
                       "C -> View Location (When Red)", "L & R -> Rotate Globe", "Arrows -> Move Cursor",
                       "Normal Mode"]
      @controls.refresh(controls)
    #------Quick Arrays Setup------
    @dispose = [@map1, @map2, @globe, @border, @tele_map, @cursor,
                       @tele_cmd, @exit_cmd, @list_cmd, @title, @location, @controls]
    @visible_change = [@border, @tele_map, @cursor, @tele_cmd, @exit_cmd, @list_cmd, @location]
    @active_change = [@tele_cmd, @exit_cmd, @list_cmd]
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @dispose.each {|x| x.dispose if !x.disposed?}
  end
  #------Updates Scene------
  def update
    @dispose.each {|x| x.update}
    @cursor.x =@x-16;@cursor.y = @y-16
    @anim_curs += @dir;@dir *= -1  if @anim_curs == 25 or @anim_curs == 0
    @cursor.bitmap = RPG::Cache.picture("Maps/Cursor0")  if @anim_curs ==0
    @cursor.bitmap = RPG::Cache.picture("Maps/Cursor3")  if @anim_curs == 5
    @cursor.bitmap = RPG::Cache.picture("Maps/Cursor1")  if @anim_curs == 10
    @cursor.bitmap = RPG::Cache.picture("Maps/Cursor4")  if @anim_curs == 15
    @cursor.bitmap = RPG::Cache.picture("Maps/Cursor2")  if @anim_curs == 20
    @cursor.bitmap = RPG::Cache.picture("Maps/Cursor5")  if @anim_curs == 25
    @map2.x = (@map1.x - 640) if @map1.x >= 0
    @map2.x = (@map1.x + 640) if @map1.x > 0
    @map1.x=0 if @map1.x==-640 or @map1.x==640
    @visible_change.each {|x| x.visible = false}
    @active_change.each {|x| x.active = false}
    @cursor.visible = true if @phase < 4
    @location.visible = true if @phase < 4
    @controls.visible = false if @phase > 2
    case @phase
     when 0
       normal_mode
     when 1
       midge_mode
     when 2
       @list_cmd.visible = @list_cmd.active = true
       list_mode
     when 3
       @border.visible = @tele_map.visible = true
       @tele_cmd.visible = @tele_cmd.active = true
       tele_mode
     when 4
       @exit_cmd.visible = @exit_cmd.active = true
       exit_mode
    end
  end
  #------Move Cursors over Location------
  def normal_mode
    controls = ["Y -> Auto Mode", "Z -> List Mode", "A ->Toggle Control Window", "B -> Exit",
                     "C -> View Location (When Red)", "L & R -> Rotate Globe", "Arrows -> Move Cursor",
                     "Normal Mode"]
    @controls.refresh(controls)
    @controls.visible = true if @toggle
    @controls.visible = false if !@toggle
    if Input.trigger?(Input::A)
      if @toggle then @toggle = false else @toggle = true end
    end
    if Input.trigger?(Input::B)
      @temp_phase = 0;@phase = 4
    end
    if Input.press?(Input::L)
      @map1.x -= 4;@map2.x -=4
    end
    if Input.press?(Input::R)
      @map1.x += 4;@map2.x +=4
    end
    @x +=2 if Input.press?(Input::RIGHT) and @x < 560
    @x -=2 if Input.press?(Input::LEFT) and @x > 80
    @y +=2 if Input.press?(Input::DOWN) and @y < 480
    @y -=2 if Input.press?(Input::UP) and @y > 0
    @phase = 1  if Input.trigger?(Input::Y)
    @phase = 2  if Input.trigger?(Input::Z)
    x1 = @x - @map1.x
    x2 = @x - @map2.x
    y1 = @y
    for i in 0...@locations.size
      x = @locations[i][1]
      y = @locations[i][2]
      if (x1<=x+16 and x1>=x-16 and y1<=y+16 and y1>=y-16)  or  (x2<=x+16 and x2>=x-16 and y1<=y+16 and y1>=y-16)
        @cursor.tone = Tone.new(255, 0, 0, 255);@location.visible = true
        @location.set_text(@locations[i][0], 1)
        if Input.trigger?(Input::C)
          @temp_loc = @locations[i]
          @tele_map.bitmap = RPG::Cache.picture("Maps/"+@locations[i][0])
          @temp_phase = 0;@phase = 3
        end
        return
      else
        @cursor.tone = Tone.new(0, 0, 0, 255);@location.visible = false
      end
    end
  end
  #------Scrolls Through Locations Automatically------
  # ------Thanks to Makeamidget for Suggestion------
  def midge_mode
    controls = ["X -> Normal Mode", "Z -> List Mode", "A ->Toggle Control Window", "B -> Exit",
                     "C -> View Location (When Red)", "Left or Right -> Next Location", "", "Auto Mode"]
    @controls.refresh(controls)
    @cursor.tone = Tone.new(255, 0, 0, 255)
    @location.set_text(@locations[@loc][0], 1)
    @controls.visible = true if @toggle
    @controls.visible = false if !@toggle
    if Input.trigger?(Input::A)
      if @toggle then @toggle = false else @toggle = true end
    end
    if Input.trigger?(Input::B)
      @temp_phase = 0;@phase = 4
    end
    @phase = 0  if Input.trigger?(Input::X)
    @phase = 2  if Input.trigger?(Input::Z)
    if Input.trigger?(Input::RIGHT)
      @loc += 1 if @loc <= @locations.size - 1;@loc = 0 if @loc > @locations.size - 1
    end
    if Input.trigger?(Input::LEFT)
      @loc = @locations.size - 1 if @loc == 0;@loc -= 1 if @loc != 0
    end
    @x = 320
    @y = @locations[@loc][2]
    @map1.x = 320 - @locations[@loc][1]
    if Input.trigger?(Input::C)
      @temp_loc = @locations[@loc]
      @tele_map.bitmap = RPG::Cache.picture("Maps/"+@locations[@loc][0])
      @temp_phase = 1;@phase = 3
    end
  end
  #------Show Locations in Command Window------
  #   ------Thanks to Viskar for Suggestion------
  def list_mode
    controls = ["X -> Normal Mode", "Y -> Auto Mode", "A ->Toggle Control Window", "B -> Exit",
                     "C -> View Location (When Red)", "Up or Down-> Next Location", "", "List Mode"]
    @controls.refresh(controls)
    @cursor.tone = Tone.new(255, 0, 0, 255)
    @controls.visible = true if @toggle
    @controls.visible = false if !@toggle
    if Input.trigger?(Input::A)
      if @toggle then @toggle = false else @toggle = true end
    end
    if Input.trigger?(Input::B)
      @temp_phase = 0;@phase = 4
    end
    @phase = 0  if Input.trigger?(Input::X)
    @phase = 1  if Input.trigger?(Input::Y)
    loc = @list_cmd.index
    @location.set_text(@locations[loc][0], 1)
    @x =320
    @y = @locations[loc][2]
    @map1.x = 320 - @locations[loc][1]
    if Input.trigger?(Input::C)
      @temp_loc = @locations[loc]
      @tele_map.bitmap = RPG::Cache.picture("Maps/"+@locations[loc][0])
      @temp_phase = 1;@phase = 3
    end
  end
  #------Teleport to Location------
  def tele_mode
    @phase = @temp_phase  if Input.trigger?(Input::B)
    teleport = true
    if @temp_loc[3] == nil
      teleport = false;@tele_cmd.disable_item(0)
    end
    if Input.trigger?(Input::C)
      case @tele_cmd.index
        when 0
          if teleport
            $game_map.setup(@temp_loc[3]);$game_player.moveto(@temp_loc[4], @temp_loc[5])
            $scene=Scene_Map.new;$game_map.refresh
          else
            $game_system.se_play($data_system.buzzer_se)
          end
        when 1
          @phase = @temp_phase
      end
    end
  end
  #------Returns to Game------
  def exit_mode
    @phase = @temp_phase  if Input.trigger?(Input::B)
    if Input.trigger?(Input::C)
      case @exit_cmd.index
        when 0;$scene = Scene_Menu.new
        when 1;$scene = Scene_Map.new
        when 2;@phase = @temp_phase
      end
    end
  end
  #---------------------------------------------------------------
end
#================================
#End of Scene_Globe
#Start Of Window_Controls
#================================
class Window_Controls < Window_Base
  #------Window Parameters------
  def initialize
    super(412, 264, 220, 208)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
  end
  #------Uses text (array) to Draw Text via .refresh------
  def refresh(text)
    self.contents.clear
    self.contents.font.size = 32;self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 208, 32, "Controls:")
    for i in 0...text.size
      if i < text.size - 1
        self.contents.font.color = normal_color;x = 6;self.contents.font.size = y = 16
      else
        self.contents.font.color = knockout_color;x = 0;self.contents.font.size = 32
      end
      cx = contents.text_size(text[i]).width;cy = contents.text_size(text[i]).height
      self.contents.draw_text(x, y*i + 32, cx, cy, text[i])
    end
  end
end



Have Fun with it! Any other Ideas?

SephirothSpawn
}




Users browsing this thread: