Advertisement
TheSixth

Target One Ally (Not the User) Scope

Dec 1st, 2017
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.83 KB | None | 0 0
  1. =begin
  2.  
  3. - Target One Ally (Not the User) Scope - What a silly title!
  4. - Made by: Sixth
  5.  
  6. - Description
  7.  
  8. This script will let you make a new scope for your skills (kinda).
  9. That scope will let the player target anyone from an ally except the user.
  10.  
  11. To make a skill use this scope, make sure to set it's database scope to
  12. the "One Ally" type, and use this note-tag in it's note-box:
  13.  
  14.   <one_ally_no_user>
  15.  
  16. This will setup the new scope for the skill. It will work in the menu outside
  17. the battles too, but only on skills.
  18. Due to how the user is set for the items in the item menu (the member with the
  19. highest PHA stat will be the user every time you use an item), it wouldn't make
  20. much sense to enable this new scope there (but if you still used the mentioned
  21. note-tag on an item with the "One Ally" scope, it will function as expected
  22. during battles, so the user will not be able to use the item on him/herself.
  23.  
  24. As a necessary fix, I also made enemies not target the last troop member every
  25. time they use a skill with the "One Ally" scope. Instead, they will now target
  26. random allies, but if the used skill got the <one_ally_no_user> note-tag, they
  27. won't be able to target themselves with the skill.
  28.  
  29. This is tested without any custom battle scripts, so there is no guarantee that
  30. it will work with those!
  31.  
  32. =end
  33.  
  34. class RPG::UsableItem < RPG::BaseItem
  35.  
  36.   attr_accessor :one_no_user
  37.  
  38.   def one_no_user
  39.     init_one_no_user if @one_no_user.nil?
  40.     return @one_no_user
  41.   end
  42.  
  43.   def init_one_no_user
  44.     @one_no_user = @note =~ /<one_ally_no_user>/i ? true : false
  45.   end
  46.  
  47. end
  48.  
  49. class Game_Action
  50.  
  51.   alias check_no_user1232 targets_for_friends
  52.   def item_target_candidates
  53.     trgs = check_no_user1232
  54.     trgs.delete(subject) if item.one_no_user && item.for_one?
  55.     return trgs
  56.   end
  57.  
  58.   alias check_no_user1132 targets_for_friends
  59.   def targets_for_friends
  60.     if subject.is_a?(Game_Enemy) && item.scope == 7
  61.       ids = []
  62.       friends_unit.alive_members.each_with_index do |mem,i|
  63.         next if item.one_no_user && mem == subject
  64.         ids << $game_troop.members.index(mem)
  65.       end
  66.       @target_index = ids.sample
  67.     end
  68.     trgs = check_no_user1132
  69.     return trgs
  70.   end
  71.  
  72. end
  73.  
  74. class Game_BattlerBase
  75.  
  76.   alias check_no_user7541 usable?
  77.   def usable?(item)
  78.     if item.is_a?(RPG::UsableItem) && item.one_no_user && friends_unit.alive_members.size <= 1
  79.       return false
  80.     end
  81.     check_no_user7541(item)
  82.   end
  83.  
  84. end
  85.  
  86. class Game_Actor < Game_Battler
  87.  
  88.   alias check_no_user9265 item_test
  89.   def item_test(user, item)
  90.     return false if item.one_no_user && self == user
  91.     check_no_user9265(user, item)
  92.   end
  93.  
  94. end
  95.  
  96. class Window_BattleActor < Window_BattleStatus
  97.  
  98.   def draw_actor_name(actor, x, y, width = 112)
  99.     if BattleManager.actor && BattleManager.actor.input.item.one_no_user &&
  100.        actor == BattleManager.actor
  101.       act_enable = false
  102.     else
  103.       act_enable = true
  104.     end
  105.     change_color(hp_color(actor),act_enable)
  106.     draw_text(x, y, width, line_height, actor.name)
  107.   end
  108.  
  109.   def current_item_enabled?
  110.     if BattleManager.actor && BattleManager.actor.input.item.one_no_user &&
  111.        $game_party.members[@index] == BattleManager.actor
  112.       return false
  113.     else
  114.       super
  115.     end
  116.   end
  117.  
  118. end
  119.  
  120. class Scene_Skill < Scene_ItemBase
  121.  
  122.   alias check_no_user8826 use_item
  123.   def use_item
  124.     if item.one_no_user && user == $game_party.members[@actor_window.index]
  125.       return Sound.play_buzzer
  126.     end
  127.     check_no_user8826
  128.   end
  129.  
  130. end
  131.  
  132. class Scene_Battle < Scene_Base
  133.  
  134.   alias check_no_user5413 on_actor_ok
  135.   def on_actor_ok
  136.     if BattleManager.actor.input.item.one_no_user &&
  137.        BattleManager.actor == $game_party.battle_members[@actor_window.index]
  138.       return Sound.play_buzzer
  139.     end
  140.     check_no_user5413
  141.   end  
  142.  
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement