[Solved]RGSS3 to RGSS [RMAce to RMXP] script request

Started by MetalZelda, March 22, 2014, 07:41:57 am

Previous topic - Next topic

MetalZelda

March 22, 2014, 07:41:57 am Last Edit: March 27, 2014, 01:20:48 pm by MetalZelda
Hmmm, I don't know if someone would actually do it, but I suck in converting script ...
There we go. This script right here is to save an event position even if you go to another map. It's much more useful than having parallel process and switches to handle a new event position. Saving switches, and even some Framerate depending on how many things to memorize.

But, I only found a script that is VX Ace compatible, and need someone to convert into a regular RMXP one, it would be useful for many other makers using RPG Maker XP.

Here's the script, and I hope someone convert it for the communauty ^^

#--------------------------------------------------
# Remember Event Position 1.0
#--------------------------------------------------
#
# Author: Shaz
#
# Description: This script lets you set the position and direction
#              where an event will appear next time the map is
#              loaded.  Events will appear in this new position
#              rather than the place they were put during design.
#
#--------------------------------------------------
#
# Installation:
#
# Copy into a new script slot in the Materials section
#
#--------------------------------------------------
#
# Use:
#
# Examples below show syntax for an Event Command on an Event Tab.
#   You can use @event_id for the current event, or specify an event number.
# To execute from within a Set Move Route command, omit the
#   $game_map.events[@event_id]. part, and just use save_pos() and forget_pos().
#
# To tell an event to move to its current position the next time
# the map is loaded, execute the following in a script call:
#   $game_map.events[@event_id].save_pos()
#
# To tell an event to move to a particular position (not its
# current position) the next time the map is loaded,
# execute the following in a script call:
#   $game_map.events[@event_id].save_pos(1, 2, 8)
# - the above will move the event to x=1, y=2, facing up
#
# To tell an event to forget its previously remembered position
# and go back to its default position the next time time map
# is loaded, execute the following in a script call:
#   $game_map.events[@event_id].forget_pos()
#--------------------------------------------------

class Game_System
 alias shaz_mem_position_gs_init initialize

 attr_accessor :event_positions

 def initialize
   shaz_mem_position_gs_init
   @event_positions = {}
 end
end

# Check to ensure $game_system.event_positions exists (save files created
# prior to this script being added would not have it initialized)
class Game_Map
 alias shaz_mem_positions_gm_init initialize

 def initialize
   shaz_mem_positions_gm_init
   $game_system.event_positions = {} if !$game_system.event_positions
 end
end

class Game_CharacterBase
 attr_accessor
end

class Game_Event
 alias shaz_mem_position_gcb_init initialize

 def initialize(map_id, event)
   shaz_mem_position_gcb_init(map_id, event)

   if $game_system.event_positions.has_key?([map_id, @id])
     mvx, mvy, mvdir = $game_system.event_positions[[map_id, @id]]
     moveto(mvx, mvy)
     set_direction(mvdir) if mvdir
     @stop_count = 0
     refresh
   end
 end

 def save_pos(x = @x, y = @y, dir = @direction)
   $game_system.event_positions[[@map_id, @id]] = [x, y, dir]
 end

 def forget_pos
   $game_system.event_positions.delete([@map_id, @id])
 end
end



MetalZelda

Hmmmm, it works but when I relaunch the game the event's position reset.
Perhaps it's because I launch it in playtest mode ?

G_G

It's because the snippet Nathmatt made doesn't save the data into a save file. It only keeps track of event positions during the game. Here, I whipped this up real quick. It saves event positions between map transfers and it'll also ensure that the data gets saved into a save file.

