Jump to content
Sign in to follow this  
Kcaz64

Common event when state ends / is removed.

Recommended Posts

I'm looking for a method to have a state run a common event when it expires or is removed. 

 

I plan on using this to remove all of a character's mana and buffs after a "berserk mode" state is finished. 

 

I figured a state is going to the easiest way to do this, so if anyone could help me out I'd appreciate it.

Share this post


Link to post
Share on other sites

Here's give this a go:

 

module StateRemoveCommonEventsKal
  
  TAG_NAME = "srce"
  
  class IDExtractor
    def get_common_event_id_for_state(state_id)
      rpg_state = get_rpg_state(state_id)
      extract_common_event_id(rpg_state.note)
    end
    
    private
    
    def get_rpg_state(state_id)
      $data_states.find do |rpg_state| 
        rpg_state && rpg_state.id == state_id
      end
    end
 
    def extract_common_event_id(note)
      id = note[/<#{TAG_NAME}\s+(\d+)\s*>/, 1]
      id.nil? ? nil : id.to_i
    end
  end
  
  class CommonEventRunner
    def run(common_event_id)
      page = make_page(common_event_id)
      $game_troop.interpreter.setup(page.list)
    end
    
    private
    
    def make_page(id)
      page = RPG::Troop::Page.new
      # 117 => common event code, 0 => indent, id => id of common event
      page.list.unshift(RPG::EventCommand.new(117, 0, [id]))
      page
    end
  end
  
  @id_extractor = IDExtractor.new
  @common_event_runner = CommonEventRunner.new
    
  def self.run_event_from_state(state_id)
    event_id = @id_extractor.get_common_event_id_for_state(state_id)
    @common_event_runner.run(event_id) if event_id
  end
end
 
class Game_BattlerBase
  alias_method :erase_state_srce_kal, :erase_state
  
  def erase_state(state_id)
    StateRemoveCommonEventsKal.run_event_from_state(state_id)
    erase_state_srce_kal(state_id)
  end
end

 

make a state and put a tag in the state notebox like this: 

 

<srce [common event id]>
 

 

For example: 

 

<srce 4>
 

will run the common event with id 4 when the state is removed. If you want to use another tag name simply change the TAG variable in the script. Let me know if it works or not. :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×