SHARE
TWEET

Eventing Tuning

Vlue Aug 5th, 2012 3,110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Eventing: Fine Tuning v3.4 ##
  2. # Fine tune the x-y position, zoom, rotation, hue, as well as mirror and
  3. #   flash event's sprites!
  4. #
  5. # Usage: All script calls are made with set move route
  6. #          offset(x,y)             within set move route x and y are equal to
  7. #                                   the number of pixels to be offset
  8. #
  9. #          set_zoom(zoom)          where zoom is a number
  10. #
  11. #          rotate(angle)           where angle is a number from -360 to 360
  12. #
  13. #          blend(color)            where color is a color object
  14. #                                   -> Color.new(red,blue,green,alpha)
  15. #
  16. #          mirrored                toggles mirror effect
  17. #
  18. #          flash(color,duration)   where color is a color object and duration
  19. #                                   is the length of the flash
  20. #
  21. #          slide(x, y)             offsets the sprite, but moves them to the
  22. #                                   position instead of transfering
  23. #
  24. #          waypoint(x,y)           will cause the character to head towards the
  25. #                                   specified point. Next command starts after
  26. #                                   point is reached.
  27. #
  28. #          moveto(x,y)             Not actually a new command, but one that is
  29. #                                   nice to know, transfers event to specified
  30. #                                   point.
  31. #
  32. #          fadein                  Fades the character to 255 opacity based
  33. #          fadein(duration)         on duration. Default of 10 frames.
  34. #
  35. #          fadeout                 Fades the character to 0 opacity based
  36. #          fadeout(duration)        on duration. Default of 10 frames.
  37. #
  38. #          shake                   Shakes the sprite, default duration of 30
  39. #          shake(duration)          frames.
  40. #
  41. #          random                  Moves the character to a random location
  42. #          random(width,height)     on the map. Can specify maximum range.
  43. #
  44. #          random_region(id)       Moves the character to a random location on
  45. #          random_region(id,w,h)    the map with the same region. Can specify
  46. #                                   maximum range.
  47. #
  48. #      self_switch("letter",value) Sets the self switch of the event. Letter is
  49. #                                   "A" to "D", value is true or false.
  50. #
  51. #          balloon(id)             Plays the specific balloon animation on the
  52. #                                   char
  53. #
  54. #      Newer Commands:
  55. #          jump_forward(length)    Makes the character jump in the direction they
  56. #                                   are facing, or backwards if negative.
  57. #          jump_side(length)       Makes the character jump to their left, or
  58. #                                   right if negative.
  59. #          jumpto(x, y)            Makes the character jump to the specified coords
  60. #
  61. #          memorize                Saves the event's current position
  62. #          recall                  Transfers event to saved position, or origin
  63. #                                   if position not set
  64. #          recall_walk             Walks the character to it's saved position
  65. #
  66. #          reset                   Resets all Fine Tuning details
  67. #          restart                 Resets the event completely, not self switches
  68. #          restart(true)           Resets the event completely and self switches
  69. #
  70. #          moveto_player           Transfers the event to the player
  71. #          moveto_player(true)     Walks the event to the player
  72. #
  73. #          moveto_event(id)        Transfers the event to the specified event
  74. #          moveto_event(id, true)  Walks the event to the specified event
  75. #
  76. #      play_animation(event, anim) Plays the specified animation on the specified
  77. #                                   event
  78. #
  79. #                                  
  80. #------#
  81. #-- Script by: V.M of D.T
  82. #
  83. #- Questions or comments can be:
  84. #    given by email: sumptuaryspade@live.ca
  85. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  86. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  87. #
  88. #--- Free to use in any project, commercial or non-commercial, with credit given
  89. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  90.  
  91. EVENTING_USE_DIR8 = false
  92.  
  93. class Game_CharacterBase
  94.   alias shake_init_public_members init_public_members
  95.   alias shake_update update
  96.   alias shake_moveto moveto
  97.  
  98.   attr_accessor   :zoom
  99.   attr_accessor   :flash_on
  100.   attr_accessor   :flash_color
  101.   attr_accessor   :flash_time
  102.   attr_accessor   :angle
  103.   attr_accessor   :mirror
  104.   attr_accessor   :blend_color
  105.  
  106.   def init_public_members
  107.     shake_init_public_members
  108.     reset_event_details
  109.   end
  110.   def reset_event_details
  111.     @shakechar = [false, 0, 0]
  112.     @zoom = 1
  113.     @flash_on = false
  114.     @flash_color = Color.new(0,0,0,0)
  115.     @flash_duration = 0
  116.     @angle = 0
  117.     @total_angle = 0
  118.     @mirror = false
  119.     @blend_color = Color.new(0,0,0,0)
  120.     @fade = @opacity
  121.     @fade_time = 0
  122.     @shake_time = 0
  123.     @shake_direction = 0
  124.     @memo_x = -1
  125.     @memo_y = -1
  126.   end
  127.   def offset(x,y); @shakechar = [true, x, y]; end
  128.   def reset
  129.     reset_event_details
  130.     rotate(@total_angle*-1)
  131.   end
  132.   def set_zoom(size); @zoom = size; end
  133.   def flash(color,duration)
  134.     @flash_color = color
  135.     @flash_time = duration
  136.     @flash_on = true
  137.   end
  138.   def rotate(angle)
  139.     @total_angle += angle
  140.     @angle = angle
  141.   end
  142.   def flashoff; @flash_on = false; end
  143.   def mirrored; @mirror == true ? @mirror = false : @mirror = true; end
  144.   def blend(color); @blend_color = color; end
  145.   def screen_x
  146.     if @shakechar[0] == false || @shakechar[1] == nil then
  147.       $game_map.adjust_x(@real_x) * 32 + 16 else
  148.       $game_map.adjust_x(@real_x) * 32 + 16 + @shakechar[1] end
  149.   end
  150.   def screen_y
  151.     if @shakechar[0] == false || @shakechar[2] == nil then
  152.       $game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height else
  153.       $game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height + @shakechar[2] end
  154.   end
  155.   def slide(x, y)
  156.     @slide_x = x + @shakechar[1]
  157.     @slide_y = y + @shakechar[2]
  158.     @step_anime = true
  159.     @shakechar[0] = true
  160.     @sliding = true
  161.   end
  162.   def fadein(time = 10)
  163.     @fade_time = time
  164.     @fade = 255
  165.   end
  166.   def fadeout(time = 10)
  167.     @fade_time = time
  168.     @fade = 0
  169.   end
  170.   def shake(time = 30)
  171.     @shakechar[0] = true
  172.     @shake_time = time
  173.   end
  174.   def random(rect_x = 250, rect_y = 250)
  175.     tiles = []
  176.     tiles = tile_array(rect_x,rect_y)
  177.     tiles = tiles.compact
  178.     return if tiles.empty?
  179.     tile = rand(tiles.size)
  180.     moveto(tiles[tile][0],tiles[tile][1])
  181.   end
  182.   def random_region(id, rect_x = 250, rect_y = 250)
  183.     tiles = tile_array(rect_x,rect_y)
  184.     tiles.each_index do |i|
  185.       next if tiles[i].nil?
  186.       erase = false
  187.       erase = true unless $game_map.region_id(tiles[i][0], tiles[i][1]) == id
  188.       tiles[i] = nil if erase
  189.     end
  190.     tiles = tiles.compact
  191.     return if tiles.empty?
  192.     tile = rand(tiles.size)
  193.     moveto(tiles[tile][0],tiles[tile][1])
  194.   end
  195.   def random_wait(min, max)
  196.     @wait_count = rand(max-min) + min - 1
  197.   end
  198.   def tile_array(rect_x,rect_y)
  199.     tiles = [];nx = 0;ny = 0
  200.     ($game_map.width * $game_map.height).times do |i|
  201.       tiles.push([nx,ny])
  202.       nx += 1
  203.       if nx == $game_map.width
  204.         nx = 0
  205.         ny += 1
  206.       end
  207.     end
  208.     tiles.each_index do |i|
  209.       erase = false
  210.       erase = true if tiles[i][0] == $game_player.x && tiles[i][1] == $game_player.y
  211.       erase = true if tiles[i][0] == x && tiles[i][1] == y
  212.       erase = true if tiles[i][0] > x + rect_x || tiles[i][0] < x - rect_x
  213.       erase = true if tiles[i][1] > y + rect_y || tiles[i][1] < y - rect_y
  214.       erase = true if !$game_map.check_passage(tiles[i][0], tiles[i][1], 0x0f)
  215.       tiles[i] = nil if erase
  216.     end
  217.     return tiles
  218.   end
  219.   def self_switch(symbol, boolean)
  220.     return if !self.is_a?(Game_Event)
  221.     key = [$game_map.map_id, @event.id, symbol]
  222.     $game_self_switches[key] = boolean
  223.   end
  224.   def balloon(id)
  225.     @balloon_id = id
  226.   end
  227.   def update
  228.     shake_update
  229.     update_sliding if @sliding
  230.     update_fading if @opacity != @fade && @fade_time > 0
  231.     update_shake if @shake_time > 0
  232.   end
  233.   def update_fading
  234.     @opacity += (255 / @fade_time) if @fade > @opacity
  235.     @opacity -= (255 / @fade_time) if @fade < @opacity
  236.     @opacity = 0 if @opacity < 0; @opacity = 255 if @opacity > 255
  237.     @fade_time = 0 if @opacity == 0 || @opacity == 255
  238.   end
  239.   def update_sliding
  240.     @shakechar[1] += 0.5 if @slide_x > @shakechar[1]
  241.     @shakechar[1] -= 0.5 if @slide_x < @shakechar[1]
  242.     @shakechar[2] += 0.5 if @slide_y > @shakechar[2]
  243.     @shakechar[2] -= 0.5 if @slide_y < @shakechar[2]
  244.     return unless screen_x == @next_x
  245.     return unless screen_y == @next_y
  246.     @sliding = false
  247.     @step_anime = false
  248.   end
  249.   def update_shake
  250.     @shake_time -= 1
  251.     @shakechar[2] += 1 if @shake_direction == 0
  252.     @shakechar[2] -= 1 if @shake_direction == 1
  253.     if @shake_time % 3 == 0
  254.       @shake_direction += 1
  255.       @shake_direction = 0 if @shake_direction > 1
  256.     end
  257.   end
  258.   def moveto(x,y)
  259.     shake_moveto(x,y)
  260.     @memo_x = @x if @memo_x < 0
  261.     @memo_y = @y if @memo_y < 0
  262.   end
  263.   def jump_forward(length)
  264.     x = 0; y = 0
  265.     x += length if @direction == 6
  266.     x -= length if @direction == 4
  267.     y += length if @direction == 2
  268.     y -= length if @direction == 8
  269.     jump(x,y)
  270.   end
  271.   def jump_side(length)
  272.     x = 0; y = 0
  273.     y += length if @direction == 6
  274.     y -= length if @direction == 4
  275.     x += length if @direction == 2
  276.     x -= length if @direction == 8
  277.     jump(x,y)
  278.   end
  279.   def jumpto(x,y)
  280.     x = x - @x
  281.     y = y - @y
  282.     jump(x,y)
  283.   end
  284.   def memorize
  285.     @memo_x = @x
  286.     @memo_y = @y
  287.   end
  288.   def recall
  289.     moveto(@memo_x, @memo_y)
  290.   end
  291.   def recall_walk
  292.     waypoint(@memo_x, @memo_y)
  293.   end
  294.   def restart(switches = false)
  295.     initialize(@map_id, @event)
  296.     if switches
  297.       self_switch("A", false)
  298.       self_switch("B", false)
  299.       self_switch("C", false)
  300.       self_switch("D", false)
  301.     end
  302.   end
  303.   def moveto_player(wp = false)
  304.     if wp
  305.       waypoint($game_player.x, $game_player.y)
  306.     else
  307.       moveto($game_player.x, $game_player.y)
  308.     end
  309.   end
  310.   def moveto_event(id, wp = false)
  311.     return if $game_map.events[id].nil?
  312.     event = $game_map.events[id]
  313.     if wp
  314.       waypoint(event.x, event.y)
  315.     else
  316.       moveto(event.x, event.y)
  317.     end
  318.   end
  319.   def play_animation(event_id, animation_id)
  320.     if event_id > 0
  321.       return if $game_map.events[event_id].nil?
  322.       event = $game_map.events[event_id]
  323.     elsif event_id == -1
  324.       event = $game_player
  325.     end
  326.     event.animation_id = animation_id
  327.   end
  328. end
  329.  
  330. class Game_Character
  331.   alias eft_init_private_members init_private_members
  332.   def init_private_members
  333.     eft_init_private_members
  334.     @waypoint = [-1,-1]      
  335.   end
  336.   def update_routine_move
  337.     if @wait_count > 0
  338.       @wait_count -= 1
  339.     else
  340.       @move_succeed = true
  341.       command = @move_route.list[@move_route_index]
  342.       if command
  343.         if @waypoint[0] != -1
  344.           process_waypoint_command
  345.           advance_waypoint_route_index
  346.         else
  347.           process_move_command(command)
  348.           advance_move_route_index
  349.         end
  350.       end
  351.     end
  352.   end
  353.   def process_waypoint_command
  354.     sx = distance_x_from(@waypoint[0])
  355.     sy = distance_y_from(@waypoint[1])
  356.     if sx.abs > sy.abs
  357.       if EVENTING_USE_DIR8
  358.         @move_succeed = false
  359.         if sy != 0
  360.           move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)
  361.         end
  362.         move_straight(sx > 0 ? 4 : 6) if !@move_succeed
  363.         move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
  364.       else
  365.         move_straight(sx > 0 ? 4 : 6)
  366.         move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
  367.       end
  368.     elsif sy != 0
  369.       if EVENTING_USE_DIR8
  370.         @move_succeed = false
  371.         if sx != 0
  372.           move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)
  373.         end
  374.         move_straight(sy > 0 ? 8 : 2) if !@move_succeed
  375.         move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
  376.       else
  377.         move_straight(sy > 0 ? 8 : 2)
  378.         move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
  379.       end
  380.     end
  381.     @waypoint = [-1,-1] if !@move_succeed && @move_route.skippable
  382.   end
  383.   def advance_waypoint_route_index
  384.     return unless @x == @waypoint[0]
  385.     return unless @y == @waypoint[1]
  386.     @waypoint = [-1,-1]
  387.   end
  388.   def waypoint(x,y); @waypoint = [x,y]; end
  389. end
  390.  
  391. class Sprite_Character
  392.   alias eventfp_update update
  393.   def update
  394.     eventfp_update
  395.     zoom_update
  396.     mirror_update
  397.     blend_update
  398.     rotate_update
  399.     flash_update if @character.flash_on
  400.   end
  401.   def blend_update; self.color = @character.blend_color; end
  402.   def zoom_update
  403.     self.zoom_y = @character.zoom
  404.     self.zoom_x = @character.zoom
  405.   end
  406.   def mirror_update; self.mirror = @character.mirror; end
  407.   def flash_update
  408.     flash(@character.flash_color,@character.flash_time)
  409.     @character.flashoff
  410.   end
  411.   def rotate_update
  412.     self.angle = @character.angle
  413.   end
  414. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top