[XP] Power Word Shield

Started by Falcon, September 05, 2008, 03:41:29 pm

Previous topic - Next topic

Falcon

September 05, 2008, 03:41:29 pm Last Edit: June 12, 2009, 05:14:18 pm by Aqua
Power Word: Shield Status Effect
Authors: Falcon
Version: 1.0
Type: Status Effect
Key Term: Misc Add-on



Introduction

This script allows you to use the Power Word: Shield status. For those of you who never played WoW, the shield absorbs some damage before it goes away.


Features


  • Absorb Damage, including poisons.
  • Configure how much damage you want the shield to absorb.



Screenshots

Imagine the actor has a status effect called power word shield. Now imagine he takes no damage.


Demo

http://www.rmrevolution.com/138/power-word-shield-status-effect/


Script
Spoiler: ShowHide
#==============================================================================
# ** Power Word: Shield Status Effect
#------------------------------------------------------------------------------
# The_Falcon
# 1.0
# 1.1.07
# SDK Version : 2.3 - Parts 1
#==============================================================================
# This script overwrites the following methods:
#------------------------------------------------------------------------------
# Game_Battler : attack_effect , skill_effect , slip_damage_effect
#------------------------------------------------------------------------------
# This script aliases the following methods:
#------------------------------------------------------------------------------
# Game Battler : initialize , add_state
#==============================================================================
#How to use:
#
#Add the script under the SDK. Then you'll need to make a new state and change the PWS_ID #in the script to the ID of the effect. Then make the skills and whatnot so you can use the #new effect goofy
#Also, keep in mind, the shield is NOT meant to be dispelled, so any dispel effects will #probably screw the system up a bit.
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Power Word: Shield Status Effect', 'The_Falcon', 1.0, '01.01.08')
SDK.check_requirements(2.3, [], [])
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Power Word: Shield Status Effect')
 PWS_ID = 17 #ID of the power word shield state
 PWS_PERCENT = 0.2 #The percent of health you want PWS to absorb
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================
class Game_Battler
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader   :pws_hp           # Strength of PWS
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias pws_init initialize
 SDK.log_alias(:Game_Battler, :initialize, :pws_init)
 #--------------------------------------------------------------------------
 def initialize
   pws_init
   @pws_hp = 0
 end
 #--------------------------------------------------------------------------
 # * Add State
 #     state_id : state ID
 #     force    : forcefully added flag (used to deal with auto state)
 #--------------------------------------------------------------------------
 alias pws_add_state add_state
 SDK.log_alias(:Game_Battler, :add_state, :pws_add_state)
 #--------------------------------------------------------------------------
 def add_state(state_id, force = false)
   if state_id == PWS_ID
     @pws_hp = Integer(self.maxhp * PWS_PERCENT)
   end
   pws_add_state(state_id, force)
 end
 # log the overwrite
 SDK.log_overwrite(:Game_Battler, :attack_effect)
 #--------------------------------------------------------------------------
 # * Applying Normal Attack Effects
 #     attacker : battler
 #--------------------------------------------------------------------------
 def attack_effect(attacker)
   # Clear critical flag
   self.critical = false
   # First hit detection
   hit_result = (rand(100) < attacker.hit)
   # If hit occurs
   if hit_result == true
     # Calculate basic damage
     atk = [attacker.atk - self.pdef / 2, 0].max
     self.damage = atk * (20 + attacker.str) / 20
     # Element correction
     self.damage *= elements_correct(attacker.element_set)
     self.damage /= 100
     # If damage value is strictly positive
     if self.damage > 0
       # Critical correction
       if rand(100) < 4 * attacker.dex / self.agi
         self.damage *= 2
         self.critical = true
       end
       # Guard correction
       if self.guarding?
         self.damage /= 2
       end
     end
     # Dispersion
     if self.damage.abs > 0
       amp = [self.damage.abs * 15 / 100, 1].max
       self.damage += rand(amp+1) + rand(amp+1) - amp
     end
     # Second hit detection
     eva = 8 * self.agi / attacker.dex + self.eva
     hit = self.damage < 0 ? 100 : 100 - eva
     hit = self.cant_evade? ? 100 : hit
     hit_result = (rand(100) < hit)
   end
   # If hit occurs
   if hit_result == true
     # State Removed by Shock
     remove_states_shock
     #-------------------------------------------
     #If the shield has strength
     if state?(PWS_ID)
       if pws_hp > self.damage
         # Substract damage from the shield's strength
         @pws_hp -= self.damage
         self.damage = "Absorb"
       else
         # Substract remaining strength from damage
         self.damage -= @pws_hp
         # Substract damage from HP
         self.hp -= self.damage
         remove_state(PWS_ID)
       end
     else
       # Substract damage from HP
       self.hp -= self.damage
     end
     #-------------------------------------------
     # State change
     @state_changed = false
     states_plus(attacker.plus_state_set)
     states_minus(attacker.minus_state_set)
   # When missing
   else
     # Set damage to "Miss"
     self.damage = "Miss"
     # Clear critical flag
     self.critical = false
   end
   # End Method
   return true
 end
 # log the overwrite
 SDK.log_overwrite(:Game_Battler, :skill_effect)
 #--------------------------------------------------------------------------
 # * Apply Skill Effects
 #     user  : the one using skills (battler)
 #     skill : skill
 #--------------------------------------------------------------------------
 def skill_effect(user, skill)
   # Clear critical flag
   self.critical = false
   # If skill scope is for ally with 1 or more HP, and your own HP = 0,
   # or skill scope is for ally with 0, and your own HP = 1 or more
   if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
      ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
     # End Method
     return false
   end
   # Clear effective flag
   effective = false
   # Set effective flag if common ID is effective
   effective |= skill.common_event_id > 0
   # First hit detection
   hit = skill.hit
   if skill.atk_f > 0
     hit *= user.hit / 100
   end
   hit_result = (rand(100) < hit)
   # Set effective flag if skill is uncertain
   effective |= hit < 100
   # If hit occurs
   if hit_result == true
     # Calculate power
     power = skill.power + user.atk * skill.atk_f / 100
     if power > 0
       power -= self.pdef * skill.pdef_f / 200
       power -= self.mdef * skill.mdef_f / 200
       power = [power, 0].max
     end
     # Calculate rate
     rate = 20
     rate += (user.str * skill.str_f / 100)
     rate += (user.dex * skill.dex_f / 100)
     rate += (user.agi * skill.agi_f / 100)
     rate += (user.int * skill.int_f / 100)
     # Calculate basic damage
     self.damage = power * rate / 20
     # Element correction
     self.damage *= elements_correct(skill.element_set)
     self.damage /= 100
     # If damage value is strictly positive
     if self.damage > 0
       # Guard correction
       if self.guarding?
         self.damage /= 2
       end
     end
     # Dispersion
     if skill.variance > 0 and self.damage.abs > 0
       amp = [self.damage.abs * skill.variance / 100, 1].max
       self.damage += rand(amp+1) + rand(amp+1) - amp
     end
     # Second hit detection
     eva = 8 * self.agi / user.dex + self.eva
     hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
     hit = self.cant_evade? ? 100 : hit
     hit_result = (rand(100) < hit)
     # Set effective flag if skill is uncertain
     effective |= hit < 100
   end
   # If hit occurs
   if hit_result == true
     # If physical attack has power other than 0
     if skill.power != 0 and skill.atk_f > 0
       # State Removed by Shock
       remove_states_shock
       # Set to effective flag
       effective = true
     end
     #-------------------------------------------
     #If the shield has strength
     if state?(PWS_ID)
       if pws_hp > self.damage
         last_hp = @pws_hp
         # Substract damage from the shield's strength
         @pws_hp -= self.damage
         self.damage = "Absorb"
         effective |= @pws_hp != last_hp
       else
         # Substract damage from HP
         last_hp = @pws_hp
         # Subtract shield's last strength from damage
         self.damage -= @pws_hp
         self.hp -= self.damage
         remove_state(PWS_ID)
         effective |= self.hp != last_hp
       end
     else
       # Substract damage from HP
       last_hp = self.hp
       self.hp -= self.damage
       effective |= self.hp != last_hp
     end
     #-------------------------------------------
     # State change
     @state_changed = false
     effective |= states_plus(skill.plus_state_set)
     effective |= states_minus(skill.minus_state_set)
     # If power is 0
     if skill.power == 0
       # Set damage to an empty string
       self.damage = ""
       # If state is unchanged
       unless @state_changed
         # Set damage to "Miss"
         self.damage = "Miss"
       end
     end
   # If miss occurs
   else
     # Set damage to "Miss"
     self.damage = "Miss"
   end
   # If not in battle
   unless $game_temp.in_battle
     # Set damage to nil
     self.damage = nil
   end
   # End Method
   return effective
 end
 # log the overwrite
 SDK.log_overwrite(:Game_Battler, :slip_damage_effect)
 #--------------------------------------------------------------------------
 # * Application of Slip Damage Effects
 #--------------------------------------------------------------------------
 def slip_damage_effect
   # Set damage
   self.damage = self.maxhp / 10
   # Dispersion
   if self.damage.abs > 0
     amp = [self.damage.abs * 15 / 100, 1].max
     self.damage += rand(amp+1) + rand(amp+1) - amp
   end
   #-------------------------------------------
   #If the shield has strength
   if state?(PWS_ID)
     if pws_hp > self.damage
       # Substract damage from the shield's strength
       @pws_hp -= self.damage
       self.damage = "Absorb"
     else
       # Subtract shield's last strength from damage
       self.damage -= @pws_hp
       self.hp -= self.damage
       remove_state(PWS_ID)
     end
   else
     # Substract damage from HP
     last_hp = self.hp
     self.hp -= self.damage
   end
   #-------------------------------------------
   # End Method
   return true
 end
