Advertisement
Loque

Move route extra

Jun 19th, 2014
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.78 KB | None | 0 0
  1. #------------------------------------------------------------------------------#
  2. #  Galv's Move Route Extras
  3. #------------------------------------------------------------------------------#
  4. #  For: RPGMAKER VX ACE
  5. #  Version 1.9
  6. #------------------------------------------------------------------------------#
  7. #  2013-07-30 - Version 1.9 - added move toward and away from x,y
  8. #  2013-04-25 - Version 1.8 - added turn toward event
  9. #  2013-03-22 - Version 1.7 - move randomly only in region id's specified
  10. #  2013-03-14 - Version 1.6 - added activating other events
  11. #  2013-03-14 - Version 1.5 - fixed a bug with jumping to xy, added jump forward
  12. #  2013-03-12 - Version 1.4 - added random wait and play animation
  13. #  2013-03-12 - Version 1.3 - added changing priortiy level
  14. #  2013-03-12 - Version 1.2 - added repeating multiple commands
  15. #  2013-03-12 - Version 1.1 - added fading in/out and repeating move commands
  16. #  2013-03-12 - Version 1.0 - release
  17. #------------------------------------------------------------------------------#
  18. #  This script was written to fill some gaps the move route commands left out.
  19. #  Script commands can be used in move routes (for events and player) to:
  20. #  - Jump to x,y coordinates on the map
  21. #  - Jump to an event's or player's current location
  22. #  - Jump forward (the direction currently facing) x number of tiles
  23. #  - Move toward or away from an event
  24. #  - Move toward or away from x,y location
  25. #  - Turn self switches on and off
  26. #  - Change charset to any pose without that 'visible turning frame'
  27. #  - Repeat move commands
  28. #  - Change the priority level (under, same as, above player)
  29. #  - Play animation/balloon
  30. #  - Activate an event below or in front of
  31. #  - Move in a random direction only on a specified region
  32. #------------------------------------------------------------------------------#
  33.  
  34. #------------------------------------------------------------------------------#
  35. #  SCRIPTS to use within MOVE ROUTES
  36. #------------------------------------------------------------------------------#
  37. #
  38. #  jump_to(x,y)               # jumps to that x,y location
  39. #  jump_to_char(id)           # jumps to event with that id or -1 for player
  40. #  jump_forward(x)            # jump forward x amount of tiles
  41. #
  42. #  move_toward_event(id)      # steps toward event with that id.
  43. #  move_away_from_event(id)   # moves away from event with that id.
  44. #  turn_toward_event(id)      # turns toward event with that id
  45. #
  46. #  move_toward_xy(x,y)        # steps toward x,y coordinates
  47. #  move_away_from_xy(x,y)     # steps away from x,y coordinates
  48. #
  49. #  fadeout(speed)             # fade out an event at the speed specified
  50. #  fadein(speed)              # fade in an event at the speed specified
  51. #
  52. #  repeat(x)                  # repeat all commands between this and end_repeat
  53. #  end_repeat                 # and do it x number of times.
  54. #
  55. #  repeat_next(x)             # repeat the following move command x times
  56. #
  57. #  char_level(x)              # change the character's level to x (0-2)
  58. #                             # 0 = below    1 = same as player    2 = above
  59. #
  60. #  anim(id)                   # play animation with that id on character
  61. #  balloon(id)                 # pops ballon with that id above player
  62. #
  63. #  wait(a,b)                  # wait a random amount of frames between a and b
  64. #
  65. #  self_switch("switch",status)    # turns self switch on or off (true or false)
  66. #  self_switch("switch",status,x)  # turns self switch on/off for event id x
  67. #
  68. #  set_char("Charset",index,col,dir)  # Change event graphic to any charset pose
  69. #                                     # index = character in the charset (1-8)
  70. #                                     # col = the column/step of graphic (1-3)
  71. #                                     # dir = direction (2,4,6,8)
  72. #
  73. #  restore_char       # restores event animation (that was disabled by set_char)
  74. #
  75. #  activate_event(type)     # activates another event...
  76. #                           # type 0 is below it, type 1 is in front of it.
  77. #                           # NOTE: If the move route is "wait for completition
  78. #                           # then the other event won't start until the current
  79. #                           # move route is finished.
  80. #
  81. #  random_region(x,x,x)     # Move in a random direction ONLY on the region ids
  82. #                           # specified (x's) to keep NPC's where they belong.
  83. #
  84. #------------------------------------------------------------------------------#
  85. #  EXAMPLES OF USE:
  86. #
  87. #  set_char("Damage3",5,1,4)   # 5th actor, left facing, column 1 of Damage3
  88. #  self_switch("A",true)       # turns self switch A ON
  89. #  self_switch("C",false)      # turns self switch C OFF
  90. #  fadeout(10)                 # gradually fades the event out at speed 10
  91. #  anim(66)                    # play animation with id 66
  92. #  wait(50,100)                # wait a random amount of frames between 50 & 100
  93. #  char_level(0)               # set level as below player
  94. #  random_region(1,2,3,4,5)    # will move a random direction on these regions
  95. #  repeat_next(9)              # repeats the next move command 9 times
  96. #
  97. #  repeat(10)                  # Will repeat moving forward and turning 10 times
  98. #  - Move Forward
  99. #  - Turn 90 degrees left
  100. #  end_repeat
  101. #
  102. #
  103. #  move_toward_xy(10,5)        # Moves toward tile at coordinates x10, y5
  104. #  move_toward_xy($game_varables[1],$game_varables[2])  # same as above using
  105. #                                                       # stored variables
  106. #------------------------------------------------------------------------------#
  107.  
  108.  
  109. #------------------------------------------------------------------------------#
  110. #  NO SETTINGS FOR YOU! Script calls only for this one :)
  111. #------------------------------------------------------------------------------#
  112.  
  113. class Game_Character < Game_CharacterBase
  114.   def jump_to(x,y)
  115.     sx = distance_x_from(x)
  116.     sy = distance_y_from(y)
  117.     jump(-sx,-sy)
  118.   end
  119.  
  120.   def jump_to_char(id)
  121.     if id <= 0
  122.       sx = distance_x_from($game_player.x)
  123.       sy = distance_y_from($game_player.y)
  124.     else
  125.       sx = distance_x_from($game_map.events[id].x)
  126.       sy = distance_y_from($game_map.events[id].y)
  127.     end
  128.     jump(-sx,-sy)
  129.   end
  130.  
  131.   def jump_forward(count)
  132.     sx = 0; sy = 0
  133.     case @direction
  134.     when 2; sy = count
  135.     when 8; sy = -count
  136.     when 4; sx = -count
  137.     when 6; sx = count
  138.     end
  139.     jump(sx,sy)
  140.   end
  141.  
  142.   def set_char(name,index,pattern,direction)
  143.     @gstop = true
  144.     @direction = direction
  145.     @pattern = pattern - 1
  146.     @character_name = name
  147.     @character_index = index - 1
  148.   end
  149.  
  150.   def restore_char
  151.     @gstop = false
  152.   end
  153.  
  154.   alias galv_move_extras_gc_update_anime_pattern update_anime_pattern
  155.   def update_anime_pattern
  156.     return if @gstop
  157.     galv_move_extras_gc_update_anime_pattern
  158.   end
  159.  
  160.   def move_toward_event(id)
  161.     move_toward_xy($game_map.events[id].x,$game_map.events[id].y)
  162.   end
  163.  
  164.   def move_toward_xy(sx,sy)
  165.     sx = distance_x_from(sx)
  166.     sy = distance_y_from(sy)
  167.     if sx.abs > sy.abs
  168.       move_straight(sx > 0 ? 4 : 6)
  169.       move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
  170.     elsif sy != 0
  171.       move_straight(sy > 0 ? 8 : 2)
  172.       move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
  173.     end
  174.   end
  175.  
  176.   def turn_toward_event(id)
  177.     turn_toward_character($game_map.events[id])
  178.   end
  179.  
  180.   def move_away_from_event(id)
  181.     move_away_from_xy($game_map.events[id].x,$game_map.events[id].y)
  182.   end
  183.  
  184.   def move_away_from_xy(sx,sy)
  185.     sx = distance_x_from(sx)
  186.     sy = distance_y_from(sy)
  187.     if sx.abs > sy.abs
  188.       move_straight(sx > 0 ? 6 : 4)
  189.       move_straight(sy > 0 ? 2 : 8) if !@move_succeed && sy != 0
  190.     elsif sy != 0
  191.       move_straight(sy > 0 ? 2 : 8)
  192.       move_straight(sx > 0 ? 6 : 4) if !@move_succeed && sx != 0
  193.     end
  194.   end
  195.  
  196.   def self_switch(switch,status,id = @id)
  197.     return if $game_self_switches[[@map_id,id,switch]].nil?
  198.     $game_self_switches[[@map_id,id,switch]] = status
  199.   end
  200.  
  201.   def fadeout(speed)
  202.     @opacity -= (speed)
  203.     @move_route_index -= 1 if @opacity > 0
  204.   end
  205.   def fadein(speed)
  206.     @opacity += (speed)
  207.     @move_route_index -= 1 if @opacity < 255
  208.   end
  209.  
  210.   def repeat_next(times)
  211.     @crepeat_next = times - 1
  212.   end
  213.  
  214.   def repeat(times)
  215.     @crepeats = times - 1
  216.     @index_position = @move_route_index
  217.   end
  218.  
  219.   def end_repeat
  220.     if @crepeats > 0
  221.       @crepeats -= 1
  222.       @move_route_index = @index_position if @index_position
  223.     else
  224.       @index_position = nil
  225.     end
  226.   end
  227.  
  228.   def char_level(type)
  229.     @priority_type = type
  230.   end
  231.  
  232.   def anim(id)
  233.     @animation_id = id
  234.   end
  235.   def balloon(id)
  236.     @balloon_id = id
  237.   end
  238.  
  239.   def wait(low,high)
  240.     @wait_count = (rand(low - high) + low).to_i
  241.   end
  242.  
  243.   alias galv_move_extras_gc_init_private_members init_private_members
  244.   def init_private_members
  245.     @crepeats = 0
  246.     @crepeat_next = 0
  247.     galv_move_extras_gc_init_private_members
  248.   end
  249.  
  250.   alias galv_move_extras_gc_process_move_command process_move_command
  251.   def process_move_command(command)
  252.     if @crepeat_next > 0
  253.       @move_route_index -= 1
  254.       @crepeat_next -= 1
  255.     end
  256.     galv_move_extras_gc_process_move_command(command)
  257.   end
  258.  
  259.   def activate_event(type)
  260.     sx = 0; sy = 0
  261.     if type != 0
  262.       case @direction
  263.       when 2; sy = 1
  264.       when 8; sy = -1
  265.       when 4; sx = -1
  266.       when 6; sx = 1
  267.       end
  268.     end
  269.     $game_map.events_xy(@x + sx, @y + sy).each do |event|
  270.       event.start unless event.id == @id
  271.     end
  272.   end
  273.  
  274.   def random_region(*args)
  275.     r = [*args]
  276.     dir = 2 + rand(4) * 2
  277.     sx = 0; sy = 0
  278.     case dir
  279.     when 2; sy = 1
  280.     when 8; sy = -1
  281.     when 4; sx = -1
  282.     when 6; sx = 1
  283.     end
  284.     return if !r.include?($game_map.region_id(@x + sx, @y + sy))
  285.     move_straight(dir, false)
  286.   end
  287.  
  288. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement