Help - Search - Members - Calendar
Full Version: Reseting self-switch on map enter/leave
RPG RPG Revolution Forums > Scripting > Script Development and Support
Titanhex
Alright so we all know how Erase Event works. The event is erased, then when you re-enter the map the Event comes back until you erase it again.

I want to do something similar but with self switches.

On entering the map, all the events run an autorun that sets up the technical details and it's graphic. It then turns on a self switch, which makes it interactive by touching it.

Now, if the player leaves the map, or saves in the map, when he returns all the events don't have graphics because they didn't run the autorun.

My solution was to run a self-switch reseter on autorun in the top left like this:

for i in 1..30
$game_self_switches[[$game_map.map_id, i, "B"]]=false
end
$game_map.need_refresh = true

But I would rather just leave it up to the event instead of do it in a batch which may reset other event's self-switches accidentally.

Is there an easy, simple way to make a self switch reset on map enter/leave, preferably without making a new event?
Pharonix
There's never an easy way to do anything cool

when you start the leave map transition set a new switch to on, then make an event page in each event that you want the self switch to turn off on - this one will have the switch you set in the transition as a pre-requisite.
then turn the self switch off in the new event page.
then before the map transfer turn the new switch off.

This is just a quick guess though so it may not work.
but from what I've seen in the project I'm working on, It may be possible.

I have class in 15minutes so I can check after class if you want
Night5h4d3
Not sure what you're looking for exactly, but try this:

spoiler

CODE
#==============================================================================
# * Night5h4d3's Self Switch Resetter
#------------------------------------------------------------------------------
# 9/16/2011  for: Titanhex
#------------------------------------------------------------------------------
# Descr:
#   Ressets self switches on the current map based on the events name
# How to use:
#   Add [N] to your event name, where N is the self switches (sepparated by
#   comma) to turn off (eg. [A, B, D])
# Config:
#   AUTO_RS_SS - This is the switch number to toggle automatic resseting of
#   self switches. turn the specified switch on to disable auto resetting.
# NOTE:
#   You can still reset self switches by using $scene.reset_sswitches(true),
#   this will force a reset of the specified self switches on the current map.
#------------------------------------------------------------------------------
# ** N5 module
#==============================================================================
module N5
  AUTO_RS_SS = 1
end
#==============================================================================
# ** Scene_Base
#------------------------------------------------------------------------------
#  This is a superclass of all scenes in the game.
#==============================================================================
class Scene_Base
  def reset_sswitches(force? = false)
    return if $game_switches[N5::AUTO_RS_SS] or force?
    @from_save    = from_save
    @name_slice   = []
    @temp_game_ss = $game_self_switches.clone
    for i in 1..$game_map.map.events.size
      if $game_map.map.events[i].name.include?("[")
        @name_slice[i] = $game_map.map.events[i].name.slice(/(\[)(.*)(\])/)
        @name_slice[i].gsub!(/[\[\,\]\s]/) {||}  
      end
    end
    for i in 0...@name_slice.size
      for n in 0...@name_slice[i].size
        if @name_slice[i] != nil
          $game_self_switches[[$game_map.map_id,
                               @name_slice[i],  
                               @name_slice[i][n]]] = false              
        end
      end
    end
    return @temp_game_ss
  end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================
class Scene_Map
  #--------------------------------------------------------------------------
  # * Player Transfer  Processing
  #--------------------------------------------------------------------------
  def update_transfer_player
    return unless $game_player.transfer?
    fade = (Graphics.brightness > 0)
    fadeout(30) if fade
    @spriteset.dispose              # Dispose of sprite set
    reset_sswitches                 # N5 reset self switches
    $game_player.perform_transfer   # Execute player transfer
    $game_map.autoplay              # Automatically switch BGM and BGS
    $game_map.update
    Graphics.wait(15)
    @spriteset = Spriteset_Map.new  # Recreate sprite set
    fadein(30) if fade
    Input.update
  end
end
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
#  This class performs the save and load screen processing.
#==============================================================================

class Scene_File < Scene_Base
  #--------------------------------------------------------------------------
  # * Write Save Data
  #     file : write file object (opened)
  #--------------------------------------------------------------------------
  def write_save_data(file)
    @temp = reset_sswitches         # N5 reset self switches
    characters = []
    for actor in $game_party.members
      characters.push([actor.character_name, actor.character_index])
    end
    $game_system.save_count += 1
    $game_system.version_id = $data_system.version_id
    @last_bgm = RPG::BGM::last
    @last_bgs = RPG::BGS::last
    Marshal.dump(characters,           file)
    Marshal.dump(Graphics.frame_count, file)
    Marshal.dump(@last_bgm,            file)
    Marshal.dump(@last_bgs,            file)
    Marshal.dump($game_system,         file)
    Marshal.dump($game_message,        file)
    Marshal.dump($game_switches,       file)
    Marshal.dump($game_variables,      file)
    Marshal.dump($game_self_switches,  file)
    Marshal.dump($game_actors,         file)
    Marshal.dump($game_party,          file)
    Marshal.dump($game_troop,          file)
    Marshal.dump($game_map,            file)
    Marshal.dump($game_player,         file)
    $game_self_switches = @temp
  end
end


NOTE: This is in theory, I haven't tested it actually resetting the self switches. (can't yet)
Titanhex
@Pharonix: Sorry, but that's not too far removed from just resetting all self-switches in a batch on map entrance.

@Nightshade:I haven't tested it yet, but thanks for concocting this.

I'm wary of using it though, as it rewrites Scene_File's methods, which would conflict greatly with a lot of systems I use.

I'm curious, why can't you just alias these systems like I've done with this?

MG_Sys
CODE
class Scene_File
  
  alias oldWriteSaveMGSys write_save_data
  def write_save_data(file)
    oldWriteSaveMGSys(file)
    Marshal.dump($mgval,             file)
    Marshal.dump($mgtype,            file)
    Marshal.dump($mgquit,            file)
    Marshal.dump($mganim,            file)
  end

  alias oldReadSaveMGSys read_save_data
  def read_save_data(file)
    oldReadSaveMGSys(file)
    $mgval            = Marshal.load(file)
    $mgtype           = Marshal.load(file)
    $mgquit           = Marshal.load(file)
    $mganim           = Marshal.load(file)
  end

end


I'm still learning. So bare with me. If you think it'll be fine I can try to alias them myself.

What I'm looking for you seem to have guessed correctly. From what I can tell from the code it does what I want it to do.
Night5h4d3
The map resetter can't be aliased, simply because the reset command needs to be run in the middle of the def, but as for scene_file the same is not true, I actually missed that and forgot that I could alias it, youd do it like so:
CODE
class Scene_File < Scene_Base
  #--------------------------------------------------------------------------
  # * Write Save Data
  #     file : write file object (opened)
  #--------------------------------------------------------------------------
  alias n5_wsd_old(file) write_save_data(file
  def write_save_data(file)
    @temp = reset_sswitches         # N5 reset self switches
    n5_wsd_old(file)
    $game_self_switches = @temp # restore self switches
  end
end
Titanhex
It's giving me a Syntax error on Line 29 of the script. I changed force? to force.

Also this line: alias n5_wsd_old(file) write_save_data(file

doesn't need (file)

The only error left is a NameError.

Line 31: from_save isn't a local variable or method for Scene_Map
Helios
Errr... never mind. I figured it out.
Titanhex
LMAO, I still need help with that from_save error.

Also, this line gives errors:


for i in 0...@name_slice.size
for n in 0...@name_slice[i].size

with size.

I removed the [i] on it.

Sadly even after making these modifications (I commented out the line that had from_save) the script doesn't do what it should.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.