Vlue

Trading Posts

Mar 24th, 2014
1,012
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #--# Trading Posts v1.1b
  2. #
  3. # Allow shops to use a random price range (defined in item notetags) to buy and
  4. #   sell certain items for different prices.
  5. #
  6. # Usage: Customize and set up note tags as needed.
  7. #
  8. #   Item Notetags:
  9. #     <LOCATION# min-max>
  10. #       # is the number of the trade post (between 1 and MAX_TRADE_POSTS)
  11. #       min is the lowest price that tradepost will sell for
  12. #       max is the highest price that tradepost will sell for
  13. #    Example: <LOCATION1 500-6000>
  14. #     Include a tag for every trade post, even if it doesn't sell it, it needs
  15. #      to know how much ot buy it for!
  16. #
  17. #    Set up trade posts like you would Shops, adding tradepost items as regular price
  18. #     Their prices will be fixed when the shop starts.
  19. #
  20. #   Script Calls:
  21. #    $trade_location = #   - where # is the id of the trade post when Shop is used
  22. #    Trade_Values.reset_values   - call this to randomize all trade values again
  23. #
  24. #------#
  25. #-- Script by: V.M of D.T
  26. #
  27. #- Questions or comments can be:
  28. #    posted on the thread for the script
  29. #    given by email: sumptuaryspade@live.ca
  30. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  31. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  32. #
  33. #--- Free to use in any project, commercial or non-commercial, with credit given
  34. #--Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  35.  
  36. #Maximum Number of Trade Posts
  37. MAX_TRADE_POSTS = 2
  38. #Buyback price of trade goods, percent
  39. BUYBACK_PRICE = 0.9
  40.  
  41. $trade_location = 0
  42. class RPG::BaseItem
  43.   def trade_value_range(location)
  44.     self.note =~ /<LOCATION#{location} (\d+)-(\d+)>/
  45.     return false unless $~
  46.     return [$1.to_i,$2.to_i]
  47.   end
  48. end
  49.  
  50. module Trade_Values
  51.   def self.start
  52.     reset_values
  53.   end
  54.   def self.reset_values
  55.     @locations = [0]
  56.     MAX_TRADE_POSTS.times do |i|
  57.       value_array = [{},{},{}]
  58.       container = [$data_items,$data_weapons,$data_armors]
  59.       3.times do |ii|
  60.         container[ii].each do |item|
  61.           next if item.nil?
  62.           if item.trade_value_range(i+1)
  63.             range = item.trade_value_range(i+1)
  64.             value_array[ii][item.id] = rand(range[1]-range[0])+range[0]
  65.           end
  66.         end
  67.       end
  68.       @locations.push(value_array)
  69.     end
  70.   end
  71.   def self.get_location(location)
  72.     self.start if @locations.nil?
  73.     @locations[location]
  74.   end
  75. end
  76.  
  77. class Scene_Shop
  78.   def prepare(goods, purchase_only)
  79.     @goods = goods
  80.     @trade_values = []
  81.     if $trade_location > 0
  82.       @trade_values = Trade_Values.get_location($trade_location)
  83.       @goods.each do |good|
  84.         if @trade_values[good[0]][good[1]]
  85.           good[2] = true
  86.           good[3] = @trade_values[good[0]][good[1]]
  87.         end
  88.       end
  89.     end
  90.     @purchase_only = purchase_only
  91.   end
  92.   def selling_price
  93.     type = 0 if @item.is_a?(RPG::Item)
  94.     type = 1 if @item.is_a?(RPG::Weapon)
  95.     type = 2 if @item.is_a?(RPG::Armor)
  96.     if @trade_values[type][@item.id]
  97.       return (@trade_values[type][@item.id] * BUYBACK_PRICE).to_i
  98.     else
  99.       @item.price / 2
  100.     end
  101.   end
  102. 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.

×