quack_rgss

Qonvenience 1.0e

Jan 14th, 2016
731
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2. #==============================================================================
  3.  * Qonvenience - v1.0e
  4.   Author: Quack
  5. #==============================================================================
  6.  
  7. What it is and what does it do?
  8. -------------------------------------------------------------------------------
  9. -Code that I have made for my own conveniece and use for some of my scripts.
  10.  Other than needing it if you plan to use certain scripts I've written it
  11.  adds some functionality others might be interested in listed below:
  12.  
  13. -Adds event self variables.
  14.  Usage: (event_id should be a number and key can be what you want. Usually a
  15.           number or a string)
  16.   -Set var: L[event_id,key] = "a_value"  OR   event.tset(key,"a_value")
  17.   -Get var: somevar = L[event_id,key]    OR   somevar = event.tget(key)
  18.  
  19. -Can access event self switches similar to self vars.
  20.  Usage:
  21.   -Set switch: SS[event_id,"A"] = true   OR   event.sset("B",false)
  22.   -Get switch: somevar = SS[event_id,"A"] OR  event.sget("C")
  23.  
  24. -Game variables and game switches can also be accessed with shorter commands
  25.  using V[23] = 200, somevar = V[2] for game variables and S[4] = true,
  26.  somevar = S[5] for game switches.
  27.  
  28. -Adds map local variables. That is variables that are unique to that map.
  29.  Usage:
  30.   -Set var: M[key] = 123
  31.   -Get var: somevar = M[key]
  32.  
  33. -Adds Temporary variables that reset on map chage. There exists both map wide
  34.  and event self temporary variables.
  35.  Usage:
  36.  -To set or get a normal temp var you do this:
  37.     TMP["a_key"] = 9999   OR  TMP[7] = "some_value"
  38.     somevar = TMP["another_key"]  OR  somevar = TMP[13]
  39.  -To set or get an event self tmp var:
  40.     event.tset("a_key","a_value")
  41.     event.tget("a_key")
  42.     TMP[event.id,"a_key"] = "a_value"  # works too
  43.    
  44. -Adds a functionality for enemy respawning. It doesn't do anything unless you
  45.  actually use it. I would have taken it out and put it a separate script but I
  46.  didn't feel like it. A bunch of extra methods aliases and waste of time.
  47.  If you have no interest in this just skip to the next point instead.
  48.  I use visible enemies that chase you in my game. When an enemy dies I set it's
  49.  self A switch to ON to make it stay dead. I did this because I didn't want
  50.  them to respawn everytime I went into the room. But I didn't want them stay
  51.  dead forever either. What I did was add a counter to each map that is set to
  52.  a certain value (depends on a game variable, which variable you decide in the
  53.  config area below). Whenever you change map that value is reduced by 1 for all
  54.  maps. When the value gets to 0 all events with the tag <en> in their name on
  55.  that map gets their 'A' self switch set to OFF so they will respawn. So if you
  56.  set the variable to 2 you have to walk at least 2 maps away from a certain map
  57.  for that maps enemies to respawn. It is also possible you might want all
  58.  enemies to stay dead in a dungeon until you leave that dungeon. To do this
  59.  you would set the game variable to a really high value so the enemies will
  60.  never respawn from you walking to other maps upon entering the dungeon. And
  61.  when you leave you set it back and also do this script call:
  62.    $game_respawnVars.clear
  63.  So to use this all your respawnable enemies would have to use the self switch
  64.  'A' as ON to make it dead and they also need to have the tag <en> in their
  65.  event name.
  66.    
  67. -Some things for Move routes.
  68.  -Designate event to move via code evaluation by setting the first command in
  69.   a move route to script call starting with '[v]' followed by code that can
  70.   be evaluated to a number like: '[v]20-5' OR '[v]V[12]'
  71.  
  72. -Like with move routes you can now using jump to label designate a label to
  73.  jump to via code evaluation by setting the label name in the jump to label
  74.  command to '[v]' followed by code that can be evaluated to a string.
  75.   Like so: '[v]"my label"' OR '[v]V[34]' OR '[v]"my label" + M[2]'
  76.  
  77. -Call an event page like you would call a common event using this method in
  78.  a script call: call_event(event_id, page_number)
  79.  
  80. -Support for editor suffixes.
  81.   Have you ever had multiple versions of the same skill, all with same name?
  82.   Or wanted to add a comment to an enemy's name to help you remember exactly
  83.   what that enemy is and/or does just by seeing it in the list rather than
  84.   having to click it and check it's details?
  85.   Then this is it. With this script active any text following and including
  86.   the first '(' in a database object's name will get removed in-game.
  87.   For example let's say I have a couple of key items which are all for a
  88.   certain sidequest, lets call it the "Pink Elephant" quest. Therefore I add
  89.   '(Pink Elephant)' to the name of each of those key items so they are easy to
  90.   spot in the list. So lets say one of these key items is the "Golden Peanut".
  91.   That item now has the name "Golden Peanut(Pink Elephant)" in the editor.
  92.   But in-game it still has the name "Golden Peanut" because the pink elephant
  93.   part gets removed.
  94.  
  95. Requirements:
  96. None
  97.  
  98. Instructions/Install notes:
  99. Paste it below Materials like you would any other script.
  100.  
  101. Terms of Use:
  102. Use it however you wish (yes, that does include commercial projects), as long
  103. as you do not claim it as your own code. I would also prefer you mention me in
  104. your credits if you do decide to use it.
  105.  
  106. Bugs:
  107. dunno
  108.  
  109. History:
  110. 13/01/2016 - Added comments, cleaned code and uploaded it since my Chatter
  111.              Messages script requires it.
  112.  
  113. =end
  114.  
  115. $imported = {} if $imported.nil?
  116. $imported["Qonvenience"] = true
  117.  
  118. #==============================================================================
  119. # CONFIG
  120. #==============================================================================
  121. module QUACK
  122.  
  123.   # Number of the game switch used to turn of the auto change bgm on
  124.   # map change.
  125.   TURN_OFF_AUTO_BGM_PLAY_SWITCH = 20
  126.  
  127.   # Number of game variable that designates how many maps you have to go away
  128.   # from a given map for that given map's enemies to respawn.
  129.   RESPAWN_ROOM_COUNT = 7
  130.  
  131. end
  132. #==============================================================================
  133. # SCRIPT START
  134. #==============================================================================
  135.  
  136. #==============================================================================
  137. # DataManager - Local variables & item names
  138. # -----------------------------------------------------------------------------
  139. # Adds hashes for new variables and removes text from all database item names
  140. # from the first encountered '('. Useful in for example when you have several
  141. # versions of the same skill (a levelable skill perhaps) and want them all to
  142. # have the same name but still be able to easily tell them apart in the editor.
  143. #==============================================================================
  144. module DataManager
  145.   class << self
  146.    
  147.     #--------------------------------------------------------------------------
  148.     # alias: Create Game Objects
  149.     #--------------------------------------------------------------------------
  150.     alias local_create_game_objects create_game_objects
  151.     def create_game_objects
  152.       local_create_game_objects
  153.       $game_selfVars = {}#Simple_Matrix.new
  154.       $game_mapVars = {}
  155.       $game_respawnVars = {}
  156.       $game_tempVars = {}
  157.       #$game_database = Database.finalize
  158.     end
  159.    
  160.     #--------------------------------------------------------------------------
  161.     # alias: Make Save Contents
  162.     #--------------------------------------------------------------------------
  163.     alias local_make_save_contents make_save_contents
  164.     def make_save_contents
  165.       contents = local_make_save_contents
  166.       contents[:self_vars] = $game_selfVars
  167.       contents[:map_vars] = $game_mapVars
  168.       contents[:respawn_vars] = $game_respawnVars
  169.       contents[:tmp_vars] = $game_tempVars
  170.       contents
  171.     end
  172.      
  173.     #--------------------------------------------------------------------------
  174.     # alias: Extract Save Contents
  175.     #--------------------------------------------------------------------------
  176.     alias local_extract_save_contents extract_save_contents
  177.     def extract_save_contents(contents)
  178.       local_extract_save_contents(contents)
  179.       $game_selfVars = contents[:self_vars]
  180.       $game_mapVars = contents[:map_vars]
  181.       $game_tempVars = contents[:tmp_vars]
  182.       $game_respawnVars = contents[:respawn_vars]
  183.       #$game_database = Database.finalize
  184.      end
  185.      
  186.     #--------------------------------------------------------------------------
  187.     # alias: Load database
  188.     #--------------------------------------------------------------------------
  189.     alias load_database_item_names load_database
  190.     def load_database
  191.       load_database_item_names
  192.       load_item_names
  193.       load_notetags_type_tags
  194.     end
  195.    
  196.     #--------------------------------------------------------------------------
  197.     # new: Load Type Tags
  198.     #--------------------------------------------------------------------------
  199.     def load_notetags_type_tags
  200.       for obj in $data_states
  201.         next if obj.nil?
  202.         obj.load_notetags_type_tags
  203.       end
  204.       for obj in $data_skills
  205.         next if obj.nil?
  206.         obj.load_notetags_type_tags
  207.       end
  208.       for obj in $data_items
  209.         next if obj.nil?
  210.         obj.load_notetags_type_tags
  211.       end
  212.       for obj in $data_weapons
  213.         next if obj.nil?
  214.         obj.load_notetags_type_tags
  215.       end
  216.       for obj in $data_armors
  217.         next if obj.nil?
  218.         obj.load_notetags_type_tags
  219.       end
  220.       for obj in $data_actors
  221.         next if obj.nil?
  222.         obj.load_notetags_type_tags
  223.       end
  224.       for obj in $data_enemies
  225.         next if obj.nil?
  226.         obj.load_notetags_type_tags
  227.       end
  228.     end
  229.          
  230.     #--------------------------------------------------------------------------
  231.     # new: Remove Editor suffixes from items
  232.     #--------------------------------------------------------------------------
  233.     def load_item_names
  234.       for actor in $data_actors
  235.         next if actor.nil?
  236.         actor.name = actor.name.partition("(")[0]
  237.       end
  238.       for clas in $data_classes
  239.         next if clas.nil?
  240.         clas.name = clas.name.partition("(")[0]
  241.       end
  242.       for item in $data_items
  243.         next if item.nil?
  244.         item.name = item.name.partition("(")[0]
  245.       end
  246.       for weapon in $data_weapons
  247.         next if weapon.nil?
  248.         weapon.name = weapon.name.partition("(")[0]
  249.       end
  250.       for armor in $data_armors
  251.         next if armor.nil?
  252.         armor.name = armor.name.partition("(")[0]
  253.       end
  254.       for skill in $data_skills
  255.         next if skill.nil?
  256.         skill.name = skill.name.partition("(")[0]
  257.       end
  258.       for state in $data_states
  259.         next if state.nil?
  260.         state.name = state.name.partition("(")[0]
  261.       end
  262.       for enemy in $data_enemies
  263.         next if enemy.nil?
  264.         enemy.name = enemy.name.partition("(")[0]
  265.       end
  266.     end
  267.   end
  268. end
  269.  
  270. class RPG::BaseItem
  271.   attr_accessor :type_tags
  272.  
  273.   def has_tag?(tag)
  274.     return @type_tags.include?(tag)
  275.   end
  276.  
  277.   def load_notetags_type_tags
  278.     @type_tags = self.note =~ /<TAGS:([^<>]*)>/i ? $1 : ""
  279.   end
  280. end # RPG::BaseItem
  281.  
  282. #==============================================================================
  283. # TEMPORARY VARIABLES (reset on map change)
  284. #==============================================================================
  285. class TMP
  286.   class << self
  287.     def [](*arg)#id)
  288.       case arg.length
  289.         when 1
  290.           return 0 if $game_tempVars[[arg[0]]].nil?
  291.           return $game_tempVars[[arg[0]]]
  292.         when 2
  293.           return 0 if $game_tempVars[[arg[0], arg[1]]].nil?
  294.           return $game_tempVars[[arg[0], arg[1]]]
  295.       end
  296.     end
  297.    
  298.     def []=(*arg)#id, val)
  299.       case arg.length
  300.         when 2; $game_tempVars[[arg[0]]] = arg[1]
  301.         when 3; $game_tempVars[[arg[0],arg[1]]] = arg[2]
  302.       end
  303.       $game_map.need_refresh = true
  304.     end  
  305.    
  306.     def clear
  307.       $game_tempVars.clear
  308.     end
  309.   end
  310. end
  311. class T
  312.   class << self
  313.     def [](*arg)
  314.       case arg.length
  315.         when 1
  316.           return 0 if $game_tempVars[[arg[0]]].nil?
  317.           return $game_tempVars[[arg[0]]]
  318.         when 2
  319.           return 0 if $game_tempVars[[arg[0], arg[1]]].nil?
  320.           return $game_tempVars[[arg[0], arg[1]]]
  321.       end
  322.     end
  323.    
  324.     def []=(*arg)
  325.       case arg.length
  326.         when 2; $game_tempVars[[arg[0]]] = arg[1]
  327.         when 3; $game_tempVars[[arg[0],arg[1]]] = arg[2]
  328.       end
  329.       $game_map.need_refresh = true
  330.     end
  331.    
  332.     def clear
  333.       $game_tempVars.clear
  334.     end
  335.   end
  336. end
  337.  
  338. #==============================================================================
  339. # MAP LOCAL VARIABLES
  340. #==============================================================================
  341. class M
  342.   class << self
  343.     def [](var_id)
  344.       return 0 if $game_mapVars[[$game_map.map_id,var_id]].nil?
  345.       return $game_mapVars[[$game_map.map_id,var_id]]
  346.     end
  347.    
  348.     def []=(var_id, value)
  349.       $game_mapVars[[$game_map.map_id,var_id]] = value
  350.       $game_map.need_refresh = true
  351.     end
  352.   end
  353. end
  354.  
  355. #==============================================================================
  356. # EVENT LOCAL VARIABLES
  357. #==============================================================================
  358. class L
  359.   class << self
  360.     def [](eid, vid)
  361.       return 0 if $game_selfVars[[$game_map.map_id,eid,vid]].nil?
  362.       return $game_selfVars[[$game_map.map_id,eid,vid]]
  363.     end
  364.    
  365.     def []=(eid, vid, value)
  366.       $game_selfVars[[$game_map.map_id,eid,vid]] = value
  367.       $game_map.need_refresh = true
  368.     end
  369.   end
  370. end
  371.  
  372. #==============================================================================
  373. # SELF SWITCHES
  374. #==============================================================================
  375. class SS
  376.   class << self
  377.     def [](eid, vid)
  378.       return false if $game_self_switches[[$game_map.map_id, eif, vid]].nil?
  379.       return $game_self_switches[[$game_map.map_id, eif, vid]]
  380.     end
  381.    
  382.     def []=(eid, vid, value)
  383.       $game_self_switches[[$game_map.map_id,eid,vid]] = value
  384.       $game_map.need_refresh = true
  385.     end
  386.   end
  387. end
  388.  
  389. #==============================================================================
  390. # GLOBAL VARIABLES
  391. #==============================================================================
  392. class V
  393.   class << self
  394.     def [](id)
  395.       return 0 if id < 1
  396.       return $game_variables[id]
  397.     end
  398.    
  399.     def []=(id, value)
  400.       $game_variables[id] = value
  401.     end
  402.   end
  403. end
  404.  
  405. #==============================================================================
  406. # GLOBAL SWITCHES
  407. #==============================================================================
  408. class S
  409.   class << self
  410.     def [](id)
  411.       return false if id < 1
  412.       return $game_switches[id]
  413.     end
  414.    
  415.     def []=(id, value)
  416.       $game_switches[id] = value
  417.     end
  418.   end
  419. end
  420.  
  421. #==============================================================================
  422. #==============================================================================
  423.  
  424. class Game_Battler < Game_BattlerBase
  425.   #--------------------------------------------------------------------------
  426.   # new: Check if battler has that tag
  427.   #--------------------------------------------------------------------------
  428.   def has_tag?(tag)
  429.     return $data_enemies[@enemy_id].has_tag?(tag)
  430.   end
  431.  
  432.   #--------------------------------------------------------------------------
  433.   # new: Check if battler has state with that tag
  434.   #--------------------------------------------------------------------------
  435.   def tagged_state?(tag)
  436.     for state in states
  437.       return true if state.type_tags.include?(tag)
  438.     end
  439.     return false
  440.   end
  441.  
  442.   #--------------------------------------------------------------------------
  443.   # new: Remove states with specified tag
  444.   #--------------------------------------------------------------------------
  445.   def remove_tagged_states(tag)
  446.     rstates = []
  447.     s = states
  448.     for state in s
  449.       if state.type_tags.include?(tag)
  450.         remove_state(state.id)
  451.         rstates.push(state)
  452.       end
  453.     end
  454.     return rstates
  455.   end
  456.  
  457.   #--------------------------------------------------------------------------
  458.   # new: Return all states battler has with specified tag
  459.   #--------------------------------------------------------------------------
  460.   def states_with_tags(tag)
  461.     s = []
  462.     for state in states
  463.       s.push(state.id) if state.type_tags.include?(tag)
  464.     end
  465.     return s
  466.   end
  467. end
  468.  
  469. class Game_Actor < Game_Battler
  470.   #--------------------------------------------------------------------------
  471.   # new: Check if battler has that tag
  472.   #--------------------------------------------------------------------------
  473.   def has_tag?(tag)
  474.     return actor.has_tag?(tag)
  475.   end
  476. end
  477.  
  478. class RPG::Troop::Page
  479.   attr_reader :note_tags
  480.   attr_reader :custom_condition
  481.  
  482.   def setup_notetags
  483.     @note_tags = ""
  484.     return if !@list || @list.size <= 0
  485.     # build note tags
  486.     @list.each {|i|
  487.       @note_tags += i.parameters[0] if i && (i.code == 108 || i.code == 408)
  488.     }
  489.     # find page custom condition if there is one
  490.     @custom_condition = @note_tags =~ /<CC>(.*)<\/CC>/i ? $1 : nil
  491.   end
  492. end
  493.  
  494. class Game_Troop
  495.   # METHODS FOR CUSTOM EVENT CONDITIONS
  496.   alias quack_qon_setup setup
  497.   def setup(troop_id)
  498.     quack_qon_setup(troop_id)
  499.     troop.pages.each{|p| p.setup_notetags }
  500.   end
  501.  
  502.   alias quack_qon_conditions_met conditions_met?
  503.   def conditions_met?(page)
  504.     r = quack_qon_conditions_met(page)
  505.     return false if has_custom_cond?(page) && custom_cond_fail(page)
  506.     return r
  507.   end
  508.  
  509.   def has_custom_cond?(page)
  510.     !page.custom_condition.nil?
  511.   end
  512.  
  513.   def custom_cond_fail(page)
  514.     return !eval(page.custom_condition)
  515.   end
  516. end
  517.  
  518. class Game_Map
  519.   attr_reader   :map_id
  520.  
  521.   #--------------------------------------------------------------------------
  522.   # alias: Autoplay
  523.   # Switch for turning off bgm auto starting new song when entering map
  524.   #--------------------------------------------------------------------------
  525.   alias quack_qon_autoplay autoplay
  526.   def autoplay
  527.     if S[QUACK::TURN_OFF_AUTO_BGM_PLAY_SWITCH]
  528.       @map.bgs.play if @map.autoplay_bgs
  529.     else
  530.       quack_qon_autoplay
  531.     end
  532.   end
  533.  
  534.   #--------------------------------------------------------------------------
  535.   # alias: Setup
  536.   # Clear TMP vars, clear event name tags & update enemy respawn
  537.   #--------------------------------------------------------------------------
  538.   alias qack_qon_setup setup
  539.   def setup(map_id)
  540.     TMP.clear
  541.     @q_name_tags = {}
  542.     qack_qon_setup(map_id)
  543.     if get_respawn(map_id) == 0
  544.       e = all_event_tag('en')
  545.       e.each {|ev| ev.sset("A",false) } unless e.nil?
  546.     end
  547.     for key in $game_respawnVars.keys
  548.       $game_respawnVars[key] -= 1
  549.     end
  550.     $game_respawnVars[map_id] = V[QUACK::RESPAWN_ROOM_COUNT]
  551.     $game_respawnVars.delete_if {|k,v| v <= 0 }
  552.   end
  553.  
  554.   #--------------------------------------------------------------------------
  555.   # new: Add Event Tags
  556.   # Used for event name tags
  557.   #--------------------------------------------------------------------------
  558.   def add_event_tags(ev, pt)
  559.     u = []
  560.     # name tags
  561.     t = ev.name.scan(/<([^<>]*)>/i)
  562.     return if t.nil? || t.length < 1
  563.     t.each {|s|
  564.       if @q_name_tags.has_key?(s[0])
  565.         @q_name_tags[s[0]].push(ev)
  566.       else
  567.         @q_name_tags[s[0]] = [ev]
  568.       end
  569.       ev.add_name_tag(s[0])
  570.       u.push(s[0])
  571.     }
  572.     # page tags
  573.     pt.each{|p|
  574.       p.each{|pagtag|
  575.         next if u.include?(pagtag)
  576.         u.push(pagtag)
  577.         if @q_name_tags.has_key?(pagtag)
  578.           @q_name_tags[pagtag].push(ev)
  579.         else
  580.           @q_name_tags[pagtag] = [ev]
  581.         end
  582.       }
  583.     }
  584.   end
  585.  
  586.   #--------------------------------------------------------------------------
  587.   # new: Delete Event Tags
  588.   # Used for event name tags
  589.   #--------------------------------------------------------------------------
  590.   def delete_event_tags(ev)
  591.     ev.name_tags.each{|s|
  592.       @q_name_tags[s].delete(ev)
  593.     }
  594.   end
  595.  
  596.   #--------------------------------------------------------------------------
  597.   # new: First Event With Tag
  598.   # First event on map with specified tag
  599.   #--------------------------------------------------------------------------
  600.   def first_event_tag(tag)
  601.     return nil unless @q_name_tags.has_key?(tag)
  602.     #return @q_name_tags[tag][0]
  603.     @q_name_tags[tag].each{|e|
  604.       return e if e.has_name_tag?(tag)
  605.     }
  606.     return nil
  607.   end
  608.   #--------------------------------------------------------------------------
  609.   # new: Last Event With Tag
  610.   # Last event on map with specified tag
  611.   #--------------------------------------------------------------------------
  612.   def last_event_tag(tag)
  613.     return nil unless @q_name_tags.has_key?(tag)
  614.     #return @q_name_tags[tag][@q_name_tags[tag].length-1]
  615.     @q_name_tags[tag].reverse_each{|e|
  616.       return e if e.has_name_tag?(tag)
  617.     }
  618.   end
  619.   #--------------------------------------------------------------------------
  620.   # new: All Events With Tag
  621.   # All events on map with specified tag
  622.   #--------------------------------------------------------------------------
  623.   def all_event_tag(tag)
  624.     return nil unless @q_name_tags.has_key?(tag)
  625.     #return @q_name_tags[tag]
  626.     return @q_name_tags[tag].select{|e| e.has_name_tag?(tag) }
  627.   end
  628.  
  629.   #--------------------------------------------------------------------------
  630.   # new: get respawn
  631.   # get respawn var
  632.   #--------------------------------------------------------------------------
  633.   def get_respawn(id)
  634.     return $game_respawnVars[id] if $game_respawnVars.has_key?(id)
  635.     return 0
  636.   end
  637.  
  638. end
  639.  
  640.  
  641. class Game_Character < Game_CharacterBase
  642.   #--------------------------------------------------------------------------
  643.   # alias: process_move_command
  644.   #--------------------------------------------------------------------------
  645.   alias process_move_command_movement_cmds_alias process_move_command
  646.   def process_move_command(command)
  647.     case command.code
  648.       when ROUTE_SCRIPT
  649.         return if command.parameters[0].include? '[v]'
  650.     end
  651.     process_move_command_movement_cmds_alias(command)
  652.   end
  653.  
  654.   MOVE_SYMBOL_CODE = {
  655.   :UP    => ROUTE_MOVE_UP,
  656.   :DOWN  => ROUTE_MOVE_DOWN,
  657.   :LEFT  => ROUTE_MOVE_LEFT,
  658.   :RIGHT => ROUTE_MOVE_RIGHT,
  659.   :FORWARD => ROUTE_MOVE_FORWARD,
  660.   :BACKWARD => ROUTE_MOVE_BACKWARD,
  661.   :TOWARD => ROUTE_MOVE_TOWARD,
  662.   :AWAY => ROUTE_MOVE_AWAY,
  663.   }
  664.  
  665.   #--------------------------------------------------------------------------
  666.   # new method: opacity_tween
  667.   #--------------------------------------------------------------------------
  668.   def opacity_tween(opacity, duration)
  669.     crnt_opacity = @opacity
  670.     i = (opacity - crnt_opacity).to_f / duration
  671.     for x in (0..duration)
  672.       @move_route.list.insert(@move_route_index + x + 1, RPG::MoveCommand.new(ROUTE_CHANGE_OPACITY, [crnt_opacity.to_i]))
  673.       crnt_opacity += i
  674.       crnt_opacity = opacity if x == (duration-1)
  675.     end
  676.     @move_route.list.delete_at(@move_route_index)
  677.   end
  678.  
  679.   #--------------------------------------------------------------------------
  680.   # new method: move
  681.   #--------------------------------------------------------------------------
  682.   def move(dir, steps)
  683.     dir = MOVE_SYMBOL_CODE[dir] if dir.is_a?(Symbol)
  684.     for x in (1..steps)
  685.       @move_route.list.insert(@move_route_index + x, RPG::MoveCommand.new(dir))
  686.     end
  687.     @move_route.list.delete_at(@move_route_index)
  688.   end
  689.  
  690.   def gotoxy(x,y)
  691.     @x = x
  692.     @y = y
  693.   end
  694.  
  695.   def moveto2(x, y)
  696.     @x = x % $game_map.width
  697.     @y = y % $game_map.height
  698.     @real_x = @x
  699.     @real_y = @y
  700.   end
  701.  
  702.   def moveto2_d(l, d)
  703.     @y -= l if d == 8
  704.     @y += l if d == 2
  705.     @x -= l if d == 4
  706.     @x += l if d == 6
  707.     @real_x = @x
  708.     @real_y = @y
  709.   end
  710.  
  711.   def set_move_speed(val)
  712.     @move_speed = val
  713.   end
  714.  
  715.   def clear_move_route
  716.     @move_route = nil
  717.     @move_route_index = 0
  718.     @wait_count = 0
  719.   end
  720.  
  721.   def turn_left
  722.     set_direction(4)
  723.   end
  724.   def turn_right
  725.     set_direction(6)
  726.   end
  727.   def turn_up
  728.     set_direction(8)
  729.   end
  730.   def turn_down
  731.     set_direction(2)
  732.   end
  733. end
  734.  
  735. class Game_Player < Game_Character
  736.   alias init_alias initialize
  737.   def initialize
  738.     init_alias
  739.     @move_input_enabled = true
  740.   end
  741.  
  742.   def disable_move_input
  743.     @move_input_enabled = false
  744.   end
  745.  
  746.   def enable_move_input
  747.     @move_input_enabled = true
  748.   end
  749.  
  750.   def in_control?
  751.     return @move_input_enabled
  752.   end
  753.  
  754.   alias qon_movable movable?
  755.   def movable?
  756.     return false if !@move_input_enabled
  757.     qon_movable
  758.   end
  759.  
  760.   #alias move_by_input_alias move_by_input
  761.   #def move_by_input
  762.   #  return if !@move_input_enabled
  763.   #  move_by_input_alias
  764.   #end
  765. end
  766.  
  767. class RPG::Event::Page
  768.   attr_reader :page_tags
  769.   attr_reader :note_tags
  770.   attr_reader :custom_condition
  771.  
  772.   def setup_notetags
  773.     @note_tags = ""
  774.     @page_tags = []
  775.     return if !@list || @list.size <= 0
  776.     # build note tags
  777.     @list.each {|i|
  778.       @note_tags += i.parameters[0] if i && (i.code == 108 || i.code == 408)
  779.     }
  780.     # find page custom condition if there is one
  781.     @custom_condition = note_tags =~ /<CC>(.*)<\/CC>/i ? $1 : nil
  782.    
  783.     # get page tags from note tags
  784.     t = @note_tags.scan(/<t:([^<>]*)>/i)
  785.     return if t.nil? || t.length < 1
  786.     t.each{|pt|
  787.       @page_tags.push(pt[0])
  788.     }
  789.   end
  790. end
  791.  
  792. class Game_Event < Game_Character
  793.  
  794.   #--------------------------------------------------------------------------
  795.   # alias: initialize
  796.   # For event name tags.
  797.   #--------------------------------------------------------------------------
  798.   alias quack_qon_init initialize
  799.   def initialize(map_id, event)
  800.     quack_qon_init(map_id, event)
  801.     pt = []
  802.     @event.pages.each {|p|
  803.       p.setup_notetags
  804.       pt.push(p.page_tags)
  805.     }
  806.     $game_map.add_event_tags(self, pt)
  807.   end
  808.   #--------------------------------------------------------------------------
  809.   # new: Add name tag
  810.   # For event name tags.
  811.   #--------------------------------------------------------------------------
  812.   def add_name_tag(tag)
  813.     if @name_tags.nil?
  814.       @name_tags = [tag]
  815.     else
  816.       @name_tags.push(tag)
  817.     end
  818.   end
  819.   def name_tags
  820.     return [] if @name_tags.nil?
  821.     return @name_tags
  822.   end
  823.   def has_name_tag?(tag)
  824.     unless @name_tags.nil?
  825.       return true if @name_tags.include?(tag)
  826.     end
  827.     return false if @page.nil? || @page.page_tags.nil?
  828.     return true if @page.page_tags.include?(tag)
  829.     return false
  830.   end
  831.   #--------------------------------------------------------------------------
  832.   # new: Return event's name
  833.   # For event name tags.
  834.   #--------------------------------------------------------------------------
  835.   def name
  836.     return @event.name
  837.   end
  838.  
  839.   def page_tags
  840.     return @page.page_tags
  841.   end
  842.  
  843.   def notetags_page
  844.     return @page.note_tags
  845.   #  return "" if !@page || !@page.list || @page.list.size <= 0
  846.   #  return @notetags_page if @notetags_page
  847.   #  @notetags_page = ""
  848.   #  l = []
  849.   #  @page.list.each {|i|
  850.   #    @notetags_page += i.parameters[0] if i && (i.code == 108 || i.code == 408)
  851.   #  }
  852.   #  return @notetags_page
  853.   end  
  854.   def notetags
  855.     return @notetags unless @notetags.nil?
  856.     @notetags = ""
  857.     @event.pages.each {|p|
  858.       next if !p || !p.list || p.list.size <= 0
  859.       @notetags += p.note_tags
  860.     }
  861.     return @notetags
  862.   end
  863.  
  864.   # METHODS FOR CUSTOM EVENT CONDITIONS
  865.  
  866.   alias quack_qon_conditions_met conditions_met?
  867.   def conditions_met?(page)
  868.     r = quack_qon_conditions_met(page)
  869.     return false if has_custom_cond?(page) && custom_cond_fail(page)
  870.     return r
  871.   end
  872.  
  873.   def has_custom_cond?(page)
  874.     !page.custom_condition.nil?
  875.   end
  876.  
  877.   def custom_cond_fail(page)
  878.     return !eval(page.custom_condition)
  879.   end
  880.  
  881.   # METHODS FOR ACCESSING THE EVENTS LOCAL VARIABLES AND SWITCHES
  882.  
  883.   #--------------------------------------------------------------------------
  884.   # new: Get self var
  885.   #--------------------------------------------------------------------------
  886.   def lget(id)
  887.     L[@id,id]
  888.   end
  889.   #--------------------------------------------------------------------------
  890.   # new: Set self var
  891.   #--------------------------------------------------------------------------
  892.   def lset(id,val)
  893.     $game_selfVars[[@map_id,@id,id]] = val
  894.     $game_map.need_refresh = true
  895.   end
  896.  
  897.   #--------------------------------------------------------------------------
  898.   # new: Get self switch
  899.   #--------------------------------------------------------------------------
  900.   def sget(id)
  901.     L[@id,id]
  902.   end
  903.   #--------------------------------------------------------------------------
  904.   # new: Set self switch
  905.   #--------------------------------------------------------------------------
  906.   def sset(id,val)
  907.     $game_self_switches[[@map_id,@id,id]] = val
  908.     $game_map.need_refresh = true
  909.   end
  910.  
  911.   #--------------------------------------------------------------------------
  912.   # new: Get self temp var
  913.   #--------------------------------------------------------------------------
  914.   def tget(id)
  915.     return TMP[@id,id]
  916.   end
  917.   #--------------------------------------------------------------------------
  918.   # new: Set self temp var
  919.   #--------------------------------------------------------------------------
  920.   def tset(id,val)
  921.     $game_tempVars[[@id,id]] = val
  922.     $game_map.need_refresh = true
  923.   end
  924.  
  925.   #--------------------------------------------------------------------------
  926.   # new: Get Page
  927.   # Needed for event page call
  928.   #--------------------------------------------------------------------------
  929.   def get_page(index)
  930.     return @event.pages[index]
  931.   end
  932. end
  933.  
  934. class Game_Interpreter
  935.   #--------------------------------------------------------------------------
  936.   # * Self Vars
  937.   #--------------------------------------------------------------------------
  938.  
  939.   #--------------------------------------------------------------------------
  940.   # new: lget
  941.   # get self var
  942.   #--------------------------------------------------------------------------
  943.   def lget(*arguments)
  944.     result = 0
  945.     case arguments.length
  946.       when 1; result = $game_selfVars[[@map_id, @event_id, arguments[0]]]
  947.       when 2; result = $game_selfVars[[@map_id, arguments[0], arguments[1]]]
  948.       when 3; result = $game_selfVars[[arguments[0], arguments[1], arguments[2]]]
  949.     end
  950.     return result
  951.   end
  952.   #--------------------------------------------------------------------------
  953.   # new: lset
  954.   # set self var
  955.   #--------------------------------------------------------------------------
  956.   def lset(*arguments)
  957.     case arguments.length
  958.       when 2; $game_selfVars[[@map_id, @event_id, arguments[0]]] = arguments[1]
  959.       when 3; $game_selfVars[[@map_id, arguments[0], arguments[1]]] = arguments[2]
  960.       when 4; $game_selfVars[[arguments[0], arguments[1], arguments[2]]] = arguments[3]
  961.     end
  962.     $game_map.need_refresh = true
  963.   end
  964.   #--------------------------------------------------------------------------
  965.   # * Self Switches
  966.   #--------------------------------------------------------------------------
  967.  
  968.   #--------------------------------------------------------------------------
  969.   # new: sget
  970.   # get self switch
  971.   #--------------------------------------------------------------------------
  972.   def sget(*arguments)
  973.     result = false
  974.     case arguments.length
  975.       when 1; result = $game_self_switches[[@map_id, @event_id, arguments[0]]]
  976.       when 2; result = $game_self_switches[[@map_id, arguments[0], arguments[1]]]
  977.       when 3; result = $game_self_switches[[arguments[0], arguments[1], arguments[2]]]
  978.     end
  979.     return result
  980.   end
  981.   #--------------------------------------------------------------------------
  982.   # new: sset
  983.   # set self switch
  984.   #--------------------------------------------------------------------------
  985.   def sset(*arguments)
  986.     case arguments.length
  987.       when 2; $game_self_switches[[@map_id, @event_id, arguments[0]]] = arguments[1]
  988.       when 3; $game_self_switches[[@map_id, arguments[0], arguments[1]]] = arguments[2]
  989.       when 4; $game_self_switches[[arguments[0], arguments[1], arguments[2]]] = arguments[3]
  990.     end
  991.     $game_map.need_refresh = true
  992.   end
  993.  
  994.   #--------------------------------------------------------------------------
  995.   # * Respawn Vars
  996.   #--------------------------------------------------------------------------
  997.  
  998.   #--------------------------------------------------------------------------
  999.   # new: get respawn
  1000.   # get respawn var
  1001.   #--------------------------------------------------------------------------
  1002.   def get_respawn(id)
  1003.     return $game_respawnVars[id] if $game_respawnVars.has_key?(id)
  1004.     return 0
  1005.   end
  1006.   #--------------------------------------------------------------------------
  1007.   # new: set respawn
  1008.   # set respawn var
  1009.   #--------------------------------------------------------------------------
  1010.   def set_respawn(id, value)
  1011.     $game_respawnVars[id] = value
  1012.   end
  1013.  
  1014.   #--------------------------------------------------------------------------
  1015.   # * Easier to remember fade commands
  1016.   #--------------------------------------------------------------------------
  1017.   def fade_in(duration)
  1018.     screen.start_fadein(duration)
  1019.   end
  1020.   def fade_out(duration)
  1021.     screen.start_fadeout(duration)
  1022.   end
  1023.  
  1024.   #--------------------------------------------------------------------------
  1025.   # alias: Temporarily Erase Event
  1026.   # For event name tags
  1027.   #--------------------------------------------------------------------------
  1028.   alias quack_qon_command_214 command_214
  1029.   def command_214
  1030.     $game_map.delete_event_tags($game_map.events[@event_id])
  1031.     quack_qon_command_214
  1032.   end
  1033.  
  1034.   #--------------------------------------------------------------------------
  1035.   # overwrite method: command_205 (Set Move Route)
  1036.   # ---------------------------------------------------
  1037.   # By making the first command in a move route a script call which starts
  1038.   # with '[v]' the rest of the script call be evaluated to an integer which
  1039.   # is used as character id to chose which event the move route pertains to.
  1040.   #--------------------------------------------------------------------------
  1041.   def command_205 # COMMAND SET MOVE ROUTE
  1042.     $game_map.refresh if $game_map.need_refresh
  1043.     character = get_character(@params[0])
  1044.     cmd = @params[1].list[0]
  1045.     if cmd.code == 45 # 45 = SCRIPT COMMAND
  1046.       if cmd.parameters[0].include? '[v]'
  1047.         @params[0] = eval(cmd.parameters[0][3..cmd.parameters[0].length])
  1048.         character = get_character(@params[0])
  1049.         #@params[1].list.delete_at(0)
  1050.       end
  1051.     end
  1052.     if character
  1053.       character.force_move_route(@params[1].dup)
  1054.       Fiber.yield while character.move_route_forcing if @params[1].wait
  1055.     end
  1056.   end
  1057.  
  1058.   #==========================================================================
  1059.   # * Jump to Label (edited to allow to jump to a label using a variable)
  1060.   #==========================================================================
  1061.   def command_119
  1062.     label_name = @params[0]
  1063.     if label_name.include? '[v]'
  1064.       label_name = eval(label_name[3..label_name.length])
  1065.     end
  1066.     @list.size.times do |i|
  1067.       if @list[i].code == 118 && @list[i].parameters[0] == label_name
  1068.         @index = i
  1069.         return
  1070.       end
  1071.     end
  1072.   end
  1073.  
  1074.   #==========================================================================
  1075.   # * Call event page
  1076.   #==========================================================================
  1077.   def call_event(event_id, page_id)
  1078.     qq = Game_Interpreter.new(@depth + 1)
  1079.     page = evs[event_id].get_page(page_id)
  1080.     qq.setup(page.list, event_id)
  1081.     qq.run
  1082.   end
  1083.  
  1084.   def ev; @event_id; end
  1085.   def evs; $game_map.events; end
  1086.   def events; $game_map.events; end
  1087.   def me; evs[ev]; end
  1088.   def pl; $game_player; end
  1089.   def player; $game_player; end
  1090.   def char(id); get_character(id); end
  1091.   def map; return $game_map; end
  1092.   def set_move_speed(char_id, val)
  1093.     get_character(char_id).set_move_speed(val)
  1094.   end
  1095.  
  1096.   def move_to_point(id,x,y,wait=false)
  1097.     c = char(id)
  1098.     c.move_to_point(x,y)
  1099.     Fiber.yield while c.move_route_forcing if wait
  1100.   end
  1101.  
  1102.   #--------------------------------------------------------------------------
  1103.   # new: First event with tag
  1104.   #--------------------------------------------------------------------------
  1105.   def first_event_tag(tag)
  1106.     $game_map.first_event_tag(tag)
  1107.   end
  1108.   #--------------------------------------------------------------------------
  1109.   # new: Last event with tag
  1110.   #--------------------------------------------------------------------------
  1111.   def last_event_tag(tag)
  1112.     $game_map.last_event_tag(tag)
  1113.   end
  1114.   #--------------------------------------------------------------------------
  1115.   # new: All events with tag
  1116.   #--------------------------------------------------------------------------
  1117.   def all_event_tag(tag)
  1118.     $game_map.all_event_tag(tag)
  1119.   end
  1120.   #--------------------------------------------------------------------------
  1121.   # new: Find all events with all the specified tags
  1122.   #--------------------------------------------------------------------------
  1123.   def find_events(*args)
  1124.     result = []
  1125.     evs.keys.each {|k|
  1126.       unless evs[k].name_tags.nil?
  1127.         if (args - evs[k].name_tags).empty?
  1128.           result.push(evs[k])
  1129.         end
  1130.       end
  1131.     }
  1132.     return result
  1133.   end
  1134.  
  1135.   def diff(val1, val2)
  1136.     return (val1 - val2).abs
  1137.   end
  1138.  
  1139.   def pos_diff(c1, c2)
  1140.     xd = c1.x - c2.x
  1141.     yd = c1.y - c2.y
  1142.     xd *= xd
  1143.     yd *= yd
  1144.     return Math.sqrt(xd+yd)
  1145.   end
  1146.  
  1147.   #returns true if the distance between char1 and char2 is greater than dist
  1148.   def distance_gt(ev1,ev2,dist)#id1, id2, dist)
  1149.     #xd = char(id1).x - char(id2).x
  1150.     #yd = char(id1).y - char(id2).y
  1151.     xd = ev1.x - ev2.x
  1152.     yd = ev1.y - ev2.y
  1153.     xd *= xd
  1154.     yd *= yd
  1155.     return (xd + yd) > dist * dist
  1156.   end
  1157.  
  1158.   # returns true if the difference between val1 and val2 is greater than i.
  1159.   def diff_gt(val1, val2, i)
  1160.     diff(val1,val2) > i
  1161.   end
  1162.  
  1163.   # returns true if the position1 is equal to position2
  1164.   def pos_is?(*arg)
  1165.     case arg.length
  1166.       when 1
  1167.         c = arg[0]#get_character(arg[0])
  1168.         return c.x == me.x && c.y == me.y
  1169.       when 2
  1170.         c1 = arg[0]#get_character(arg[0])
  1171.         c2 = arg[1]#get_character(arg[1])
  1172.         return c1.x == c2.x && c1.y == c2.y
  1173.       when 3
  1174.         c1 = arg[0]#get_character(arg[0])
  1175.         return c1.x == arg[1] && c2.y == arg[2]
  1176.       when 4
  1177.         return arg[0] == arg[2] && arg[1] == arg[3]
  1178.     end
  1179.     return false
  1180.   end
  1181.  
  1182.   # Returns in which of the 4 directions char2 is related to char1
  1183.   def ev_dir(char1, char2)
  1184.     if diff(char1.x, char2.x) > diff(char1.y,char2.y)
  1185.       if char1.x < char2.x
  1186.         return 6
  1187.       else
  1188.         return 4
  1189.       end
  1190.     else
  1191.       if char1.y < char2.y
  1192.         return 2
  1193.       else
  1194.         return 8
  1195.       end
  1196.     end
  1197.   end
  1198.  
  1199.   def wait_rnd(min_dur, max_dur)
  1200.     duration = min_dur + rnd(max_dur - min_dur).to_i
  1201.     duration.times { Fiber.yield }
  1202.   end
  1203.  
  1204.   def break_loop #becuz who can remember that 113 = break?
  1205.     command_113
  1206.   end
  1207.  
  1208.   # Prepare for cutscene
  1209.   def prep_scene
  1210.     $game_system.menu_disabled = true
  1211.     $game_system.save_disabled = true
  1212.     pl.disable_move_input
  1213.   end
  1214.  
  1215.   #end cutscene
  1216.   def end_scene
  1217.     $game_system.menu_disabled = false
  1218.     $game_system.save_disabled = false
  1219.     pl.enable_move_input
  1220.   end
  1221. end
RAW Paste Data