じ☆ve冰风 发表于 2026-8-2 18:39:46

Random Common Event Occurence

Random Common Event Occurence v1.0
Drykul

Introduction
Basically this acts similar to random battle events only it calls a specified Common Event instead of a battle.

Features
- Process common events at random intervals depending on Region ID.
- Can adjust the % chance per event as well as minimum # of steps required before the event will proc.
- Disable/Enable any particular event by either setting to true/false, a $game_switch, or any other boolean.

Screenshots
No screenshots needed.

How to Use
Simply set up your events in the "Configuration Section", set up your common event in the database, and paint your terrain with the Region ID you specify.

Demo
No Demo Included (I will post one if requested but it's pretty easy to set up and use.)

Script

Spoiler                Code:       
=begin---------------------------------------------Random Common Event Occurance v1.0 by Drykul---------------------------------------------    Basically this acts similar to random battle events only it calls a specifiedCommon Event instead of a battle. Simply set up your events below in the"Configuration Section", set up your common event in the database, and paintyour terrain with the Region ID you specify below.   *Special thanks to Adorna for writing the initial script and giving me theinspiration for this!   --------------Compatibility--------------    The update method in Scene_Map is aliased. Other than that you shouldn't haveany issues with compatibility!   --------------------------------                          ToS--------------------------------    Completely free to use for commercial and non-commercial with no restrictions.Just a heads up to me that you're using it would be nice.    --------------Contacting me--------------    You can email me at drykul@cloud9studios.net, find me on the/r/RPGMaker subreddit, I'm shaynec1981 at www.rpgmakerweb.com=end################################################################################class Random_Event_Occuranceattr_reader :reo_region_idattr_accessor :random_eventsattr_accessor :steps_countingdef reo_setup    @random_events =    {######################################################################################## DO NOT EDIT ABOVE THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ################################# Configuration Section ################################          # :event_name => [ region id,#                                  % chance of occurance,#                                  enabled/disabled,#                                  common event to run,#                                  minimum number of steps taken to process ],    :test1 => [ 1,                          50,                          true,                          4,                          10 ],      :test2 => [ 2,                          20,                          true,                          5,                          40 ],                                                  ######################################################################################### DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING #######################################################################################    }enddef initialize    @regionid = nil    @steps_counting = nil    @numbers_to_proc = []    @steps = 0    reo_setupend   def encounter_chance(region_id)    for i in @random_events          if i == region_id && i == true          @steps += 1          chance = rand(101)          while @numbers_to_proc.size < i                  new_num = rand(101)                  if !@numbers_to_proc.include?(new_num)                  @numbers_to_proc[@numbers_to_proc.size] = new_num                  end                             end          if @numbers_to_proc.include?(chance) && @steps >= i                  $game_temp.reserve_common_event(i)                  @steps = 0          end          end    endend   def update    reo_setup    if @regionid != $game_map.region_id($game_player.x, $game_player.y)          @regionid = $game_map.region_id($game_player.x, $game_player.y)          @steps = 0    end    encounter_chance(@regionid)    @numbers_to_proc.clearend end################# UPDATED SCENE_MAP ############################################class Scene_Map < Scene_Base   alias random_event_occurance_map_update updatedef update    random_event_occurance_map_update    for i in $reo.random_events          if $game_map.region_id($game_player.x, $game_player.y) == i          if $reo.steps_counting != $game_party.steps                  $reo.steps_counting = $game_party.steps                  $reo.update          end          end    endendend################# UPDATED DATAMANAGER###########################################module DataManagerclass << self      unless self.method_defined?(:reo_GameObj_Alias)          alias_method(:reo_GameObj_Alias, :create_game_objects)    end    unless self.method_defined?(:reo_MakeSaveAlias)          alias_method(:reo_MakeSaveAlias, :make_save_contents)    end    unless self.method_defined?(:reo_ExtractSaveAlias)          alias_method(:reo_ExtractSaveAlias, :extract_save_contents)    end    def create_game_objects          reo_GameObj_Alias          $reo = Random_Event_Occurance.new    end      def make_save_contents          contents = reo_MakeSaveAlias          contents[:reo] = $reo          contents    end      def extract_save_contents(contents)          reo_ExtractSaveAlias(contents)          $reo = contents[:reo]    endendend






FAQ


Credit and Thanks
- Drykul
- Adorna

Author's Notes
I'm fairly new to scripting and this is the first one that I thought would be easy enough to clean up and share and to get some feedback! Hopefully it comes in handy for someone.
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7


本贴来自国际rpgmaker官方论坛作者:shaynec1981处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/random-common-event-occurence.45627/
页: [1]
查看完整版本: Random Common Event Occurence