#===============================================================================
# Remember Events Position
# Version 1.0
# Author gameus
#-------------------------------------------------------------------------------
# Intro:
# This will save an events position between map transfers and in save files, so
# next time you come to the map, any moving NPC will still be in its remembered
# spot.
#
# Features:
# Saves event positions
#
# Instructions:
# No configuration required, just plug-n-play.
#
# Compatibility:
# Shouldn't be any
# Not tested with SDK
#
# Credits:
# gameus ~ for creating it
# MetalZelda ~ for requesting it
#===============================================================================
class Game_Map
 
  attr_accessor :positions
 
  alias gg_init_event_positions_lat initialize
  def initialize
    @positions = {}
    gg_init_event_positions_lat
  end
 
  alias gg_save_event_positions_lat setup
  def setup(map_id)
    if @events != nil
      @positions[@map_id] = {} if @positions[@map_id] == nil
      @events.each_value { |event|
        @positions[@map_id][event.id] = [event.x, event.y] }
    end
    gg_save_event_positions_lat(map_id)
    if @positions[@map_id] != nil
      @events.each_value { |event|
        if @positions[@map_id][event.id] != nil
          x = @positions[@map_id][event.id][0]
          y = @positions[@map_id][event.id][1]
          event.moveto(x, y)
        end }
    end
  end
 
end

MetalZelda

March 29, 2014, 04:09:37 pm #5 Last Edit: March 29, 2014, 04:13:34 pm by MetalZelda
The genius of GG strikes again ...
Is it me or does this Forum have the best RM scripter xD

PS : No need to credit me for the request, I mean, it's for everyone in this forum. And I'm not the only one that requested it xD

G_G

I always credit people who request scripts. It just shows who came up with the idea or who asked for it. And I am definitely not the best RM scripter, there are definitely a handful of people here that are just as good, if not, better than me. ForeverZer0, KK20, Ryex, winkio, and LittleDrago. And as far as I'm concerned, Blizzard is still one of the top scripters here, it's just he's retired now.

Zexion


G_G


LiTTleDRAgo

ひまつぶし

Spoiler: ShowHide

# to clear event position in maps:
#     $game_map.event_positions[MAP_ID] = nil
# or
#     $game_map.event_positions.delete(MAP_ID)

# to clear event position in all maps:
#     $game_map.event_positions.clear


class Game_Map

  alias_method(:setup_eventmanager_alias, :setup)
  define_method(:event_positions) { @event_positions ||= {}}

  def setup(map_id)
    setup_eventmanager_alias(map_id)
    if self.event_positions[map_id]
      (@events = self.event_positions[map_id]) && refresh
    else
      (self.event_positions[map_id] = @events)
    end
  end
end

Wecoc

It's some sort of a great coincidence that I just did a script about this some hours ago and now I read this topic here.

But mine is different so I want to post it.

#==============================================================================
# ** Game Map Save Features v1.3
#------------------------------------------------------------------------------
#  Author: Wecoc
#==============================================================================

class Game_Maps
  EVENT_MAPS = [1, 2]
  PANORAMA_MAPS = [1, 2]
  FOG_MAPS = [1, 2]

  attr_accessor :data
  def initialize
    @data = []
  end

  def [](map_id)
    return @data[map_id]
  end

  def []=(map_id, value)
    @data[map_id] = value
  end

  def reset(map_id)
    @data[map_id] = nil
  end
end

