World/Location Window
Version: 1.0
By: Sailerius
Introduction
I wrote this for a game a friend of mine is making. It's nothing special, but it's my first script. So, I'm looking for comments on how to improve it and what I did right/wrong. I'm not too familiar with scripting conventions.
It shows a window at the top left of the screen that displays the name of the current world (or country, or island...) and below it the name of the map. The window can be hidden and displayed by manipulating a switch, whose ID number you specify.
Screenshots
Script
Instructions
Paste the script into a new slot above Main. Change the constants at the top to define what switch you're using for visibility and what variable you're using to store current world. Change the names of the worlds to whatever you want.
FAQ
---
Compatibility
Probably doesn't work with anything that modifies Scene_Map.
Author's Notes
I don't expect anyone to have a use for this. Just looking for feedback on how to script better.
Terms and Conditions
Free to use however you want. I don't know why you'd want to. Just be sure to credit me and let me know so I can see your game!
Version: 1.0
By: Sailerius
Introduction
I wrote this for a game a friend of mine is making. It's nothing special, but it's my first script. So, I'm looking for comments on how to improve it and what I did right/wrong. I'm not too familiar with scripting conventions.
It shows a window at the top left of the screen that displays the name of the current world (or country, or island...) and below it the name of the map. The window can be hidden and displayed by manipulating a switch, whose ID number you specify.
Screenshots

