RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
"Before/After Battle Common Event Activator" Script

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 72
RMRK Junior
Hello everyone!

To make a short story, I made a few games on RMXP about 5 years ago. I remember having a script I would use to run common events before battle, such as for giving special bonuses for a fight, testing if a thief would have a free backstab, etc.. I would also use that script after battle to regen a few HP/MP with a skill and adjust a few variables and switches.
A few years ago, I developed the itch to make a new game, then I finally cracked and acquired RMVX. I've looked here and on other sites but I can't seem to find a script like I just described for RMVX. Does such a script exist? If not, is it okay to [Request] it in the proper place?

Thanks

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
This should let you run a common event before and after battle.

Code: [Select]
#==============================================================================
# ** TDS Battle Common Events
#    ver : 1.0
#------------------------------------------------------------------------------
#  Description :
#    This script is used to run common events before and after battle.
#==============================================================================

  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  # Common Event ID to run before a battle starts
  BEFORE_BATTLE_C_EVENT_ID = 1
  # Common Event ID to run after a battle ends (Win, Escape, Lose) 0 for nothing
  AFTER_BATTLE_C_EVENTS_ID = [2, 0, 2]
 
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listing
  #-------------------------------------------------------------------------- 
  alias tds_battle_common_events_scene_map_call_battle     call_battle 
  #--------------------------------------------------------------------------
  # * Switch to Battle Screen
  #--------------------------------------------------------------------------
  def call_battle     
    # Run Original Method
    tds_battle_common_events_scene_map_call_battle
    # Call a battle common event
    $game_map.interpreter.battle_common_event(BEFORE_BATTLE_C_EVENT_ID)   
    # Update Game Map Interpreter
    $game_map.interpreter.update   
  end
end


#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listing
  #-------------------------------------------------------------------------- 
  alias tds_battle_common_events_scene_battle_battle_end     battle_end 
  #--------------------------------------------------------------------------
  # * End Battle
  #     result : Results (0: win, 1: escape, 2:lose)
  #--------------------------------------------------------------------------
  def battle_end(result)
    # Run Original Method
    tds_battle_common_events_scene_battle_battle_end(result)
    # If After Battle Common Event ID is not 0
    if AFTER_BATTLE_C_EVENTS_ID[result] != 0
      # Call a battle common event
      $game_map.interpreter.battle_common_event(AFTER_BATTLE_C_EVENTS_ID[result])
      # Update Game Map Interpreter
      $game_map.interpreter.update   
    end   
  end 
end


#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Call Battle Common Event
  #--------------------------------------------------------------------------
  def battle_common_event(id)
    common_event = $data_common_events[id]
    if common_event != nil
      @child_interpreter = Game_Interpreter.new(@depth + 1)
      @child_interpreter.setup(common_event.list, @event_id)
    end
    return true
  end
end

To use simply edit these constants in the script.

Code: [Select]
  BEFORE_BATTLE_C_EVENT_ID = #

# Is the ID of the common event you want to run before battles.

Code: [Select]
  AFTER_BATTLE_C_EVENTS_ID = [#1, #2, #3]

After battle you can set 3 different common events to run depending on what happened in battle.

#1 ID of common event to run if you win
#2 ID of common event to run if you escape
#3 ID of common event to run if you lose

If you set the ID of any to 0 it won't run any common events in that instance.

Let me know if this works out for you and if you need anything fixed/added.

Have a nice day.

**
Rep: +0/-0Level 72
RMRK Junior
The script was loaded and tested, it worked perfectly. Thanks a lot! Good thinking on splitting up the three possible outcomes, if I remember correctly the RMXP version ran the same script whatever the battle result was.

For now, I don't have anything in mind that I would like to add/modify, but I'll be sure to drop a line if I think about something.

Thanks again and have a nice day too!  :)