Advertisement
Vlue

Field Abilities

Apr 23rd, 2014
2,363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.90 KB | None | 0 0
  1. #Field Abilities v1.1
  2. #----------#
  3. #Features: I have no idea what to call this. But this script adds jumping,
  4. #           throwing, and grabbing options. Now you can drag things around,
  5. #           throw pots and jump over gorges! The possibilities!
  6. #
  7. #Usage:    Plug and play, customize as needed.
  8. #           Jumping:
  9. #            Pressing the jump button causes the hero to jump forward two
  10. #            spaces. Will not jump onto unpassable tiles, or on and through
  11. #            tiles with the NO_JUMP_REGION. Can be disabled with a switch.
  12. #      
  13. #           Throwing:
  14. #            Script call: pickup
  15. #            Events that call pickup will be picked up by the hero. Upon pressing
  16. #            the confirm button the event will be thrown 2 spaces ahead unless
  17. #            it's an unpassable tile or on and through tiles with the
  18. #            NO_JUMP_REGION. Thrown events have their D self switch activated
  19. #            to allow for an event page to run after being thrown.
  20. #            (Events can pick up other events with the script call:
  21. #             pick_up(event_id) - but only during a set move route.
  22. #             and can be thrown with:
  23. #             throw - again only during a set move route.)
  24. #
  25. #           Grabbing:
  26. #            Script call: grab
  27. #            Events that call grab will be grabbed by the hero. The hero can
  28. #            only move forward or backward, and stops grabbing once the confirm
  29. #            button is released.
  30. #
  31. #----------#
  32. #-- Script by: V.M of D.T
  33. #
  34. #- Questions or comments can be:
  35. #    given by email: sumptuaryspade@live.ca
  36. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  37. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  38. #
  39. #- Free to use in any project with credit given, donations always welcome!
  40.  
  41. #The button to be used for jumping:
  42. JUMP_KEY = :SHIFT
  43. #The region that you can use to define no jump areas
  44. NO_JUMP_REGIONS = [10,11]
  45. #The Toggle Jump Switch, jumping is not allowed when this switch is on
  46. TOGGLE_JUMP_SWITCH = 100
  47. #Events containing this string in their name will allow player to jump over them
  48. JUMP_EVENT_STRING = "BG"
  49.  
  50. class Game_Character < Game_CharacterBase
  51.   attr_accessor :carried
  52.   attr_accessor :through
  53.   attr_accessor :priority_type
  54.   attr_accessor :x
  55.   attr_accessor :y
  56.   attr_accessor :direction
  57.   attr_accessor :direction_fix
  58.   attr_accessor :move_succeed
  59.   alias env_screen_y screen_y
  60.   alias env_screen_x screen_x
  61.   def pick_up(event_id)
  62.     @carrying = event_id
  63.     @carrying = $game_map.events[event_id] if $game_map.events[event_id]
  64.     @carrying.through = true
  65.     @carrying.carried = self
  66.     @carrying.priority_type = 2
  67.   end
  68.   def throw
  69.     @carrying.moveto(@x,@y)
  70.     @carrying.direction = @direction
  71.     return unless @carrying.jump_forward_field
  72.     @carrying.thrown
  73.     @carrying.through = false
  74.     @carrying.priority_type = 1
  75.     @carrying.carried = nil
  76.     @carrying = nil
  77.   end
  78.   def screen_y
  79.     @carried ? @carried.screen_y - 24 : env_screen_y
  80.   end
  81.   def screen_x
  82.     @carried ? @carried.screen_x : env_screen_x
  83.   end
  84.   def can_jump?(x,y)
  85.     return false if NO_JUMP_REGIONS.include?($game_map.region_id(@x+x/2,@y+y/2))
  86.     return false if NO_JUMP_REGIONS.include?($game_map.region_id(@x+x,@y+y))
  87.     map_passable?(@x+x,@y+y,@direction) && !collide_with_characters?(@x+x,@y+y) &&
  88.       !sp_cwc(@x+x/2,@y+y/2)
  89.   end
  90.   def sp_cwc(x, y)
  91.     $game_map.events_xy_nt(x, y).any? do |event|
  92.       next if event.name.include?(JUMP_EVENT_STRING)
  93.       event.normal_priority? || self.is_a?(Game_Event)
  94.     end
  95.   end
  96.   def jump_forward_field
  97.     return jump_straight(0,2)  if @direction == 2
  98.     return jump_straight(-2,0) if @direction == 4
  99.     return jump_straight(2,0)  if @direction == 6
  100.     return jump_straight(0,-2) if @direction == 8
  101.   end
  102.   def jump_straight(x,y)
  103.     return false if jumping?
  104.     if can_jump?(x,y)
  105.       jump(x,y)
  106.       return true
  107.     else
  108.       jump(0,0)
  109.       return false
  110.     end
  111.   end
  112.   def thrown
  113.   end
  114. end
  115.  
  116. class Game_Player < Game_Character
  117.   alias throw_cae check_action_event
  118.   alias throw_ms move_straight
  119.   alias throw_update update
  120.   def update
  121.     throw_update
  122.     if !Input.press?(:C) && @grabbed
  123.       @grabbed = nil
  124.       @direction_fix = false
  125.       @move_speed += 1
  126.     @move_frequency += 1
  127.     end
  128.   end
  129.   def move_by_input
  130.     allow = !$game_switches[TOGGLE_JUMP_SWITCH]
  131.     return jump_forward_field if Input.trigger?(JUMP_KEY) && !@grabbed && allow
  132.     return if !movable? || $game_map.interpreter.running?
  133.     return if jumping?
  134.     move_straight(Input.dir4) if Input.dir4 > 0
  135.   end
  136.   def check_action_event
  137.     if @carrying
  138.       throw
  139.       return true
  140.     end
  141.     throw_cae
  142.   end
  143.   def grab(event_id)
  144.     @grabbed = $game_map.events[event_id]
  145.     @move_speed -= 1
  146.     @move_frequency -= 1
  147.     @grabbed.move_speed = @move_speed
  148.     @grabbed.move_frequency = @move_frequency
  149.     @direction_fix = true
  150.   end
  151.   def move_straight(d, tok = true)
  152.     return throw_ms(d, tok) if @grabbed.nil?
  153.     return unless @direction == d || @direction == (d-10).abs
  154.     if @direction == d
  155.       @grabbed.move_straight(d,tok)
  156.       throw_ms(d, tok) if @grabbed.move_succeed
  157.     elsif @direction == (d-10).abs
  158.       throw_ms(d,tok)
  159.       @grabbed.move_straight(d,tok) if @move_succeed
  160.     end
  161.   end
  162. end
  163.  
  164. class Game_Event < Game_Character
  165.   attr_accessor  :move_speed    
  166.   attr_accessor  :move_frequency
  167.   def thrown
  168.     super
  169.     $game_self_switches[[@map_id, @id, "D"]] = true
  170.   end
  171.   def update
  172.     super
  173.     check_event_trigger_auto
  174.     return unless @interpreter
  175.     @interpreter.setup(@list, @event.id) unless @interpreter.running?
  176.     @interpreter.update unless jumping?
  177.   end
  178.   def name
  179.     @event.name
  180.   end
  181. end
  182.  
  183. class Game_Interpreter
  184.   def pickup
  185.     $game_player.pick_up(@event_id)
  186.   end
  187.   def grab
  188.     $game_player.grab(@event_id)
  189.   end
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement