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.

Overall and final Question of Transferring

Ok, awesome, I asked two questions and got answers I needed, but now, I need to combine those two questions, in a way to speak. Anyway, someone gave me a good script/demo to a waypoint thing, and someone gave me good directions to how to make a way to use a boat to transport people, but heres my big question.

Heres my problem,
Ok when you go to the first city and talk to the boat porter, hes supose to give you a list of places you can fly to, only, its not supose to give you all the towns yet, it should only give you that one town that your in, cause thats the only port you have been to. But, once you go to the second town and talk to the porter there, it should give you a list, and on the list it should have the first town, then you would click that, but instead of sending you directly to the destination, it should put you on a boat then after about 5 minutes (not game time) it should tell you, We are here!, then transferr you infront of the porter in that town.

How do I do this????
 

khmp

Sponsor

Its odd that you mention it. I was just helping someone doing something similar. Your answer, I guess, will be a little shorter. You will need a script though, hope you don't mind.
Code:
#============================================================================
# ** Game_Towns
#----------------------------------------------------------------------------
#  This class holds the possible towns that the player can go to. Refer to 
#  "$game_towns" for the instance of this class.
#============================================================================
class Game_Towns
  # If the user has invoked traveling instead of direct travel this will be
  # true.
  attr_reader :traveling
  #--------------------------------------------------------------------------
  # * Initialization
  #--------------------------------------------------------------------------
  def initialize
    @towns, @traveling, @send_to = Hash.new, false, nil
  end
  #--------------------------------------------------------------------------
  # * Add Town
  #     town_name : name of the town you want to change.
  #     map_id : the id of the map where the town is located.
  #     x : the x location of where you want to appear on the map.
  #     y : the y location of where you want to appear on the map.
  #--------------------------------------------------------------------------
  def add_town(town_name, map_id, x, y)
    @towns[town_name] = [map_id,x,y]
  end
  #--------------------------------------------------------------------------
  # * Remove a Town
  #     town_name : name of the town you want to remove.
  #--------------------------------------------------------------------------
  def remove_town(town_name)
    @towns.delete(town_name)
  end
  #--------------------------------------------------------------------------
  # * Going to
  #     town_name : name of the town you will eventually travel to.
  #     t_map_id : the id of the map where you will be sent to before hand.
  #     t_x : the x location of where you will appear on the traveling map.
  #     t_y : the y location of where you will appear on the traveling map.
  #--------------------------------------------------------------------------
  def going_to(town_name, t_map_id, t_x, t_y)
    @traveling = true
    @send_to = town_name
    
    # Rather than check to see if anything else is nil just check the player.
    return if $game_player == nil
    
    # Return if there is no such town by that name.
    return if !@towns.has_key?(town_name)
    
    # Reset the frame counter
    Graphics.frame_count = 0
    
    # Set up the map and move the player to it.
    $game_map.setup(t_map_id)
    $game_player.moveto(t_x, t_y)
    
    # Refresh player
    $game_player.refresh
    # Run automatic change for BGM and BGS set with map
    $game_map.autoplay
    # Update map (run parallel process event)
    $game_map.update
    # Switch to map screen
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # * Go to a Town
  #     town_name : name of the town you want to travel to.
  #--------------------------------------------------------------------------
  def goto_town(town_name = @send_to)
    # Rather than check to see if anything else is nil just check the player.
    return if $game_player == nil
    
    # Return if there is no such town by that name.
    return if !@towns.has_key?(town_name)
    
    @traveling = false if @traveling
    
    # Reset the frame counter
    Graphics.frame_count = 0
    
    # Set up the map and move the player to it.
    $game_map.setup(@towns[town_name][0])
    $game_player.moveto(@towns[town_name][1], @towns[town_name][2])
      
    # Refresh player
    $game_player.refresh
    # Run automatic change for BGM and BGS set with map
    $game_map.autoplay
    # Update map (run parallel process event)
    $game_map.update
    # Switch to map screen
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # * Get the Towns
  #     excluded_name : the name you want excluded from the list of towns.
  #--------------------------------------------------------------------------
  def get_towns(excluded_name = nil)
    # If no allegiance was specified return all the towns.
    towns = @towns.keys
    towns.delete(excluded_name) if excluded_name
    return towns
  end
end

#============================================================================
# ** Window_Command
#----------------------------------------------------------------------------
#  This window deals with general command choices.
#============================================================================
class Window_Command
  attr_reader :commands
end

#============================================================================
# ** Window_Town
#----------------------------------------------------------------------------
#  This window deals just shows Town text
#============================================================================
class Window_Town < Window_Base
  AVAILABLE_TOWNS = 'Available Towns'
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x : the x coordinate where the window will appear.
  #     y : the y coordinate where the window will appear.
  #     width : the width of the window.
  #     height : the height of the window.
  #--------------------------------------------------------------------------
  def initialize(x,y,width,height)
    super(x,y,width,height)
    self.contents = Bitmap.new(width - 32,height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Redraws the window contents.
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, width - 32, 32, AVAILABLE_TOWNS, 1)
  end
end

#============================================================================
# ** Scene_TownSelection
#----------------------------------------------------------------------------
#  This class provides the user with the ability to change the towns.
#============================================================================
class Scene_TownSelection
  # The name that will be excluded in the list of towns.
  attr_accessor :excluded_name
  #--------------------------------------------------------------------------
  # * Scene Main
  #--------------------------------------------------------------------------
  def main
    # Create a background.
    @background = Spriteset_Map.new
    
    # Create the collection of towns the player can go to.
    @towns = Window_Command.new(200,$game_towns.get_towns(excluded_name))
    @towns.x = (640 / 2) - (@towns.width / 2)
    @towns.y = 100
    @towns.opacity = 140
    
    # Create the window that only displays a line of text.
    @town = Window_Town.new(@towns.x, @towns.y - 64, @towns.width, 64)
    @town.opacity = @towns.opacity
    
    # Graphics.transition to break the last Graphics.freeze
    Graphics.transition
    
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    
    # Create a lead in for the next scene.
    Graphics.freeze
    
    # Dispose of the disposables.
    @background.dispose
    @towns.dispose
    @town.dispose
  end
  #--------------------------------------------------------------------------
  # * Traveling
  #     t_map_id : the id of the map that you will be on while traveling.
  #     t_x : the x position where the player will start at in the map.
  #     t_y : the y position where the player will start at in the map.
  #--------------------------------------------------------------------------
  def travel(t_map_id = 1, t_x = 0, t_y = 0)
    @traveling = true
    @t_map_id, @t_x, @t_y = t_map_id, t_x, t_y
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update the window.
    @towns.update
    # If the user has selected a town send him there.
    if Input.trigger?(Input::C)
      # If the user called the method, 'travel' assume we are temporarily
      # going to another map before traveling to the final destination.
      if @traveling
        $game_towns.going_to(@towns.commands[@towns.index],@t_map_id,@t_x,@t_y)
        @traveling = false
      else
        $game_towns.goto_town(@towns.commands[@towns.index]) 
      end
    end
    # Break the scene if the user hits the B key.
    @traveling, $scene = false, Scene_Map.new if Input.trigger?(Input::B)
  end
end

#============================================================================
# ** Scene_Map
#----------------------------------------------------------------------------
#  This class performs map screen processing.
#============================================================================
class Scene_Map
  alias_method :old_main, :main
  alias_method :old_update, :update
  TIME_SPENT_TRAVELING = 50
  def main
    @time_spent_traveling = 0
    old_main
  end
  
  def update
    if $game_towns.traveling
      @time_spent_traveling += 1
      if @time_spent_traveling == TIME_SPENT_TRAVELING
        $game_towns.goto_town
        @time_spent_traveling = 0
      end
    end
    old_update
  end
end

#============================================================================
# ** Scene_Title
#----------------------------------------------------------------------------
#  This class performs title screen processing.
#============================================================================
class Scene_Title
  alias_method :old_main, :main
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # If battle test
    if $BTEST
      battle_test
      return
    end
    $game_towns = Game_Towns.new
    old_main
  end
end

#============================================================================
# ** Scene_Save
#----------------------------------------------------------------------------
#  This class performs save screen processing.
#============================================================================
class Scene_Save < Scene_File
  alias_method :old_write_save_data, :write_save_data
  #--------------------------------------------------------------------------
  # * Write Save Data
  #     file : write file object (opened)
  #--------------------------------------------------------------------------
  def write_save_data(file)
    old_write_save_data(file)
    # Added this to save the list of towns.
    Marshal.dump($game_towns, file)
  end
end

#============================================================================
# ** Scene_Load
#----------------------------------------------------------------------------
#  This class performs load screen processing.
#============================================================================
class Scene_Load < Scene_File
  #--------------------------------------------------------------------------
  # * Read Save Data (*!OVERRIDE!*)
  #     file : file object for reading (opened)
  #--------------------------------------------------------------------------
  def read_save_data(file)
    # Read character data for drawing save file
    characters = Marshal.load(file)
    # Read frame count for measuring play time
    Graphics.frame_count = Marshal.load(file)
    # Read each type of game object
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    # Added this line to load towns.
    $game_towns         = Marshal.load(file)
    # If magic number is different from when saving
    # (if editing was added with editor)
    if $game_system.magic_number != $data_system.magic_number
      # Load map
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    # Refresh party members
    $game_party.refresh
  end
end

First before you install this I will warn you by telling you that it overrides saving and loading. So if you were saving any custom objects I just invalidated them. Also any save game made before the institution of this code will be invalid. Sorry. :-/

Ok it works by utilizing the global: '$game_towns'.
Methods:
Code:
add_town(town_name, map_id, x, y)
remove_town(town_name)
goto_town(town_name)
get_town_names(excluded_name = nil)

Let's say you want to add a couple towns at the start:
Code:
$game_towns.add_town('TheShadowGuy', 1, 8, 7)
$game_towns.add_town('Awesom-o', 2, 10, 11)
$game_towns.add_town('TV Reference', 3, 14, 23)

Let's say you are in 'Awesom-o' and want to get somewhere else. Provide a command list to the player using this array:
Code:
$game_towns.get_town_names('Awesome-o')
I put Awesom-o as the excluded name because I don't want to see that in the list. Once the player has decided where next to go:
Code:
$game_towns.goto_town('TV Reference')

A little picture help as to how to actually get something going.
http://i229.photobucket.com/albums/ee31 ... _towns.jpg[/img]

Good luck with it TheShadowGuy! :thumb:
 
well, I didn't consider that teleporting was an real issue since I have found Trickster's Travel Menu.
I may need to change my version of the script after I took a look at this request.
Edit:
it's odd to see that another shadow asked for something like that... maybe it's part of any shadow's destiny he he he

anyway, I don't think he was trying to set any allegiance...
Code:
 def get_towns(excluded_name = nil)
    # If no allegiance was specified return all the towns.
    towns = @towns.keys
    towns.delete(excluded_name) if excluded_name
    return towns
  end
 

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