Script
Code:
#==============================================================================
# ** Window_Location
#------------------------------------------------------------------------------
# This window displays universe name and map name.
# Version 1.0
# Written by Sailerius
#
# Instructions: Define the constants below.
# You can make the location window visible/invisible by toggling the visibility switch.
# It will display the name of the current map.
# You can define what it says for each universe below.
#==============================================================================
class Window_Location < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
#--------------------------------------------------------------------------
# * Constants: Edit these values to customize
#--------------------------------------------------------------------------
$VISIBILITY_SWITCH = 1 # Enter the ID number of the switch used to determine window visibility
$WORLD_VAR = 1 # Enter the ID number of the variable used to determine current universe
#--------------------------------------------------------------------------
# * Values: Here, enter what you want the location window to display for each
# variable value. For example, for WORLD[1], enter what you want the universe
# section of the window to say when the variable is set to 1.
# Feel free to add more.
# NOTE: If you set the variable to a number not defined here, it'll probably crash.
#--------------------------------------------------------------------------
$WORLD=[]
$WORLD[0] = "Undefined"
$WORLD[1] = "Universe 1"
$WORLD[2] = "Universe 2"
$WORLD[3] = "Universe 3"
$WORLD[4] = "Universe 4"
$WORLD[5] = "Universe 5"
$WORLD[6] = "Universe 6"
#--------------------------------------------------------------------------
# Don't edit anything below here.
#--------------------------------------------------------------------------
super(0, 0, 160, 64) #96
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.size = 16
self.visible = $game_switches[$VISIBILITY_SWITCH]
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, -8, 120, 32, $WORLD[$game_variables[$WORLD_VAR]])
self.contents.font.color = normal_color
self.contents.draw_text(4, 4, 120, 32, $game_map.name, 1)
end
end
#==========================================================================
====
# * Game_Map
#==========================================================================
====
class Game_Map
def name
$map_infos[@map_id]
end
end
#==========================================================================
====
# * Scene_Title
#==========================================================================
====
class Scene_Title
# Enables ability to show map name on screen
$map_infos = load_data("Data/MapInfos.rxdata")
for key in $map_infos.keys
$map_infos[key] = $map_infos[key].name
end
end
#==========================================================================
====
# * Scene_Map
#==========================================================================
====
class Scene_Map
attr_accessor:location_window
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make sprite set
@spriteset = Spriteset_Map.new
# Make message window
@message_window = Window_Message.new
# Make location window
@location_window = Window_Location.new
@location_window.x = 0
@location_window.y = 0
# Transition run
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of sprite set
@spriteset.dispose
# Dispose of message window
@message_window.dispose
# Dispose of location window
@location_window.dispose
# If switching to title screen
if $scene.is_a?(Scene_Title)
# Fade out screen
Graphics.transition
Graphics.freeze
end
end
#--------------------------------------------------------------------------
# * Player Place Move
#--------------------------------------------------------------------------
def transfer_player
# Clear player place move call flag
$game_temp.player_transferring = false
# If move destination is different than current map
if $game_map.map_id != $game_temp.player_new_map_id
# Set up a new map
$game_map.setup($game_temp.player_new_map_id)
@location_window.refresh
end
# Set up player position
$game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
# Set player direction
case $game_temp.player_new_direction
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
# Straighten player position
$game_player.straighten
# Update map (run parallel process event)
$game_map.update
# Remake sprite set
@spriteset.dispose
@spriteset = Spriteset_Map.new
# If processing transition
if $game_temp.transition_processing
# Clear transition processing flag
$game_temp.transition_processing = false
# Execute transition
Graphics.transition(20)
end
# Run automatic change for BGM and BGS set on the map
$game_map.autoplay
# Frame reset
Graphics.frame_reset
# Update input information
Input.update
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Loop
loop do
# Update map, interpreter, and player order
# (this update order is important for when conditions are fulfilled
# to run any event, and the player isn't provided the opportunity to
# move in an instant)
$game_map.update
$game_system.map_interpreter.update
$game_player.update
# Update system (timer), screen
$game_system.update
$game_screen.update
# Abort loop if player isn't place moving
unless $game_temp.player_transferring
break
end
# Run place move
transfer_player
# Abort loop if transition processing
if $game_temp.transition_processing
break
end
end
# Update sprite set
@spriteset.update
# Update message window
@message_window.update
# Update location window
@location_window.update
# If game over
if $game_temp.gameover
# Switch to game over screen
$scene = Scene_Gameover.new
return
end
# If returning to title screen
if $game_temp.to_title
# Change to title screen
$scene = Scene_Title.new
return
end
# If transition processing
if $game_temp.transition_processing
# Clear transition processing flag
$game_temp.transition_processing = false
# Execute transition
if $game_temp.transition_name == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$game_temp.transition_name)
end
end
# If showing message window
if $game_temp.message_window_showing
return
end
# If encounter list isn't empty, and encounter count is 0
if $game_player.encounter_count == 0 and $game_map.encounter_list != []
# If event is running or encounter is not forbidden
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
# Confirm troop
n = rand($game_map.encounter_list.size)
troop_id = $game_map.encounter_list[n]
# If troop is valid
if $data_troops[troop_id] != nil
# Set battle calling flag
$game_temp.battle_calling = true
$game_temp.battle_troop_id = troop_id
$game_temp.battle_can_escape = true
$game_temp.battle_can_lose = false
$game_temp.battle_proc = nil
end
end
end
# If B button was pressed
if Input.trigger?(Input::B)
# If event is running, or menu is not forbidden
unless $game_system.map_interpreter.running? or
$game_system.menu_disabled
# Set menu calling flag or beep flag
$game_temp.menu_calling = true
$game_temp.menu_beep = true
end
end
# If debug mode is ON and F9 key was pressed
if $DEBUG and Input.press?(Input::F9)
# Set debug calling flag
$game_temp.debug_calling = true
end
# If player is not moving
unless $game_player.moving?
# Run calling of each screen
if $game_temp.battle_calling
call_battle
elsif $game_temp.shop_calling
call_shop
elsif $game_temp.name_calling
call_name
elsif $game_temp.menu_calling
call_menu
elsif $game_temp.save_calling
call_save
elsif $game_temp.debug_calling
call_debug
end
end
end
end
Instructions
Paste the script into a new slot above Main. Change the constants at the top to define what switch you're using for visibility and what variable you're using to store current world. Change the names of the worlds to whatever you want.
FAQ
---
Compatibility
Probably doesn't work with anything that modifies Scene_Map.
Author's Notes
I don't expect anyone to have a use for this. Just looking for feedback on how to script better.
Terms and Conditions
Free to use however you want. I don't know why you'd want to. Just be sure to credit me and let me know so I can see your game!