Advertisement
Narzew

RMXP Battle Item & Skill Use Limits

Feb 23rd, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.11 KB | None | 0 0
  1. #===============================================
  2. # Battle Item & Skill Use Limits
  3. # Autor skryptu: Narzew
  4. # Bazowano na skrypcie Ayene
  5. #===============================================
  6.  
  7. ############################################################
  8. #**Battle Item & Skill Use Limits
  9. #**Narzew
  10. #**Based work on Ayene script.
  11. ############################################################
  12. #11.04.12 - Script Start Date
  13. #11.04.12 - Script Completed Date V 1.0
  14. #23.02.14 - Script Completed Date V 1.01
  15. #V 1.01
  16. ############################################################
  17. #**Instructions:
  18. #**$itemuselimit[id] = limit of item use
  19. #**$skilluselimit[id] = limit of skill use
  20. #**Module BattleUseLimits
  21. #**change_itemuselimit
  22. #**In: Id (Integer)
  23. #**In: Modifier (Value - add, remove, set (with no quotes))
  24. #**In: Value (Integer)
  25. #**Out: Nil (Operation)
  26. #**DescEn: Changes the item id x use limit
  27. #**DescPl: Zwiększa limit użyć przedmiotu o id x
  28. #**change_skilluselimit
  29. #**In: Id (Integer)
  30. #**In: Modifier (Value - add, remove, set (with no quotes))
  31. #**In: Value (Integer)
  32. #**Out: Nil (Operation)
  33. #**DescEn: Changes the skill id x use limit
  34. #**DescPl: Zwiększa limit użyć czaru o id x
  35. ############################################################
  36. $itemuselimit = {
  37. 1=>3,
  38. 2=>3,
  39. 4=>1
  40. }
  41. $skilluselimit = {
  42. 1=>2,
  43. 2=>1
  44. }
  45. module BattleUseLimits
  46.   def self.change_itemuselimit(id, modifier, value)
  47.     case modifier
  48.     when 0 then $itemuselimit[id] += value
  49.     when 1 then $itemuselimit[id] -= value
  50.     when 2 then $itemuselimit[id] = value
  51.     end
  52.   end
  53.   def self.change_skilluselimit(id, modifier, value)
  54.     case modifier
  55.     when 0 then $skilluselimit[id] += value
  56.     when 1 then $skilluselimit[id] -= value
  57.     when 2 then $skilluselimit[id] = value
  58.     end
  59.   end
  60. end
  61. class Game_Temp
  62.   attr_accessor :battle_item_used
  63.   attr_accessor :battle_skill_used
  64.   alias aye_gamtemp_ini initialize
  65.   def initialize
  66.     aye_gamtemp_ini
  67.     @battle_item_used = {}
  68.     @battle_skill_used = {}
  69.   end
  70. end
  71. class Window_Skill < Window_Selectable
  72.   def draw_item(index)
  73.     skill = @data[index]
  74.     if @actor.skill_can_use?(skill.id)
  75.       self.contents.font.color = normal_color
  76.     else
  77.       self.contents.font.color = disabled_color
  78.     end
  79.     if $game_temp.battle_skill_used.include?(skill.id)
  80.       if $game_temp.battle_skill_used[skill.id] >= $skilluselimit[skill.id]
  81.         self.contents.font.color = disabled_color
  82.       end
  83.     end
  84.     x = 4 + index % 2 * (288 + 32)
  85.     y = index / 2 * 32
  86.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  87.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  88.     bitmap = RPG::Cache.icon(skill.icon_name)
  89.     opacity = self.contents.font.color == normal_color ? 255 : 128
  90.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  91.     self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
  92.     self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
  93.   end
  94. end
  95. class Window_Item < Window_Selectable
  96.   def draw_item(index)
  97.     item = @data[index]
  98.     case item
  99.     when RPG::Item
  100.       number = $game_party.item_number(item.id)
  101.     when RPG::Weapon
  102.       number = $game_party.weapon_number(item.id)
  103.     when RPG::Armor
  104.       number = $game_party.armor_number(item.id)
  105.     end
  106.     if item.is_a?(RPG::Item) and
  107.        $game_party.item_can_use?(item.id)
  108.       self.contents.font.color = normal_color
  109.     else
  110.       self.contents.font.color = disabled_color
  111.     end
  112.     if $game_temp.battle_item_used.include?(item.id)
  113.       if $game_temp.battle_item_used[item.id] >= $itemuselimit[item.id]
  114.         self.contents.font.color = disabled_color
  115.       end
  116.     end
  117.     x = 4 + index % 2 * (288 + 32)
  118.     y = index / 2 * 32
  119.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  120.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  121.     bitmap = RPG::Cache.icon(item.icon_name)
  122.     opacity = self.contents.font.color == normal_color ? 255 : 128
  123.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  124.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  125.     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  126.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  127.   end
  128. end
  129. class Scene_Battle
  130.   alias aye_scbat_update_phase3_skill_select update_phase3_skill_select
  131.   def update_phase3_skill_select
  132.     if Input.trigger?(Input::C)
  133.       @skill = @skill_window.skill
  134.       if $game_temp.battle_skill_used.include?(@skill.id)
  135.         if $game_temp.battle_skill_used[@skill.id] >= $skilluselimit[@skill.id]
  136.           $game_system.se_play($data_system.buzzer_se)
  137.           return
  138.         end
  139.       end
  140.     end
  141.     aye_scbat_update_phase3_skill_select
  142.   end
  143.   alias aye_scbat_update_phase3_item_select update_phase3_item_select
  144.   def update_phase3_item_select
  145.     if Input.trigger?(Input::C)
  146.       @item = @item_window.item
  147.       if $game_temp.battle_item_used.include?(@item.id)
  148.         if $game_temp.battle_item_used[@item.id] >= $itemuselimit[@item.id]
  149.           $game_system.se_play($data_system.buzzer_se)
  150.           return
  151.         end
  152.       end
  153.     end  
  154.     aye_scbat_update_phase3_item_select
  155.   end
  156.   alias aye_scbat_make_skill_action_result make_skill_action_result
  157.   def make_skill_action_result  
  158.     @skill = $data_skills[@active_battler.current_action.skill_id]
  159.     skill_number = $game_temp.battle_skill_used.include?(@skill.id) ?
  160.                   $game_temp.battle_skill_used[@skill.id] : 0
  161.     $game_temp.battle_skill_used[@skill.id] = skill_number + 1
  162.     aye_scbat_make_skill_action_result
  163.   end
  164.   alias aye_scbat_make_item_action_result make_item_action_result
  165.   def make_item_action_result
  166.     @item = $data_items[@active_battler.current_action.item_id]
  167.     item_number = $game_temp.battle_item_used.include?(@iteml.id) ?
  168.                   $game_temp.battle_item_used[@iteml.id] : 0
  169.     $game_temp.battle_item_used[@item.id] = item_number + 1
  170.     aye_scbat_make_item_action_result
  171.   end
  172.   alias aye_scbat_battle_end battle_end
  173.   def battle_end(result)
  174.     $game_temp.battle_skill_used.clear
  175.     $game_temp.battle_item_used.clear
  176.     aye_scbat_battle_end(result)
  177.   end
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement