- Joined
- May 8, 2013
- Messages
- 33
- Reaction score
- 2
- Primarily Uses
I can use $game_map.display_name to access the display name for the map I'm on, but how do I access the display name of any map?
map_id = 1
temporary_map = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
other_map_name = temporary_map.display_name
q[:location] = "#{@npc45_loc} "
loc_id = $game_variables[80] #The map ID NPC 45 is currently on, set by the NPCs Common Event)
loc_map = load_data(sprintf(
"Data/Map%03d.rvdata2", loc_id))
loc_name = loc_map.display_name
@npc45_loc = loc_name
module NPC_Locations
# This stores the dynamic locations of all npcs
# It needs to be filled with the 'keys' for each
# npc. A key looks like this - :some_name - if
# you copy the examples below you should be fine.
# You can leave the location blank if want like
# example #2
@@locations = {
:npc45 => "camp"
:new_npc => ""
}
# This links the npcs to their corresponding id
# in $game_variables
# Every npc present above needs an entry here
@@npc_game_vars = {
:npc45 => 80
:new_npc => 1
}
# To then make the quest journal reference our npcs
# we use the following:
# q[:location] = NPC_Locations[:npc45]
# Obviously, replace :npc45 with whatever npc key you need
def self.[](name)
@@locations[name]
end
def self.[]=(id, newvar)
@@locations[id].clear
@@locations[id] << newvar
end
def self.update_all()
@@locations.each_key do |key|
loc_id = $game_variables[ @@npc_game_vars[key] ]
loc_map = load_data(sprintf("Data/Map%03d.rvdata2", loc_id))
loc_name = loc_map.display_name
NPC_Locations[key] = loc_name
end
end
end
class Scene_Quest < Scene_MenuBase
# Create an alias for the old method so we can call it
alias MA_start start
# Add our code to the scene start method
def start
# Call the original method
MA_start
# Call our update code
NPC_Locations.update_all()
end
end
module DataManager
#--------------------------------------------------------------------------
# * Create Wrapper Class
#--------------------------------------------------------------------------
class AAKHash
def initialize(default = nil)
@data = default || {}
end
def [](key)
@data[key] || 0
end
def []=(key, value)
@data[key] = value
end
end
#--------------------------------------------------------------------------
# * Create Game Objects
#--------------------------------------------------------------------------
class << self
alias create_game_objects_tablelist_base create_game_objects
end
def self.create_game_objects
create_game_objects_tablelist_base
$npcs = AAKHash.new
$cards = AAKHash.new
$guildloot = AAKHash.new
$dailysearch = AAKHash.new
$ingredients = AAKHash.new
end
#--------------------------------------------------------------------------
# * Create Save Contents
#--------------------------------------------------------------------------
class << self
alias make_save_contents_tablelist_base make_save_contents
end
def self.make_save_contents
contents = make_save_contents_tablelist_base
contents[:npcs] = $npcs
contents[:cards] = $cards
contents[:guildloot] = $guildloot
contents[:dailysearch] = $dailysearch
contents[:ingredients] = $ingredients
contents
end
#--------------------------------------------------------------------------
# * Extract Save Contents
#--------------------------------------------------------------------------
class << self
alias extract_save_contents_tablelist_base extract_save_contents
end
def self.extract_save_contents(contents)
extract_save_contents_tablelist_base(contents)
$npcs = contents[:npcs]
$cards = contents[:cards]
$guildloot = contents[:guildloot]
$dailysearch = contents[:dailysearch]
$ingredients = contents[:ingredients]
end
end
def self.update_all()
@@locations.each_key do |key|
loc_id = $game_variables[ @@npc_game_vars[key] ]
loc_map = load_data(sprintf("Data/Map%03d.rvdata2", loc_id))
loc_name = loc_map.display_name
NPC_Locations[key] = loc_name
end
end
def self.update_all()
@@locations.each_key do |key|
loc_id = $npcs[key] #### <<<< This one
loc_map = load_data(sprintf("Data/Map%03d.rvdata2", loc_id))
loc_name = loc_map.display_name
NPC_Locations[key] = loc_name
end
end
# To then make the quest journal reference our npcs
# we use the following:
# q[:location] = NPC_Locations[:npc45]
# Obviously, replace :npc45 with whatever npc key you need
q[:location] = "#{@npc45_loc}"
q[:location] = NPC_Locations[:npc45_loc]
q[:location] =
$npcs.each_key { |key|
print key
}
q[:location] =
when 1 # Quest 1 - SAMPLE QUEST
...
q[:location] = NPC_Locations[:npc1]
...
when 2 # Quest 2
...
q[:location] = NPC_Locations[:npc2]
...
when 3 # Quest 3
...
q[:location] = NPC_Locations[:npc3]
...
# To then make the quest journal reference our npcs
# we use the following:
# q[:location] = NPC_Locations[:npc45]
# Obviously, replace :npc45 with whatever npc key you need
That's my bad. I sometimes forget some of Ruby's rules. Just change every instance of "MA_start" to "ma_start" (there should be two).Next, I get an error in your code saying MA_start (found at the bottom) is an uninitialized constant.
def self.update_all()
@@locations.each_key do |key|
loc_id = $npcs[key]
if loc_id == 0
loc_name = "Unavailable"
else
loc_map = load_data(sprintf("Data/Map%03d.rvdata2", loc_id))
loc_name = loc_map.display_name
end
NPC_Locations[key] = loc_name
end
end
class Scene_Quest < Scene_MenuBase
# Create an alias for the old method so we can call it
alias ma_start start
# Add our code to the scene start method
def start
# Call our update code
NPC_Locations.update_all() #<< Swap these
# Call the original method
ma_start #<< two lines
end
end