class Game_Map
  attr_reader :fog_tone_target
  attr_reader :fog_tone_duration
  attr_reader :fog_opacity_target
  attr_reader :fog_opacity_duration

  def setup(map_id)
    @map_id = map_id
    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
    tileset = $data_tilesets[@map.tileset_id]
    @tileset_name = tileset.tileset_name
    @autotile_names = tileset.autotile_names
    @panorama_name = tileset.panorama_name
    @panorama_hue = tileset.panorama_hue
    if Game_Maps::PANORAMA_MAPS.include?(map_id)
      if $game_maps.data[map_id] != nil
        @panorama_name = $game_maps.data[map_id].panorama_name
        @panorama_hue = $game_maps.data[map_id].panorama_hue
      end
    end
    @fog_name = tileset.fog_name
    @fog_hue = tileset.fog_hue
    @fog_opacity = tileset.fog_opacity
    @fog_blend_type = tileset.fog_blend_type
    @fog_zoom = tileset.fog_zoom
    @fog_sx = tileset.fog_sx
    @fog_sy = tileset.fog_sy
    if Game_Maps::FOG_MAPS.include?(map_id)
      if $game_maps.data[map_id] != nil
        @fog_name = $game_maps.data[map_id].fog_name
        @fog_hue = $game_maps.data[map_id].fog_hue
        @fog_opacity = $game_maps.data[map_id].fog_opacity
        @fog_blend_type = $game_maps.data[map_id].fog_blend_type
        @fog_zoom = $game_maps.data[map_id].fog_zoom
        @fog_sx = $game_maps.data[map_id].fog_sx
        @fog_sy = $game_maps.data[map_id].fog_sy
      end
    end
    @battleback_name = tileset.battleback_name
    @passages = tileset.passages
    @priorities = tileset.priorities
    @terrain_tags = tileset.terrain_tags
    @display_x = 0
    @display_y = 0
    @need_refresh = false
    @events = {}
    for i in @map.events.keys
      @events[i] = Game_Event.new(@map_id, @map.events[i])
    end
    if Game_Maps::EVENT_MAPS.include?(map_id)
      if $game_maps.data[map_id] != nil
        @events = $game_maps.data[map_id].events
      end
    end
    @common_events = {}
    for i in 1...$data_common_events.size
      @common_events[i] = Game_CommonEvent.new(i)
    end
    @fog_ox = 0
    @fog_oy = 0
    @fog_tone = Tone.new(0, 0, 0, 0)
    @fog_tone_target = Tone.new(0, 0, 0, 0)
    @fog_tone_duration = 0
    @fog_opacity_target = 0
    @fog_opacity_duration = 0
    if Game_Maps::FOG_MAPS.include?(map_id)
      if $game_maps.data[map_id] != nil
        @fog_ox = $game_maps.data[map_id].fog_ox
        @fog_oy = $game_maps.data[map_id].fog_oy
        @fog_tone = $game_maps.data[map_id].fog_tone
        @fog_tone_target = $game_maps.data[map_id].fog_tone_target
        @fog_tone_duration = $game_maps.data[map_id].fog_tone_duration
        @fog_opacity_target = $game_maps.data[map_id].fog_opacity_target
        @fog_opacity_duration = $game_maps.data[map_id].fog_opacity_duration
      end
    end
    @scroll_direction = 2
    @scroll_rest = 0
    @scroll_speed = 4
  end

  def each_event(&block)
    @events.values.each{|event| yield event}
  end
end

class Scene_Title
  def command_new_game
    $game_system.se_play($data_system.decision_se)
    Audio.bgm_stop
    Graphics.frame_count = 0
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_switches      = Game_Switches.new
    $game_variables    = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party        = Game_Party.new
    $game_troop        = Game_Troop.new
    $game_map          = Game_Map.new
    $game_player        = Game_Player.new
    $game_maps          = Game_Maps.new ##
    $game_party.setup_starting_members
    $game_map.setup($data_system.start_map_id)
    $game_player.moveto($data_system.start_x, $data_system.start_y)
    $game_player.refresh
    $game_map.autoplay
    $game_map.update
    $scene = Scene_Map.new
  end
end

class Scene_Load < Scene_File
  alias game_maps_read_save_data read_save_data unless $@
  def read_save_data(file)
    game_maps_read_save_data(file)
    $game_maps = Marshal.load(file)
  end
end

class Scene_Save < Scene_File
  alias game_maps_write_save_data write_save_data unless $@
  def write_save_data(file)
    game_maps_write_save_data(file)
    Marshal.dump($game_maps, file)
  end
end

class Game_Event < Game_Character
  attr_accessor :erased
end

class Interpreter
  alias game_maps_command_201 command_201 unless $@
  def command_201
    $game_map.each_event do |event|
      event.erased = false
      event.refresh
    end
    maps = Game_Maps::EVENT_MAPS + Game_Maps::PANORAMA_MAPS +
      Game_Maps::FOG_MAPS
     
    if maps.include?($game_map.map_id)
      $game_maps.data[$game_map.map_id] = $game_map.clone
    else
      $game_maps.data[$game_map.map_id] = nil
    end
    game_maps_command_201
  end
end


With this one you can set the maps where the event features will be saved using the global array EVENT_MAPS in Game_Maps, at the very begining of the script.
You can do the same with panorama and fog features. If you don't need anything of this, use the other one!

Hope it will be useful for someone.