end
#--------------------------------------------------------------------------
# End SDK Enabled Test
#--------------------------------------------------------------------------
end




Instructions

Add the script under the SDK. Then you'll need to make a new state and change the PWS_ID in the script to the ID of the effect. Then make the skills and whatnot so you can use the new effect :)

Also, keep in mind, the shield is NOT meant to be dispelled, so any dispel effects will probably screw the system up a bit.


Compatibility

Tried to make this SDK Compliant and Compatible.


Credits and Thanks


  • Falcon



Author's Notes

Next version, I plan to add:

  • Ability to turn off poison damage absorb.
  • Fix any bugs/errors of course :P


Free to use for non-commerical use, with credit of course ;)

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Falcon

I'd rather just delete this than remake it with a new template :P

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Falcon

There's a difference :P

All I see is some lines XD

Starrodkirby86

Quote from: Falcon on September 05, 2008, 10:36:50 pm
There's a difference :P

All I see is some lines XD
More like, bigger font, different arrangement, key term, and all that good stuff... :ninja:


This seems to be a very convenient script, like one that seems to be quick and all, but it does go a long way...Nice. I haven't played WoW so I'm not fully acquainted with this system. :/

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Aqua

Mmm...
Site is down. >.<

Anyone have a copy or something? XD

Jackolas

