[XP] Effectivity ratings for skills, defenses and attacks

Started by gerrtunk, July 14, 2011, 01:19:22 pm

Previous topic - Next topic

gerrtunk

July 14, 2011, 01:19:22 pm Last Edit: September 10, 2011, 12:58:53 pm by gerrtunk
Effectivity ratings for skills, defenses and attacks
Authors: gerrtunk,gerkrt
Version: 1.5
Type: Battle Add-on
Key Term: Battle Add-on



Introduction
This script gives a lost option expanded from 2k3, where you could create
elements for equipment that defined it general effectivity in a scale of rates.


Features

Now you can set it for classes also, and for skills too.



Screenshots
No.


Demo

http://www.mediafire.com/?ezvrk0dvh94yz82



Script

Spoiler: ShowHide



Code: text
#==============================================================================
# Effectivity ratings for skills, defenses and attacks
# By gerkrt/gerrtunk
# Version: 1.5
# License: GPL, credits
# Date: 09/07/2011
# For the latests updates or bugs fixes of this script check here:
# http://usuarios.multimania.es/kisap/english_list.html
#==============================================================================

=begin

---------INTRODUCTION----------

This script gives a lost option expanded from 2k3, where you could create
elements for equipment that defined it general effectivity in a scale of rates.

Now you can set it for classes also, and for skills too.

--------INSTRUCTIONS------------

You have to define two things:
-Group armors, skills... by a name.
 Weapons_groups = {
   
   'Great Axe' => [1, 10],
   'Bow' => [[4,5]]
 }

