TheoAllen

Theo - Random Event Location by Region

Jun 16th, 2013
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.64 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Random Event Location
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_RandEventLocation] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.06.15 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Perkenalan :
  16.   Script ini berfungsi untuk menempatkan event secara acak berdasar region id
  17.   yang telah diset.
  18.  
  19.   Cara penggunaan :
  20.   Pasang dibawah material namun diatas main
  21.   Tulis comment pada event dengan format seperti ini
  22.  
  23.   <rand pos: n>
  24.   <rand pos: n,m>
  25.  
  26.   Dimana n adalah region id. Kamu bisa menulis region id sebanyak-banyaknya.
  27.  
  28.   Terms of use :
  29.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  30.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  31.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  32.  
  33. =end
  34. # =============================================================================
  35. # Tidak ada konfigurasi :
  36. # =============================================================================
  37. module THEO
  38.   module MAP
  39.   module REGEXP
  40.     RAND_REGION = /<(?:RAND_POS|rand pos): [ ]*[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  41.   end
  42.   end
  43. end
  44.  
  45. class Game_Map
  46.  
  47.   include THEO::MAP
  48.   Point = Struct.new(:x,:y)
  49.  
  50.   alias pre_rand_location_setup setup
  51.   def setup(map_id)
  52.     pre_rand_location_setup(map_id)
  53.     setup_rand_events_location
  54.   end
  55.  
  56.   def setup_rand_events_location
  57.     @events.values.each do |event|
  58.       event.list.each do |cmd|
  59.         code = cmd.code
  60.         next unless code == 108 || code == 408
  61.         case cmd.parameters[0]
  62.         when REGEXP::RAND_REGION
  63.           points = []
  64.           $1.scan(/\d+/).each do |region|
  65.             points += get_region_points(region.to_i)
  66.           end
  67.           next if points.empty?
  68.           selected = rand(points.size)
  69.           x_pos = points[selected].x
  70.           y_pos = points[selected].y
  71.           event.moveto(x_pos,y_pos)
  72.         end
  73.       end
  74.     end
  75.   end
  76.  
  77.   def get_region_points(reg_id)
  78.     result = []
  79.     for x_pos in 0..width
  80.       for y_pos in 0..height
  81.         result.push(Point.new(x_pos,y_pos)) if region_id(x_pos,y_pos) == reg_id
  82.       end
  83.     end
  84.     return result
  85.   end
  86.  
  87. end
Advertisement
Add Comment
Please, Sign In to add comment