was cleaning up my pc.
found shit loads of scripts that I collected in the time.
do you still need it?
and am I allowed to post here? (could not contact Falcon, I tried tough)

Aqua

Yes, please.

I'll edit the 1st post with it... XD

Jackolas

June 12, 2009, 05:05:52 pm #9 Last Edit: June 13, 2009, 02:10:29 pm by Jackolas
QuoteTried to make this SDK Compliant and Compatible.


it would be cool if someone could try to undo the Compatible with SDK.
tried SDK 1 time and will never have it invade my projects again, but love this script.

Blizzard

Compatible doens't mean dependent. o_o; Just try to use it. I don't think it requires SDK.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

We should make an SDK compatibility layer :V

Blizzard

And promote its usage? No way! :V
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Jackolas

June 13, 2009, 06:02:57 pm #13 Last Edit: June 13, 2009, 06:06:34 pm by Jackolas
if you don't have SDK it crashes (like every SDK script)

line 25: name error occurred
uninitialized constant SDK

so its kinda SDK dependable

Aqua

You can just delete those lines... :P

Jackolas

June 14, 2009, 05:12:20 am #15 Last Edit: June 14, 2009, 05:23:43 am by Jackolas
and than the shield won't work anymore :S

edit: NVM found the problem... needed to change 1 of my scripts :S

Inverse

If it is not SDK dependant then how can I make it work ? I've tried to simply delete the lines with SDK but it doesn't work... any help ?

deadeye

November 10, 2012, 12:47:58 pm #17 Last Edit: November 10, 2012, 05:09:05 pm by KK20
For anyone struggling with non-SDK versions of this script, because this script is AWESOME and I couldn't for the life of me figure out how to simply remove the SDK lines, I just edited a few things in the default battler_3 script in order to make this work fine (or fine thus far).

if you add this around line 8

attr_reader   :pws_hp           # Strength of PWS
 alias pws_init initialize
 def initialize
   pws_init
   @pws_hp = (how much HP you want the shield to have)
 end

Then continue down to where it says #subtract damage from HP and remove this:

# Substract damage from HP
     last_hp = self.hp
     self.hp -= self.damage
   end

You can simply add this in replacement:

# Substract damage from HP
     #If the shield has strength
   if state?(state of the power shield)
     if self.damage > 0
       if pws_hp > self.damage
         # Substract damage from the shield's strength
         @pws_hp -= self.damage
         self.damage = "Absorbed"
       else
         # Subtract shield's last strength from damage
         self.damage -= @pws_hp
         remove_state(31)
         last_hp = self.hp
         self.hp -= self.damage
         @pws_hp = (PWS original HP)
       end
     end
   else
     # Substract damage from HP
     last_hp = self.hp
     self.hp -= self.damage
   end


ALSO: my appologies, I can't figure out how to do the spoiler script thing :/ I'm new

Fixed it for ya. ~KK20