'Group name' => ['weapon_id1, weapon_id2, etc],


-Make skills, weapons, etc scale ratings.

 Weapons_skills_ratings  = {
   'Great Axe' => [0.10, 0.20],
   'Bow' => [0.20, 0.40, 0.60, 0.80]
 }
 
'Group name' => ['rate for rating1, for 2, etc],

See that you need to add a entry for each group defining the scale ratings,
and the group.

What more you need? You have to define how effictevily the battler will use
the scale. For example, adding entries of that groups in some classes with
the effecitivety value:

 Classes_ratings = {
  1 => {
    'Great Axe' => 1,
    'Bow' => 1
   },
   
  2 => {
    'Mag' => 2
   },
 }
 
Then you have to add to classes ratings or actors ratings the group name with
the rating index value:

'Group name' => rate index,

The rate index number extract the values you store in Weapons_skills_ratings, like if
it used the 'A', 'B', etc, but with numbers. This works in the natural order, but
using a -1 index: it starts with index 0, 1, 2, 3, 4, etc. You can customitze each
scale at your will, in power or number of entries.

In this case, for example, for class 1:
  1 => {
    'Great Axe' => 1, # 0.20
    'Bow' => 1, # 0.40
   },

Then the value in the rating is multiplied with the damage. If there are values
of actor and class, first these two are multiplied, and then with the damage.

This means that a 0.10 is a 10% and a 1.4 a 140%

Note that if you put a invalid index in classes or actors ratings
it will give you a error.

The other things are pretty straightforward from here, they just use the same
methods and vocablury but for others things: skills, defense, actors, etc.

----CONFIGURE THE MODE-------

Set the mode used by the script: 'Both' classes and and actors, 'Only classes'
and 'Only actors'. You have to add that 'words' in that variable:

Use_class_actors = 'Both'

=end




module Wep
 # Set the mode used by the script: 'Both' classes and and actors, 'Only classes'
 # and 'Only actors'.
 Use_class_actors = 'Both'
 
 
 Weapons_groups = {
                   
   'Great Axe' => [1, 10],
   'Bow' => [[4,5]]
 }
 
 Weapons_skills_ratings  = {
   'Great Axe' => [0.10, 0.20],
   'Bow' => [0.20, 0.40, 0.60, 0.80, 1.00, 1.20, 1.40]
 }
 
 Skills_groups = {
                   
   'Mag' => [7],
 }
 
 Skills_skills_ratings  = {
   'Mag' => [0.10, 0.20],
 }
 
 
 Armors_groups = {
                   
   'Base' => [13],
   'Test' => [1]
 }
 
 Armors_skills_ratings  = {
   'Base' => [0.10, 0.20, 0.50],
   'Test'=> [0.10, 0.13, 0.50]
   
 }

 Classes_ratings = {
  1 => {
    'Great Axe' => 1,
    'Bow' => 1,
    'Base' => 2,
    'Mag' => 1,
    'Test' => 1
   }
 
 }
 
  Actors_ratings = {
  1 => {
    'Great Axe' => 0,
    'Bow' => 1,
   }
 
 }
   
end


class Game_Actor

 #--------------------------------------------------------------------------
 # * Attack Rate
 #--------------------------------------------------------------------------  
 def attack_rate
   # Search mark
   encounter = false
   class_val = 0
   actor_val = 0
   val = 0
   
   # Search if equipped weapons have rate
   for key,  value in Wep::Weapons_groups
     if value.include?(self.weapon_id)
       encounter = true
       # Class rate
       if Wep::Classes_ratings[self.class_id] != nil and Wep::Classes_ratings[@class_id][key] != nil
         rate = Wep::Classes_ratings[self.class_id][key]
         #p 'rate', rate
         class_val = Wep::Weapons_skills_ratings[key][rate]
         #p 'classval', class_val
         
       end
       
       if Wep::Actors_ratings[@actor_id] != nil and Wep::Actors_ratings[@actor_id][key] != nil
         # Actor rate
         rate = Wep::Actors_ratings[@actor_id][key]
         actor_val = Wep::Weapons_skills_ratings[key][rate]
       end
     end
   end
   

   # Check mode
   if Wep::Use_class_actors == 'Both'
     if actor_val == 0
       val = class_val
     elsif class_val == 0
       val = actor_val
     else
       val = class_val * actor_val
     end
     #p 'bo', val
   elsif Wep::Use_class_actors == 'Only classes'
     val = class_val
     #p'clas'
   else
     val = actor_val
   end
   
   # Make default if no value used
   val = 1.00 if encounter == false
   #p val, class_val, actor_val
   return val
 end

 #--------------------------------------------------------------------------
 # * Skill Rate
 #--------------------------------------------------------------------------
 def skill_rate(skill_id)
   # Search mark
   encounter = false
   class_val = 0
   actor_val = 0
   val = 0
   
   # Search if equipped weapons have rate
   for key,  value in Wep::Skills_groups
     if value.include?(skill_id)
       #p 'encounter', Wep::Classes_ratings[self.class_id], Wep::Classes_ratings[self.class_id][key]
       encounter = true
       # Class rate
       if Wep::Classes_ratings[self.class_id] != nil and Wep::Classes_ratings[@class_id][key] != nil
         rate = Wep::Classes_ratings[self.class_id][key]
         #p 'rate', rate,Wep::Skills_skills_ratings[key], key
         class_val = Wep::Skills_skills_ratings[key][rate]
         
         #p 'classval', class_val
         
       end
       
       if Wep::Actors_ratings[@actor_id] != nil and Wep::Actors_ratings[@actor_id][key] != nil
         # Actor rate
         rate = Wep::Actors_ratings[@actor_id][key]
         actor_val = Wep::Skills_skills_ratings[key][rate]
       end
     end
   end
   

   # Check mode
   if Wep::Use_class_actors == 'Both'
     if actor_val == 0
       val = class_val
     elsif class_val == 0
       val = actor_val
     else
       val = class_val * actor_val
     end
     #p 'bo', val
   elsif Wep::Use_class_actors == 'Only classes'
     val = class_val
     #p'clas'
   else
     val = actor_val
   end
   
   # Make default if no value used
   val = 1.00 if encounter == false
   #p val, class_val, actor_val
   return val
 end
   
 
 #--------------------------------------------------------------------------
 # * Defend Rate
 #--------------------------------------------------------------------------
 def defend_rate
   # Search mark
   encounter = false
   class_val = 0
   actor_val = 0
   val = 0
   arm_arr = [@armor1_id,@armor2_id,@armor3_id,@armor4_id ]
   
   for arm_id in arm_arr
     # Search if equipped weapons have rate
     for key,  value in Wep::Armors_groups
       if value.include?(arm_id)        
         encounter = true
         # Class rate
         if Wep::Classes_ratings[self.class_id] != nil and Wep::Classes_ratings[self.class_id][key] != nil
           rate = Wep::Classes_ratings[self.class_id][key] and Wep::Classes_ratings[@class_id][key] != nil
           #p 'rate', rate
           class_val += Wep::Armors_skills_ratings[key][rate]
           #p 'classval', class_val
           
         end
         
         if Wep::Actors_ratings[@actor_id] != nil and Wep::Actors_ratings[@actor_id][key] != nil
           # Actor rate
           rate = Wep::Actors_ratings[@actor_id][key]
           #p rate
           actor_val += Wep::Armors_skills_ratings[key][rate]
         end
       end
     end
     
   end
   # Check mode
   if Wep::Use_class_actors == 'Both'
     if actor_val == 0
       val = class_val
     elsif class_val == 0
       val = actor_val
     else
       val = class_val * actor_val
     end
     #p 'both'
   elsif Wep::Use_class_actors == 'Only classes'
     val = class_val
     #p'clas'
   else
     val = actor_val
   end
   
   # Make default if no value used
   val = 1.00 if encounter == false
   #p val, class_val, actor_val
   return val
 end
 
 
 
end


class Game_Battler
 
 #--------------------------------------------------------------------------
 # * 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
     
     # Rating correction only for actors
     if user.is_a? Game_Actor
      self.damage *= user.skill_rate(skill.id)
      self.damage = self.damage.to_i
     end
     # Rating defensive correction only for actors
     if self.is_a? Game_Actor
      self.damage *= self.defend_rate
      self.damage = self.damage.to_i
     end
   
     # 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
     # Substract damage from HP
     last_hp = self.hp
     self.hp -= self.damage
     effective |= self.hp != last_hp
     # 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

 #--------------------------------------------------------------------------
 # * 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
     # Rating correction only for actors
     if attacker.is_a? Game_Actor
      self.damage *= attacker.attack_rate
      self.damage = self.damage.to_i
     end
     # Rating defensive correction only for actors
     if self.is_a? Game_Actor
      self.damage *= self.defend_rate
      self.damage = self.damage.to_i
     end
     # 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
     # Substract damage from HP
     self.hp -= self.damage
     # 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

 
end





Instructions
In the script.


Compatibility
Any other enemy troop script.


Credits and Thanks
No.


Author's Notes

I will add more things when i need them in my projects(or i have time), so it will be updated. Again, feedback, bugs,retc, i will listen.

Twb6543

You should add the platform this was made for [XP] or/and [VX] in the thread title.
If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

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.

gerrtunk


ForeverZer0

Just a suggestion, but I would think about cleaning up the config and making it a bit more over-viewable.  This will help those who may not be very savvy with scripts.

* Moves to database *
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Griver03

edit: ok now it works fine heres a demo if someone want ?!
you can add this to the first post if you want  :???:
http://www.mediafire.com/?ezvrk0dvh94yz82
My most wanted games...