Vlue

Gathering Nodes

Jan 2nd, 2015
1,107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Gathering Nodes v1.1
  2. #----------#
  3. #Features: Now you too can create simple and easy (and copy/pastable *wink*)
  4. #           gathering nodes for your game! Want a herb patch that respawns
  5. #           every 6 minutes and gives the player some herbs? You can do that.
  6. #           Need to change the herb patch but already placed a 100 of them?
  7. #           You can change them all at once, since it uses script options!
  8. #
  9. #Usage:    Simply name an empty event: Node #id
  10. #           And the script does the rest! Say for example you named an
  11. #           event: Node #1, it'd use the node data of id 1. You can have
  12. #           as many events of the same node and as many node types that
  13. #           you want! And more to come I'm sure...
  14. #
  15. #~ #----------#
  16. #-- Script by: V.M of D.T
  17. #
  18. #- Questions or comments can be:
  19. #    given by email: sumptuaryspade@live.ca
  20. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  21. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  22. #
  23. #--- Free to use in any project, commercial or non-commercial, with credit given
  24. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  25.  
  26. #Setting up your nodes is as easy as minor surgery.
  27. # A basic node consists of:
  28. #   id => {:item => [:type,id,[min,max]],  #:type is :item, :weapon, or :armor
  29. #          :tool => [:type, id]            #item required to gather (optional)
  30. #          :level => value,                #level needed to gather
  31. #          :timer => value(in seconds),    #respawn timer
  32. #          :base_chance => value,          #chance to gather
  33. #          :max_chance => value,           #max chance to gather
  34. #          :chance_mod => value,}          #see below
  35. #          :graphic_b => [:type,val1,val2] #also see below
  36. #          :graphic_a => [:type,val1,val2] #still also see below
  37. #          :sound => ["se name",vol,times,wait]
  38. #
  39. # Below: The chance to gather from a node is: bc + (level - node_level) * cm
  40. #  Which means for every level the player is above the node, they get the
  41. #   chance mod times that added on to the base chance. And reverse for lower
  42. #   player level compared to node level.
  43. # Example: BC = 50, CM = 5
  44. #   50 + (5 - 1) * 5 = 70% chance to gather (PL 5, NL 1)
  45. #   50 + (5 - 5) * 5 = 50% chance to gather (PL 5, NL 5)
  46. #   50 + (5 - 9) * 5 = 30% chance to gather (PL 5, NL 9)
  47. #
  48. # Graphic_A and Graphic_B (Optional)
  49. #  Denotes the graphic for each node before harvest (graphic_b) and after
  50. #  harvest (graphic_a). Could be tileset or character like as follows:
  51. #   :graphic_b => [:tileset,11],
  52. #   :graphic_a => [:char,"Animal",1],
  53. #  Tileset numbers start at 0 (B top left corner), uses map tileset
  54. #
  55. # Items - The :item section can also be set up to include multiple different
  56. #   gathering results!
  57. #  Instead of :item => [:type,id,[min,max]], you would set it up like:
  58. #   :item => [ [:type,id,[min,max],chance], [:type,id,[min,max],chance], ... ],
  59. #  Where chance is a value out of 100 (higher values more likely), the script
  60. #   will iterate through all possible items until one passes it's chance check.
  61.  
  62. $imported = {}
  63. $imported[:Vlue_GatheringNodes] = true
  64.  
  65. #Note the strange and bizarre double quotes ( '" "' ), keep those.
  66. NODES_OBTAINED_STRING = '"Obtained \\\i[#{item.icon_index}] #{item.name} x#{amount}."'
  67. NODES_LOWLEVEL_STRING = '"Level #{node_data[:level]} required."'
  68. NODES_TOOLREQ_STRING = '"Tool \\\i[#{item.icon_index}] #{item.name} required."'
  69. NODES_GATHERFAIL_STRING = "Failed to gather resource."
  70.  
  71. GATHERING_NODES = {
  72.   1 => {:item => [:item,1,[1,5]],
  73.         :tool => [:weapon,1],
  74.         :level => 1,
  75.         :timer => 6,
  76.         :base_chance => 70,
  77.         :max_chance => 95,
  78.         :chance_mod => 5,
  79.         :graphic_b => [:tileset,177],
  80.         :graphic_a => [:tileset,100],
  81.         :sound => ["Blow2",75,3,15]},
  82.        
  83.   2 => {:item => [
  84.           [:item,2,[1,3],90],
  85.           [:item,3,[1,1],5]],
  86.         :level => 0,
  87.         :timer => 1,
  88.         :base_chance => 100,
  89.         :max_chance => 100,
  90.         :chance_mod => 1,
  91.         :graphic_b => [:tileset,281],
  92.         :graphic_a => [:tileset,0],
  93.         :sound => ["Equip3",75,1,5]}
  94.        
  95. }
  96.  
  97. class Game_Event
  98.   alias gather_update update
  99.   alias gather_start start
  100.   alias gather_init setup_page
  101.   def setup_page(*args)
  102.     gather_init(*args)
  103.     if node
  104.       graphic = erased? ? node_data[:graphic_a] : node_data[:graphic_b]
  105.       if graphic
  106.         if graphic[0] == :tileset
  107.           @tile_id = graphic[1]
  108.         else
  109.           @character_name = graphic[1]
  110.           @character_index = graphic[2]
  111.         end
  112.       end
  113.     end
  114.   end
  115.   def node
  116.     @event.name.include?("Node")
  117.   end
  118.   def node_id
  119.     @event.name =~ /Node #(\d+)/ ? $1.to_i : nil
  120.   end
  121.   def node_data
  122.     GATHERING_NODES[node_id]
  123.   end
  124.   def start
  125.     node ? node_start : gather_start
  126.   end
  127.   def node_start
  128.     return if $imported[:Vlue_PopupWindow] and $popup
  129.     return no_tool if !carrying_tool?
  130.     return no_level if node_data[:level] > $game_party.highest_level
  131.     $game_party.gathering = true
  132.     if node_data[:sound]
  133.       node_data[:sound][2].times do |i|
  134.         Audio.se_play("Audio/SE/" + node_data[:sound][0],node_data[:sound][1])
  135.         node_data[:sound][3].times do |i|
  136.           Graphics.update
  137.           SceneManager.scene.update
  138.         end
  139.       end
  140.     end
  141.     $game_party.gathering = false
  142.     if gather_success
  143.       if node_data[:item][0].is_a?(Array)
  144.         item_d = nil
  145.         while item_d.nil?
  146.           node_data[:item].each do |array|
  147.             item_d = array if rand(100) < array[3]
  148.           end
  149.         end
  150.       else
  151.         item_d = node_data[:item]
  152.       end
  153.       item = $data_items[item_d[1]] if item_d[0] == :item
  154.       item = $data_weapons[item_d[1]] if item_d[0] == :weapon
  155.       item = $data_armors[item_d[1]] if item_d[0] == :armor
  156.       msgbox("Invalid item category") unless item
  157.       amount = (rand(item_d[2][1] - item_d[2][0]) + item_d[2][0]).to_i
  158.       $game_party.gain_item(item,amount)
  159.       if $imported[:Vlue_SleekPopup]
  160.         Popup_Manager.add(item,amount,PU_DEFAULT_DURATION,false,0,0)
  161.       elsif $imported[:Vlue_PopupWindow]
  162.         Popup.add([eval(NODES_OBTAINED_STRING)],POPUP_DURATION,nil,nil)
  163.       else
  164.         $game_message.add(eval(NODES_OBTAINED_STRING))
  165.       end
  166.     end
  167.     erase
  168.     set_timer(node_data[:timer])
  169.   end
  170.   def carrying_tool?
  171.     item_d = node_data[:tool]
  172.     return true if item_d.nil?
  173.     item = $data_items[item_d[1]] if item_d[0] == :item
  174.     item = $data_weapons[item_d[1]] if item_d[0] == :weapon
  175.     item = $data_armors[item_d[1]] if item_d[0] == :armor
  176.     return $game_party.has_item?(item)
  177.   end
  178.   def set_timer(length)
  179.     $game_party.node_timers.set_timer(@id,$game_map.map_id,length)
  180.   end
  181.   def unerase
  182.     @erased = false
  183.     refresh
  184.   end
  185.   def erased?; @erased == true; end
  186.   def event_id; @id; end
  187.   def no_level
  188.     if $imported[:Vlue_PopupWindow]
  189.       Popup.add([eval(NODES_LOWLEVEL_STRING)],POPUP_DURATION,nil,nil)
  190.     else
  191.       $game_message.add(eval(NODES_LOWLEVEL_STRING))
  192.     end
  193.   end
  194.   def no_tool
  195.     item_d = node_data[:tool]
  196.     item = $data_items[item_d[1]] if item_d[0] == :item
  197.     item = $data_weapons[item_d[1]] if item_d[0] == :weapon
  198.     item = $data_armors[item_d[1]] if item_d[0] == :armor
  199.     if $imported[:Vlue_PopupWindow]
  200.       Popup.add([eval(NODES_TOOLREQ_STRING)],POPUP_DURATION,nil,nil)
  201.     else
  202.       $game_message.add(eval(NODES_TOOLREQ_STRING))
  203.     end
  204.   end
  205.   def gather_success
  206.     chance = node_data[:base_chance]
  207.     chance += node_data[:chance_mod] * ($game_party.highest_level - node_data[:level])
  208.     chance = [chance,node_data[:max_chance]].min
  209.     if rand(100) < chance
  210.       return true
  211.     else
  212.       if $imported[:Vlue_PopupWindow]
  213.         Popup.add([NODES_GATHERFAIL_STRING],POPUP_DURATION,nil,nil)
  214.       else
  215.         $game_message.add(NODES_GATHERFAIL_STRING)
  216.       end
  217.       return false
  218.     end
  219.   end
  220. end
  221.  
  222. class Game_Player
  223.   alias gather_movable? movable?
  224.   def movable?
  225.     return if $game_party.gathering
  226.     return gather_movable?
  227.   end
  228. end
  229.  
  230. class Game_Map
  231.   alias gather_se setup_events
  232.   alias gather_ue update_events
  233.   def setup_events
  234.     gather_se
  235.     @events.each_value do |event|
  236.       next unless event.node
  237.       event.erase if $game_party.node_timers.timer(event.event_id,@map_id) > 0
  238.     end
  239.   end
  240.   def update_events
  241.     $game_party.node_timers.update
  242.     gather_ue
  243.     @events.each_value do |event|
  244.       next unless event.node && event.erased?
  245.       event.unerase if $game_party.node_timers.timer(event.event_id,@map_id) == 0
  246.     end
  247.   end
  248. end
  249.  
  250. class Node_Timers
  251.   def initialize
  252.     @event_timers = {}
  253.   end
  254.   def update
  255.     return unless Graphics.frame_count % 60 == 0
  256.     @event_timers.each do |k,i|
  257.       @event_timers[k] -= 1 if @event_timers[k] > 0
  258.     end
  259.   end
  260.   def timer(eid,mid)
  261.     res = @event_timers[[eid,mid]]
  262.     res ? res : 0
  263.   end
  264.   def set_timer(eid,mid,len)
  265.     @event_timers[[eid,mid]] = len
  266.   end
  267. end
  268.  
  269. class Game_Party
  270.   attr_accessor :node_timers
  271.   attr_accessor :gathering
  272.   alias gather_init initialize
  273.   def initialize(*args)
  274.     gather_init
  275.     @node_timers = Node_Timers.new
  276.     @gathering = false
  277.   end
  278. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×