[ACE] Yanfly button-activated common events

Hey! Anyways, I want to first start off with the cheesy usual. I really appreciate what this community has to offer, and I definitely would appreciate it even more if you guys can come up with a solution for me 😛

Oookay, so where to begin? So I have this script doo-hickey right here

Spoiler
#==============================================================================
#
# ▼ Yanfly Engine Ace - Button Common Events v1.00
# -- Last Updated: 2012.01.09
# -- Level: Normal
# -- Requires: n/a
#
#==============================================================================


$imported = {} if $imported.nil?
$imported["YEA-ButtonCommonEvents"] = true


#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.01.09 - Started Script and Finished.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# RPG Maker VX Ace supports 8 different action buttons to use. However, only
# 3 of those are used (A, B, and C) on the field map. The rest of them aren't
# used at all. This script allows usage of the L, R, X, Y, and Z buttons by
# binding them to common events.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# Modify the COMMON_EVENT hash in the script module to adjust which common
# events are used for each button.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
#==============================================================================


module YEA
module BUTTON_EVENT

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Button Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# This sets the common events that are to run when the particular button
# is pressed. The following chart shows the respective keyboard buttons.
#
# :Button Default Keyboard Button
# :L Q
# :R W
# :X A
# :Y S
# :Z D
#
# If you do not wish to associate a button with a common event, set the
# common event for that button to 0.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
COMMON_EVENT ={
# :Button => Common Event,
:L => 0, # Does not run a common event.
:R => 0, # Does not run a common event.
:X => 0, # Runs common event 1.
:Y => 0, # Runs common event 2.
:Z => 1, # Runs common event 3.
} # Do not remove this.

end # BUTTON_EVENT
end # YEA


#==============================================================================
# ▼ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================


#==============================================================================
# ■ Scene_Map
#==============================================================================


class Scene_Map < Scene_Base

#--------------------------------------------------------------------------
# alias method: update_scene
#--------------------------------------------------------------------------
alias scene_map_update_scene_bce update_scene
def update_scene
scene_map_update_scene_bce
update_button_common_events unless scene_changing?
end

#--------------------------------------------------------------------------
# new method: update_button_common_events
#--------------------------------------------------------------------------
def update_button_common_events
for key in YEA::BUTTON_EVENT::COMMON_EVENT
next unless Input.trigger?(key[0])
next if key[1] <= 0
$game_temp.reserve_common_event(key[1])
end
end

end # Scene_Map


#==============================================================================
#
# ▼ End of File
#
#==============================================================================

Technically, this will call common event #1 whenever I press the button "D" on my keyboard. great, right? Well, common event #1 activates a building script which brings up a menu and allows me to place events on the map. My problem is that players are able to press the "D" button even while already placing events, which creates a copy of that event and has the player moving two of the same object at once. This effectively breaks the game.

Is there any possible way I can simply stop this script from running by using script calls, and then restart it whenever I feel like it? I want to stop the common event script from running through an event's script call. I hope I'm making enough sense here guys :s

An idea would be perhaps to bind the common event script to a switch, which will hopefully activate/deactivate the script depending on the state of the switch?

Any help would be appreciated.
I became pretty impatient and decided to come up with a solution myself, lol.

For those of you who stumbled onto this page looking for an answer, here's the modified version of the script. I'm not claiming any of this as mine, it all belongs to Yanfly and any other contributors respectively. I even stole snippets from a few of his other scripts to patch this together.

Spoiler
#==============================================================================# # ▼ Yanfly Engine Ace - Button Common Events v1.00# -- Last Updated: 2012.01.09# -- Level: Normal# -- Requires: n/a# #==============================================================================$imported = {} if $imported.nil?$imported["YEA-ButtonCommonEvents"] = true#==============================================================================# ▼ Updates# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 2012.01.09 - Started Script and Finished.# #==============================================================================# ▼ Introduction# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# RPG Maker VX Ace supports 8 different action buttons to use. However, only# 3 of those are used (A, B, and C) on the field map. The rest of them aren't# used at all. This script allows usage of the L, R, X, Y, and Z buttons by# binding them to common events.# #==============================================================================# ▼ Instructions# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# To install this script, open up your script editor and copy/paste this script# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.# # Modify the COMMON_EVENT hash in the script module to adjust which common# events are used for each button.# #==============================================================================# ▼ Compatibility# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that# it will run with RPG Maker VX without adjusting.# #==============================================================================module YEA  module UTILITY        #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-    # - Stop Movement Switches -    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-    # These switches control whether or not the respective events can move.    # If the switches are off, then there is no locking them. If the switches    # are on, then the events are locked from moving.    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-    CAN_PRESS_BUTTON_SWITCH = 21      end # UTILITY#==============================================================================# ■ Switch#==============================================================================          module BUTTON_EVENT        #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-    # - Button Settings -    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-    # This sets the common events that are to run when the particular button    # is pressed. The following chart shows the respective keyboard buttons.    #     #   :Button    Default Keyboard Button    #      :L        Q    #      :R        W    #      :X        A    #      :Y        S    #      :Z        D    #     # If you do not wish to associate a button with a common event, set the    # common event for that button to 0.    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-    COMMON_EVENT ={    # :Button => Common Event,           :L =>   0,    # Does not run a common event.           :R =>   0,    # Does not run a common event.           :X =>   0,    # Runs common event 1.           :Y =>   0,    # Runs common event 2.           :Z =>   1,    # Runs common event 3.    } # Do not remove this.      end # BUTTON_EVENTend # YEA  module Switch    #--------------------------------------------------------------------------  # self.Switch  #--------------------------------------------------------------------------    def self.can_press_buttons      return $game_switches[YEA::UTILITY::CAN_PRESS_BUTTON_SWITCH]    end  end # Switch#==============================================================================# ▼ Editting anything past this point may potentially result in causing# computer damage, incontinence, explosion of user's head, coma, death, and/or# halitosis so edit at your own risk.#==============================================================================#==============================================================================# ■ Scene_Map#==============================================================================class Scene_Map < Scene_Base    #--------------------------------------------------------------------------  # alias method: update_scene  #--------------------------------------------------------------------------  alias scene_map_update_scene_bce update_scene  def update_scene    scene_map_update_scene_bce    update_button_common_events unless scene_changing?  end    #--------------------------------------------------------------------------  # new method: update_button_common_events  #--------------------------------------------------------------------------  def update_button_common_events    return if Switch.can_press_buttons    for key in YEA::BUTTON_EVENT::COMMON_EVENT      next unless Input.trigger?(key[0])      next if key[1] <= 0      $game_temp.reserve_common_event(key[1])    end  end  end # Scene_Map#==============================================================================# # ▼ End of File# #==============================================================================

By default, the script is "on", which means that pressing the designated buttons will activate the corresponding common event. I simply made it check if CAN_PRESS_BUTTON_SWITCH = XX is on or off before checking for input. You need to set the switch to ON in order to disable the script.

Ghetto-rigged but works perfectly fine 😛

Original thread: https://forums.rpgmakerweb.com/threads/ace-yanfly-button-activated-common-events.35664/