Black_Mage

Special Invulnerable State Script RMXP

Nov 9th, 2015
1,303
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.28 KB | None | 0 0
  1. ################################################################################
  2. # Special Invulnerable State Script By Black Mage (Credit required to use)
  3. # Version : 1.3
  4. # https://burningwizard.wordpress.com/2015/11/09/special-invulnerable-state-script/
  5. ################################################################################
  6.  
  7. # WARNING : This script is heavily modified the targeting system and how things
  8. # related to them is handled, thus make this script might not compatible with
  9. # many custom battle script. If you found some incompatibility, with another
  10. # script, make sure to report to :
  11. # https://burningwizard.wordpress.com/2015/11/09/special-invulnerable-state-script/
  12. # so we can solve the problem.
  13.  
  14. # To use this script, put it above Main script in the script editor, and make sure
  15. # to put it BELOW any script that alter the battle system.
  16.  
  17. # Character inflicted by these states are treated as they not existed in the party.
  18. # Insert the states ID to the brackets below.
  19. $special_states1 = [1,17]
  20.  
  21. # Character inflicted by these states can't be attacked by the enemies.
  22. # If player insisted to attack the target, it'll change into another target.
  23. # It still work on skill that target self.
  24. # Insert the states ID to the brackets below.
  25. $special_states2 = [17]
  26.  
  27. # Character inflicted by these states are grayed out.
  28. # You can modified the value of $special_tone to get your own color.
  29. # Insert the states ID to the brackets below.
  30. $special_states3 = [17]
  31. $special_tone = [0,0,0,255]
  32.  
  33. class Game_Party
  34.   #--------------------------------------------------------------------------
  35.   # * Determine wether state 2 is in effect or not
  36.   #--------------------------------------------------------------------------
  37.   def state2_invulnerable(target)
  38.     # If it fits the conditions
  39.     @special_states = false
  40.     # Check whether special state available
  41.     for i in 0..($special_states2.size - 1)
  42.       if target.state?($special_states2[i])
  43.         @special_states = true
  44.       end
  45.     end
  46.     if @special_states == true
  47.       return true
  48.     else
  49.       return false
  50.     end
  51.   end
  52.  
  53.   #--------------------------------------------------------------------------
  54.   # * Determine Everyone is Dead
  55.   #--------------------------------------------------------------------------
  56.   def all_dead?
  57.     # If number of party members is 0
  58.     if $game_party.actors.size == 0
  59.       return false
  60.     end
  61.     # If an actor is in the party with 0 or more HP
  62.     @special_game_over = 0
  63.     for actor in @actors
  64.       @special_states = false
  65.       if actor.hp == 0
  66.         @special_game_over = @special_game_over + 1
  67.       elsif actor.hp > 0
  68.         # If it fits the conditions
  69.         if $special_states1.size == 0
  70.           return false
  71.         else
  72.           for i in 0..($special_states1.size - 1)
  73.             if actor.state?($special_states1[i])
  74.               @special_states = true              
  75.             end
  76.           end
  77.         end
  78.       end
  79.       if @special_states == true
  80.         @special_game_over = @special_game_over + 1
  81.       end
  82.     end
  83.     # All members dead
  84.     if @special_game_over == @actors.size
  85.       return true
  86.     else
  87.       return false
  88.     end
  89.   end
  90.  
  91.   #--------------------------------------------------------------------------
  92.   # * Random Selection of Target Actor
  93.   #     hp0 : limited to actors with 0 HP
  94.   #--------------------------------------------------------------------------
  95.   def random_target_actor(hp0 = false)
  96.     # Initialize roulette
  97.     roulette = []
  98.     # Loop
  99.     for actor in @actors
  100.       if state2_invulnerable(actor) == false
  101.         if (not hp0 and actor.exist?) or (hp0 and actor.hp0?)
  102.           # Get actor class [position]
  103.           position = $data_classes[actor.class_id].position
  104.           # Front guard: n = 4; Mid guard: n = 3; Rear guard: n = 2
  105.           n = 4 - position
  106.           # Add actor to roulette n times
  107.           n.times do
  108.             roulette.push(actor)
  109.           end
  110.         end
  111.       end
  112.     end
  113.     # If roulette size is 0
  114.     if roulette.size == 0
  115.       return nil
  116.     end
  117.     # Spin the roulette, choose an actor
  118.     return roulette[rand(roulette.size)]
  119.   end
  120.  
  121.   #--------------------------------------------------------------------------
  122.   # * Smooth Selection of Target Actor
  123.   #     actor_index : actor index
  124.   #--------------------------------------------------------------------------
  125.   def smooth_target_actor(actor_index)
  126.     # Get an actor
  127.     actor = @actors[actor_index]
  128.     # If an actor exists
  129.     if actor != nil and actor.exist?
  130.       if state2_invulnerable(actor) == false
  131.         return actor
  132.       end
  133.     end
  134.     # Loop
  135.     for actor in @actors
  136.       # If an actor exists
  137.       if actor.exist?
  138.         if state2_invulnerable(actor) == false
  139.           return actor
  140.         end
  141.       end
  142.     end
  143.     actor = $game_party.random_target_actor
  144.     return actor
  145.   end
  146.  
  147. end
  148.  
  149. #----------------------------------------------------------------------------
  150. class Scene_Battle
  151. #----------------------------------------------------------------------------
  152.   #--------------------------------------------------------------------------
  153.   # * Determine wether state 2 is in effect or not
  154.   #--------------------------------------------------------------------------
  155.   def state2_invulnerable(target)
  156.     # If it fits the conditions
  157.     @special_states = false
  158.     # Check whether target is exist
  159.     if target == nil
  160.       return false
  161.     else
  162.       # Check whether special state available
  163.       for i in 0..($special_states2.size - 1)
  164.         if target.state?($special_states2[i])
  165.           @special_states = true
  166.         end
  167.       end
  168.       if @special_states == true
  169.         return true
  170.       else
  171.         return false
  172.       end
  173.     end
  174.   end
  175.  
  176.   #--------------------------------------------------------------------------
  177.   # * Set Targeted Battler for Skill or Item
  178.   #     scope : effect scope for skill or item
  179.   #--------------------------------------------------------------------------
  180.   def set_target_battlers(scope)
  181.     # If battler performing action is enemy
  182.     if @active_battler.is_a?(Game_Enemy)
  183.       # Branch by effect scope
  184.       case scope
  185.       when 1  # single enemy
  186.         index = @active_battler.current_action.target_index
  187.         actortemp = $game_party.smooth_target_actor(index)
  188.         if state2_invulnerable(actortemp) == false
  189.           @target_battlers.push($game_party.smooth_target_actor(index))
  190.         end
  191.       when 2  # all enemies
  192.         for actor in $game_party.actors
  193.           if actor.exist?
  194.             if state2_invulnerable(actor) == false
  195.               @target_battlers.push(actor)
  196.             end
  197.           end
  198.         end
  199.       when 3  # single ally
  200.         index = @active_battler.current_action.target_index
  201.         enemytemp = $game_troop.smooth_target_enemy(index)
  202.         if state2_invulnerable(enemytemp) == false
  203.           @target_battlers.push($game_troop.smooth_target_enemy(index))
  204.         end
  205.       when 4  # all allies
  206.         for enemy in $game_troop.enemies
  207.           if enemy.exist?
  208.             if state2_invulnerable(enemy) == false
  209.               @target_battlers.push(enemy)
  210.             end
  211.           end
  212.         end
  213.       when 5  # single ally (HP 0)
  214.         index = @active_battler.current_action.target_index
  215.         enemy = $game_troop.enemies[index]
  216.         if enemy != nil and enemy.hp0?
  217.           if state2_invulnerable(enemy) == false
  218.             @target_battlers.push(enemy)
  219.           end
  220.         end
  221.       when 6  # all allies (HP 0)
  222.         for enemy in $game_troop.enemies
  223.           if enemy != nil and enemy.hp0?
  224.             if state2_invulnerable(enemy) == false
  225.               @target_battlers.push(enemy)
  226.             end
  227.           end
  228.         end
  229.       when 7  # user
  230.         @target_battlers.push(@active_battler)
  231.       end
  232.     end
  233.     # If battler performing action is actor
  234.     if @active_battler.is_a?(Game_Actor)
  235.       # Branch by effect scope
  236.       case scope
  237.       when 1  # single enemy
  238.         index = @active_battler.current_action.target_index
  239.         enemytemp = $game_troop.smooth_target_enemy(index)
  240.         if state2_invulnerable(enemytemp) == false
  241.           @target_battlers.push($game_troop.smooth_target_enemy(index))
  242.         end
  243.       when 2  # all enemies
  244.         for enemy in $game_troop.enemies
  245.           if enemy.exist?
  246.             if state2_invulnerable(enemy) == false
  247.               @target_battlers.push(enemy)
  248.             end
  249.           end
  250.         end
  251.       when 3  # single ally
  252.         index = @active_battler.current_action.target_index
  253.         actortemp = $game_party.smooth_target_actor(index)
  254.         if state2_invulnerable(actortemp) == false
  255.           @target_battlers.push($game_party.smooth_target_actor(index))
  256.         end
  257.       when 4  # all allies
  258.         for actor in $game_party.actors
  259.           if actor.exist?
  260.             if state2_invulnerable(actor) == false
  261.               @target_battlers.push(actor)
  262.             end
  263.           end
  264.         end
  265.       when 5  # single ally (HP 0)
  266.         index = @active_battler.current_action.target_index
  267.         actor = $game_party.actors[index]
  268.         if actor != nil and actor.hp0?
  269.           if state2_invulnerable(actor) == false
  270.             @target_battlers.push(actor)
  271.           end
  272.         end
  273.       when 6  # all allies (HP 0)
  274.         for actor in $game_party.actors
  275.           if actor != nil and actor.hp0?
  276.             if state2_invulnerable(actor) == false
  277.               @target_battlers.push(actor)
  278.             end
  279.           end
  280.         end
  281.       when 7  # user
  282.         @target_battlers.push(@active_battler)
  283.       end
  284.     end
  285.   end
  286.  
  287.   #--------------------------------------------------------------------------
  288.   # * Make Skill Action Results
  289.   #--------------------------------------------------------------------------
  290.   def make_skill_action_result
  291.     # Get skill
  292.     @skill = $data_skills[@active_battler.current_action.skill_id]
  293.     # If not a forcing action
  294.     unless @active_battler.current_action.forcing
  295.       # If unable to use due to SP running out
  296.       unless @active_battler.skill_can_use?(@skill.id)
  297.         # Clear battler being forced into action
  298.         $game_temp.forcing_battler = nil
  299.         # Shift to step 1
  300.         @phase4_step = 1
  301.         return
  302.       end
  303.     end
  304.    
  305.     # Set target battlers
  306.     set_target_battlers(@skill.scope)
  307.     if @target_battlers == nil
  308.     else
  309.       # Use up SP
  310.       @active_battler.sp -= @skill.sp_cost
  311.       # Refresh status window
  312.       @status_window.refresh
  313.       # Show skill name on help window
  314.       @help_window.set_text(@skill.name, 1)
  315.       # Set animation ID
  316.       @animation1_id = @skill.animation1_id
  317.       @animation2_id = @skill.animation2_id
  318.       # Set command event ID
  319.       @common_event_id = @skill.common_event_id
  320.       # Apply skill effect
  321.       for target in @target_battlers
  322.         if target != nil
  323.           target.skill_effect(@active_battler, @skill)
  324.         end
  325.       end
  326.     end
  327.   end
  328.  
  329.   #--------------------------------------------------------------------------
  330.   # * Make Item Action Results
  331.   #--------------------------------------------------------------------------
  332.   def make_item_action_result
  333.     # Get item
  334.     @item = $data_items[@active_battler.current_action.item_id]
  335.     # If unable to use due to items running out
  336.     unless $game_party.item_can_use?(@item.id)
  337.       # Shift to step 1
  338.       @phase4_step = 1
  339.       return
  340.     end
  341.     # If consumable
  342.     if @item.consumable
  343.       # Decrease used item by 1
  344.       $game_party.lose_item(@item.id, 1)
  345.     end
  346.     # Display item name on help window
  347.     @help_window.set_text(@item.name, 1)
  348.     # Set animation ID
  349.     @animation1_id = @item.animation1_id
  350.     @animation2_id = @item.animation2_id
  351.     # Set common event ID
  352.     @common_event_id = @item.common_event_id
  353.     # Decide on target
  354.     index = @active_battler.current_action.target_index
  355.     target = $game_party.smooth_target_actor(index)
  356.     # Set targeted battlers
  357.     set_target_battlers(@item.scope)
  358.     # Apply item effect
  359.     for target in @target_battlers
  360.       if target != nil
  361.         target.item_effect(@item)
  362.       end
  363.     end
  364.   end
  365.  
  366.   #--------------------------------------------------------------------------
  367.   # * Frame Update (main phase step 4 : animation for target)
  368.   #--------------------------------------------------------------------------
  369.   def update_phase4_step4
  370.     # Animation for target
  371.     for target in @target_battlers
  372.       if target != nil
  373.         target.animation_id = @animation2_id
  374.         target.animation_hit = (target.damage != "Miss")
  375.       end
  376.     end
  377.     # Animation has at least 8 frames, regardless of its length
  378.     @wait_count = 8
  379.     # Shift to step 5
  380.     @phase4_step = 5
  381.   end
  382.  
  383.   #--------------------------------------------------------------------------
  384.   # * Frame Update (main phase step 5 : damage display)
  385.   #--------------------------------------------------------------------------
  386.   def update_phase4_step5
  387.     # Hide help window
  388.     @help_window.visible = false
  389.     # Refresh status window
  390.     @status_window.refresh
  391.     # Display damage
  392.     for target in @target_battlers
  393.       if target != nil
  394.         if target.damage != nil
  395.           target.damage_pop = true
  396.         end
  397.       end
  398.     end
  399.     # Shift to step 6
  400.     @phase4_step = 6
  401.   end
  402.  
  403. end
  404.  
  405. ###########################################################################
  406. #--------------------------------------------------------------------------
  407. # * This section enables the first two states to be inflicted onto enemies
  408. #--------------------------------------------------------------------------
  409. ###########################################################################
  410. class Game_Troop
  411.  
  412.   #--------------------------------------------------------------------------
  413.   # * Determine wether state 2 is in effect or not
  414.   #--------------------------------------------------------------------------
  415.   def state2_invulnerable(target)
  416.     # If it fits the conditions
  417.     @special_states = false
  418.     # Check whether special state available
  419.     for i in 0..($special_states2.size - 1)
  420.       if target.state?($special_states2[i])
  421.         @special_states = true
  422.       end
  423.     end
  424.     if @special_states == true
  425.       return true
  426.     else
  427.       return false
  428.     end
  429.   end
  430.  
  431.   def random_target_enemy(hp0 = false)
  432.     # Initialize roulette
  433.     roulette = []
  434.     # Loop
  435.     for enemy in @enemies
  436.       if state2_invulnerable(enemy) == false
  437.         if (not hp0 and enemy.exist?) or (hp0 and enemy.hp0?)
  438.           # Add an enemy to the roulette
  439.           roulette.push(enemy)
  440.         end
  441.       end
  442.     end
  443.     # If roulette size is 0
  444.     if roulette.size == 0
  445.       return nil
  446.     end
  447.     # Spin the roulette, choose an enemy
  448.     return roulette[rand(roulette.size)]
  449.   end
  450.  
  451.   #--------------------------------------------------------------------------
  452.   # * Smooth Selection of a Target Enemy
  453.   #     enemy_index : enemy index
  454.   #--------------------------------------------------------------------------
  455.   def smooth_target_enemy(enemy_index)
  456.     # Get an enemy
  457.     enemy = @enemies[enemy_index]
  458.     # If an enemy exists
  459.     if enemy != nil and enemy.exist?
  460.       if state2_invulnerable(enemy) == false
  461.         return enemy
  462.       end
  463.     end
  464.     # Loop
  465.     for enemy in @enemies
  466.       # If an enemy exists
  467.       if enemy.exist?
  468.         if state2_invulnerable(enemy) == false
  469.           return enemy
  470.         end
  471.       end
  472.       enemy = $game_troop.random_target_enemy
  473.       return enemy
  474.     end
  475.   end
  476. end
  477.  
  478. #----------------------------------------------------------------------------
  479. class Scene_Battle
  480. #----------------------------------------------------------------------------
  481.   def make_basic_action_result
  482.     # If attack
  483.     if @active_battler.current_action.basic == 0
  484.       # Set anaimation ID
  485.       @animation1_id = @active_battler.animation1_id
  486.       @animation2_id = @active_battler.animation2_id
  487.       # If action battler is enemy
  488.       if @active_battler.is_a?(Game_Enemy)
  489.         if @active_battler.restriction == 3
  490.           target = $game_troop.random_target_enemy
  491.         elsif @active_battler.restriction == 2
  492.           target = $game_party.random_target_actor
  493.         else
  494.           index = @active_battler.current_action.target_index
  495.           target = $game_party.smooth_target_actor(index)
  496.           if state2_invulnerable(target) == false
  497.           else
  498.             target = $game_troop.random_target_actor
  499.           end
  500.         end
  501.       end
  502.       # If action battler is actor
  503.       if @active_battler.is_a?(Game_Actor)
  504.         if @active_battler.restriction == 3
  505.           target = $game_party.random_target_actor
  506.         elsif @active_battler.restriction == 2
  507.           target = $game_troop.random_target_enemy
  508.         else
  509.           index = @active_battler.current_action.target_index
  510.           target = $game_troop.smooth_target_enemy(index)
  511.           if state2_invulnerable(target) == false
  512.           else
  513.             target = $game_troop.random_target_enemy
  514.           end
  515.         end
  516.       end
  517.       # Set array of targeted battlers
  518.       @target_battlers = [target]
  519.       # Apply normal attack results
  520.       if target != nil
  521.         for target in @target_battlers
  522.           target.attack_effect(@active_battler)
  523.         end
  524.       end
  525.       return
  526.     end
  527.     # If guard
  528.     if @active_battler.current_action.basic == 1
  529.       # Display "Guard" in help window
  530.       @help_window.set_text($data_system.words.guard, 1)
  531.       return
  532.     end
  533.     # If escape
  534.     if @active_battler.is_a?(Game_Enemy) and
  535.        @active_battler.current_action.basic == 2
  536.       # Display "Escape" in help window
  537.       @help_window.set_text("Escape", 1)
  538.       # Escape
  539.       @active_battler.escape
  540.       return
  541.     end
  542.     # If doing nothing
  543.     if @active_battler.current_action.basic == 3
  544.       # Clear battler being forced into action
  545.       $game_temp.forcing_battler = nil
  546.       # Shift to step 1
  547.       @phase4_step = 1
  548.       return
  549.     end
  550.   end
  551.  
  552. end
  553.  
  554.  
  555. ###########################################################################
  556. #--------------------------------------------------------------------------
  557. # * This section enables grey battler sprite
  558. #--------------------------------------------------------------------------
  559. ###########################################################################
  560. class Sprite_Battler < RPG::Sprite
  561.   #--------------------------------------------------------------------------
  562.   # * Determine wether state 3 is in effect or not
  563.   #--------------------------------------------------------------------------
  564.   def state3_gray(target)
  565.     # If it fits the conditions
  566.     @special_states = false
  567.     # Check whether special state available
  568.     for i in 0..($special_states3.size - 1)
  569.       if target.state?($special_states3[i])
  570.         @special_states = true
  571.       end
  572.     end
  573.     if @special_states == true
  574.       return true
  575.     else
  576.       return false
  577.     end
  578.   end
  579.  
  580.   alias black_sprite_update update
  581.   def update
  582.     black_sprite_update
  583.     if @battler != nil
  584.       if state3_gray(@battler) == true
  585.         self.tone.set($special_tone[0],$special_tone[1],$special_tone[2],$special_tone[3])
  586.       end
  587.     end
  588.   end
  589.  
  590. end
Comments
  • User was banned
Add Comment
Please, Sign In to add comment