[SCRIPT] AUTO-POTION (VX ACE)
Posts
author=GreatRedSpirit
Sorry, I missed your post!
Sounds like the blitz script doesn't always generate a target which my script assumes does. If you go into it and find the bit near the toptargets = @subject.current_action.last_targets.compact
And change it totargets = @subject.current_action.last_targets.compact unless @subject.current_action.last_targets.nil?
Hopefully that'll do the trick. This will have it not assume there are always valid targets from the last action.
(I even had a bit of code that did the check for no valid actions but didn't think think it all the way through which caused this bug)
Yes, it works now!
author=GreatRedSpirit
I liked Script. But I found another issue. Battler die when attack (counterattack...), Script line 8: NoMethodError occurred undefined method 'last_targets' for nil:NilClass
You can fix error. Thank you very much.
Sorry for my bad English.
Huh, that's what I get for not testing counter attacks! Replace line 8 with:
This just adds an extra check seeing if current_action is nil or not. Looks like when an actor dies from a counter it runs the use_item code again but without an actor the actor takes which I never programmed for.
Here's the full script again (I really should submit this to the site)
targets = @subject.current_action.last_targets.compact unless @subject.current_action.nil? or @subject.current_action.last_targets.nil?
This just adds an extra check seeing if current_action is nil or not. Looks like when an actor dies from a counter it runs the use_item code again but without an actor the actor takes which I never programmed for.
Here's the full script again (I really should submit this to the site)
class Scene_Battle < Scene_Base alias :use_item_autoitem :use_item unless $@ def use_item(*args) # First call the original method use_item_autoitem # Get the targets last hit by the use item targets = @subject.current_action.last_targets.compact unless @subject.current_action.nil? or @subject.current_action.last_targets.nil? # If the subject is an actor then they can use an autoitem after their turn if @subject.is_a? Game_Actor use_autoitem(@subject, :after_action) # Otherwise if its an enemy then actors can act if they were a target elsif @subject.is_a? Game_Enemy and not targets.nil? # Use the determined actors list to see who gets a turn at auto item! targets.each do |target| use_autoitem(target, :after_target, @subject) end end end def use_autoitem(actor, phase = :after_target, source = nil) # Sanity check, we only deal with actors return unless actor.is_a? Game_Actor and actor.alive? # Look for items in the player's inventory that the current actor can # use as an autoitem auto_item = get_autoitem(actor, phase) # If no auto item was found then there's no work to do return if auto_item.nil? # Otherwise we found an item and it's time to use it! # Prepare to use the item! This will display it to the user and consume the item @log_window.display_use_item(actor, auto_item) actor.use_item(auto_item) refresh_status # And generate the targets for it targets = [] # If the item is a single-target ally item then the user will use it on themselves if auto_item.for_friend? and not auto_item.for_all? targets = [actor] # If the target is for a single enemy use the source target (if they aren't nil) elsif auto_item.for_opponent? and not auto_item.for_all? and not source.nil? targets = [source] # Otherwise just use a standard action to generate our targets else # Create an action to represent this auto item execution action = Game_Action.new(actor, true) action.set_item(auto_item.id) targets = action.make_targets.compact end # Show the animation for the item being used show_animation(targets, auto_item.animation_id) # Now use the item! targets.each {|target| auto_item.repeats.times { invoke_item(target, auto_item) } } end def get_autoitem(actor, phase) case phase when :after_action return $game_party.items. select{|x| x.auto_item_condition_after_action(actor, $game_party, $game_troop)}. sort_by{ |a| a.auto_item_priority_after_action(actor, $game_party, $game_troop) }. last; when :after_target return $game_party.items. select{|x| x.auto_item_condition_after_target(actor, $game_party, $game_troop)}. sort_by{ |a| a.auto_item_priority_after_target(actor, $game_party, $game_troop) }. last; end end end class Game_Action # We need to access the last targets of this action without invoking # make_targets again since it isn't determinate. This will cache the last # targets and make it accessible attr_reader :last_targets alias :make_targets_autoitem :make_targets unless $@ def make_targets @last_targets = make_targets_autoitem return @last_targets end end class RPG::Item < RPG::UsableItem AutoItemConditionAfterActionRegEx = /<AutoItemConditionAfterAction>(.*)<\/AutoItemConditionAfterAction>/mix def auto_item_condition_after_action(user, party, enemies) # First get the eval to execute for the item if @aicaa.nil? if @note =~ AutoItemConditionAfterActionRegEx @aicaa = $1 else @aicaa = "" end end # If the condition eval is empty then this is always false return false if @aicaa == "" # Otherwise try to execute the condition begin return eval(@aicaa) rescue print "Error occured evaluating #{@aicaa} in auto_item_condition_after_action, error: #{$!}\n" return false end end AutoItemPriorityAfterActionRegEx = /<AutoItemPriorityAfterAction>(.*)<\/AutoItemPriorityAfterAction>/mix def auto_item_priority_after_action(user, party, enemies) # First get the eval to execute for the item if @aipaa.nil? if @note =~ AutoItemPriorityAfterActionRegEx @aipaa = $1 else @aipaa = "" end end # If the condition eval is empty then this is always false return 0 if @aipaa == "" # Otherwise try to execute the condition begin return eval(@aipaa) rescue print "Error occured evaluating #{@aipaa} in auto_item_priority_after_action, error: #{$!}\n" return false end end AutoItemConditionAfterTargetRegEx = /<AutoItemConditionAfterTarget>(.*)<\/AutoItemConditionAfterTarget>/mix def auto_item_condition_after_target(user, party, enemies) # First get the eval to execute for the item if @aicat.nil? if @note =~ AutoItemConditionAfterTargetRegEx @aicat = $1 else @aicat = "" end end # If the condition eval is empty then this is always false return false if @aicat == "" # Otherwise try to execute the condition begin return eval(@aicat) rescue print "Error occured evaluating #{@aicat} in auto_item_condition_after_target, error: #{$!}\n" return false end end AutoItemPriorityAfterTargetRegEx = /<AutoItemPriorityAfterTarget>(.*)<\/AutoItemPriorityAfterTarget>/mix def auto_item_priority_after_target(user, party, enemies) # First get the eval to execute for the item if @aipat.nil? if @note =~ AutoItemPriorityAfterTargetRegEx @aipat = $1 else @aipat = "" end end # If the condition eval is empty then this is always false return 0 if @aipat == "" # Otherwise try to execute the condition begin return eval(@aipat) rescue print "Error occured evaluating #{@aipat} in auto_item_priority_after_target, error: #{$!}\n" return -1 end end end















