Guest User

Troublesome Code

a guest
Apr 2nd, 2015
221
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##### This is the problematic part of my script. I left out the vast majority of
  2. ##### my script because this is the only part causing problems.
  3.  
  4.  
  5. class Game_Map # didn't alias because I couldn't seem to get the alias to work  
  6.                # properly.
  7.   def update(main = false)
  8.     refresh if @need_refresh
  9.     update_interpreter if main
  10.     update_scroll
  11.     update_events
  12.     update_vehicles
  13.     update_parallax
  14.     @screen.update
  15.     if $weather != nil && $weather.raining == true # if weather object exists and
  16.       $weather.precipAnim                          # it is currently raining
  17.     end
  18.   end
  19.  
  20.  
  21.   def any_direction_passable?(x, y, directions = 0b1111) # by Another Fen to
  22.                                               # easier check for tile passability
  23.     tile = all_tiles(x, y).find { |tile_id| tileset.flags[tile_id] & 0x10 == 0 }
  24.     return (tile != nil and (directions & ~tileset.flags[tile]) != 0)
  25.   end
  26.  
  27. end
  28.  
  29.  
  30. # code to allow spawning an event from the event spawn map
  31. def spawn_event(spawn_from_map_id, _map_id, _event_id, _x, _y)
  32.   map = load_data(sprintf("Data/Map%03d.rvdata2", spawn_from_map_id))
  33.   event_id = $game_map.events.keys.max + 1
  34.   preprocess = map.events[_event_id]
  35.   preprocess.id = event_id
  36.   event = $game_map.events[event_id] = Game_Event.new(_map_id, preprocess)
  37.   sp_map = SceneManager.scene.instance_eval('@spriteset')
  38.   sp_map_char_sprs = sp_map.instance_eval('@character_sprites')
  39.   sp_map_view_1 = sp_map.instance_eval('@viewport1')
  40.   sp_map_char_sprs.push(Sprite_Character.new(sp_map_view_1, event))
  41.   event.moveto(_x, _y)
  42. end
  43.  
  44. # begin of partial problematic code
  45. class DrykulWeatherSystem  
  46.  
  47.   attr_accessor :raining
  48.   attr_accessor :firstSplashId
  49.   attr_accessor :splashEventIds
  50.  
  51.   def initialize
  52.     @raining = false      # check for current weather type
  53.     @haltAnim = false     # pause to allow events to delete themselves
  54.     @firstSplashId = 0    # the very first splash event to spawn in's event ID
  55.     @splashCounter = 0    # var. init so all events don't spawn at the same time
  56.     @splashEventIds = []  # array init, contains all existing splash event IDs
  57.     end
  58.  
  59.   def precipAnim
  60.    
  61.     if @haltAnim == false
  62.       if @firstSplashId != 0
  63.         tooManyEvents = @firstSplashId + 14
  64.         check = @splashEventIds.size - 1      
  65.         if @splashEventIds[check] > tooManyEvents
  66.           @haltAnim = true
  67.           return
  68.         end
  69.       end
  70.       if @splashCounter == 5
  71.         xVariance = rand(8)
  72.         yVariance = rand(6)
  73.         dirVarianceCalc = rand(2)
  74.         if dirVarianceCalc == 1
  75.           dirVariance = 1
  76.         else
  77.           dirVariance = -1
  78.         end
  79.         splashXpos = $game_player.x + (xVariance * dirVariance)
  80.         splashYpos = $game_player.y + (yVariance * dirVariance)
  81.         if $game_map.any_direction_passable?(splashXpos, splashYpos) == true
  82.           spawn_event(2, 1, 1, splashXpos, splashYpos)
  83.           @splashCounter = 0
  84.         end
  85.       else
  86.         @splashCounter += 1
  87.       end
  88.     else
  89.       if @splashEventIds.size == 0
  90.         @firstSplashId = 0
  91.         @splashCounter = 0
  92.         @haltAnim = false
  93.       end
  94.     end
  95.   end    
  96. end
  97.  
  98. ##### This next bit of code is in the splash event template set to parallel process. The event is on a different map that is
  99. ##### reserved for template events that will be spawned in.
  100.  
  101. if $weather.firstSplashId == 0
  102.  $weather.firstSplashId = @event_id
  103. end
  104. $weather.splashEventIds[$weather.splashEventIds.size] = @event_id
  105.  
  106. # Next is an event command Wait for 25 frames. After words this code snippet:
  107.  
  108. $weather.splashEventIds.delete(@event_id)
  109. e = $game_map.events.delete(@event_id)
  110. e.erase unless e.nil?
RAW Paste Data