Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Little edit on Atoas Drain addon (ATOA ACBS)

Hello guys. Im using atoas acbs and his drain addon as you can see below.
It allows one to add an drain effect on skills, items, weapons.
for example:
Drain_Action['Skill'][116] = {'hp' => [50, 27, 161, true, true]}
the skill id 116 has a 50% chance to absorb 27% of the damage the user did to a monster. And the animation 161 will be shown.


But besides the skill, weapon, item option - I also want the same options for states. I want the script to be able to choose a state and as long as a battler has the certain state he will absorb a certain amount of HP or SP when performing normal attacks or skills.

It should look like this:
Drain_Action['State'][30] = {'hp' => [50, 27, 161, true, true, true, true, true]}

It means: When a battler would inflicted with state 30, he had a 50% chance to absorb 27% of the damage he dealt. 161 means animation 161 will popup when absorb works.
Note that I've put another 3 trues which are not included in the the script itself. The least 3 trues are just something I came up with. The first true makes clear that the absorb state works with normal attacks, the second true makes clear it works for physical attacks and the last true makes clear that it works with magical attacks.
So the absorb would come with any normal, magical, physical attacks as long the battler is inflicted with the state I mentioned.

I hope my english is enough to get my message out.

Thanks in advance.



Code:
#==============================================================================

# Skill Drain

# By Atoa

#==============================================================================

# This script allow to create skills and equips that adds the effect 'drain'

# of HP and SP.

# That way attacks and skills can absorb part of the damage caused

#==============================================================================

 

module Atoa

  # Do not remove this line

  Drain_Action = {'Skill' => {}, 'Weapon' => {}, 'Item' => {}}

  # Do not remove this line

  

  # Drain_Action[action_type][id] = {drain_type => [success, rate, anim_id, pop, show_excedent],...}

  # action_type = action type

  #   action_type = 'Skill' for skills, 'Weapon' for weapons, 'Item' for items

  # id = ID of the skill/weapon/item

  # drain_type = drain type

  #   'hp' for HP drain, 'sp' for SP drain

  # success = absorb success rate

  # rate = % of damage converted in HP/SP

  # anim_id = ID of the animation shown when absorb HP/SP, leave nil or 0 for

  #   no animation

  # 

  

  Drain_Action['Skill'][116] = {'hp' => [50, 27, 161, true, true]} 

                               # 'sp' =>[100, 50, 88, true, false]}

 

  #Drain_Action['Skill'][904] = {'hp' => [100, 100, nil, true, true]} 

  #Drain_Action['Skill'][308] = {'hp' => [100, 100, nil, true, true]} 

                                

  Drain_Action['Weapon'][43] = {'hp' => [50, 50, nil, true, true]}

  

  

end

 

#==============================================================================

# ■ Atoa Module

#==============================================================================

$atoa_script = {} if $atoa_script.nil?

$atoa_script['Atoa Drain'] = true

 

#==============================================================================

# ■ Game_Battler

#------------------------------------------------------------------------------

# Esta classe gerencia os jogadores da batalha.

# Esta classe identifica os Aliados ou Heróis como (Game_Actor) e

# os Inimigos como (Game_Enemy).

#==============================================================================

 

class Game_Battler

  #--------------------------------------------------------------------------

  # Variáveis Públicas

  #--------------------------------------------------------------------------

  attr_accessor :base_absorb

  #--------------------------------------------------------------------------

  # Inicialização do Objeto

  #--------------------------------------------------------------------------

  alias initialize_drain initialize

  def initialize

    initialize_drain

    @base_absorb = 0

  end

end

 

#==============================================================================

# ■ Scene_Battle

#------------------------------------------------------------------------------

# Esta classe processa a tela de Batalha

#==============================================================================

 

class Scene_Battle

  #--------------------------------------------------------------------------

  # Atualização da fase 4 do personagem (parte 1)

  #     battler : Battler ativo

  #--------------------------------------------------------------------------

  alias step4_part2_drain step4_part2

  def step4_part2(battler)

    step4_part2_drain(battler)

    set_drain_damage(battler)

  end

  #--------------------------------------------------------------------------

  # Atualização da fase 4 do personagem (parte 3)

  #     battler : Battler ativo

  #--------------------------------------------------------------------------

  alias step4_part3_drain step4_part3

  def step4_part3(battler)

    step4_part3_drain(battler)

    action = battler.now_action

    if action != nil and Drain_Action[action.type_name] != nil and

       Drain_Action[action.type_name].include?(action_id(action))

      absorb_damage(battler, battler.base_absorb, Drain_Action[action.type_name][action_id(action)].dup)

    end

  end

  #--------------------------------------------------------------------------

  # Definir dano do dreno

  #     battler : Battler ativo

  #--------------------------------------------------------------------------

  def set_drain_damage(battler)

    battler.base_absorb = 0

    for target in battler.target_battlers

      battler.base_absorb += target.damage if target.damage.numeric?

    end

  end

  #--------------------------------------------------------------------------

  # Absover dano

  #     battler : Battler ativo

  #     absorb  : valor de absorção

  #     action  : Ação

  #--------------------------------------------------------------------------

  def absorb_damage(battler, absorb, action)

    for type in action.keys

      if type == 'hp' and (action[type][0] >= rand(100))

        base_absorb = ((absorb * action[type][1]) / 100).to_i

        if base_absorb > 0

          difference = battler.maxhp - battler.hp

          base_absorb = [base_absorb, difference].min

        elsif base_absorb < 0 

          base_absorb = [base_absorb, - battler.hp].max

        end

        if base_absorb != 0

          battler.damage = - base_absorb

          battler.hp -= battler.damage

          battler.animation_id = action[type][2].nil? ? 0 : action[type][2]

          battler.damage_pop = action[type][3]

          wait(3) if battler.damage != 0

        end

      end

      if type == 'sp' and (action[type][0] >= rand(100))

        base_absorb = ((absorb * action[type][1]) / 100).to_i

        if base_absorb > 0

          difference = battler.maxsp - battler.sp

          base_absorb = [base_absorb, difference].min

        elsif base_absorb < 0 

          base_absorb = [base_absorb, - battler.sp].max

        end

        if base_absorb != 0

          battler.damage = - base_absorb

          battler.sp -= battler.damage

          battler.animation_id = action[type][2].nil? ? 0 : action[type][2]

          battler.damage_pop = action[type][3]

          battler.sp_damage = action[type][3]

          wait(3) if battler.damage != 0

        end

      end

    end

  end

end
 
Solution
Well...
At line 82 I added this underline bit excuse me, blue bit (so you can see the underscore)
set_drain_damage(battler) unless battler.target_battlers.include?(battler)

This prevents the character from draining themselves.

and/or

And at line 108
battler.base_absorb += target.damage if target.damage.numeric? and target.damage > 0

That'll stop drain damage from a healing attack, like say a monster absorbed fire.
Sorry for ignoring this for so long. The problem with the way you want it done is that script works via action types. Attack, Skill, Item.

The method you'd suggest wouldn't work because "State" isn't an action_type.
Maybe adding a line to the step4_part3 that just does the drain action if the battler has assigned state.
I'm too tried to think of how to write it right now.
 
It's not everything you asked for, but it works for the most part. Slightly buggy.
The drain state ID I used is [24], if you want it to be something else you'll have the change lines 35, 97, and 98

Note:
  • It only works on single targets. If you hit multiple targets with a weapon or spell, nothing will happen.
  • If the base_drain variable is something other than 0 then you'll "drain" that amount while guarding.
  • Healing a target will Damage you. You can kill yourself while healing, I recommend keeping the drain% low.
  • If an enemy absorbs an attack, it'll damage you.

Code:
#==============================================================================

# Skill Drain

# By Atoa

#==============================================================================

# This script allow to create skills and equips that adds the effect 'drain'

# of HP and SP.

# That way attacks and skills can absorb part of the damage caused

#==============================================================================

 

module Atoa

  # Do not remove this line

  Drain_Action = {'Skill' => {}, 'Weapon' => {}, 'Item' => {}, 'State' => {}}

  # Do not remove this line

 

  # Drain_Action[action_type][id] = {drain_type => [success, rate, anim_id, pop, show_excedent],...}

  # action_type = action type

  #   action_type = 'Skill' for skills, 'Weapon' for weapons, 'Item' for items

  # id = ID of the skill/weapon/item

  # drain_type = drain type

  #   'hp' for HP drain, 'sp' for SP drain

  # success = absorb success rate

  # rate = % of damage converted in HP/SP

  # anim_id = ID of the animation shown when absorb HP/SP, leave nil or 0 for

  #   no animation

  #

 

  Drain_Action['Skill'][116] = {'hp' => [50, 27, 161, true, true]}

                               # 'sp' =>[100, 50, 88, true, false]}

 

  #Drain_Action['Skill'][904] = {'hp' => [100, 100, nil, true, true]}

  #Drain_Action['Skill'][308] = {'hp' => [100, 100, nil, true, true]}

                               

  Drain_Action['Weapon'][001] = {'hp' => [50, 50, nil, true, true]}

  

  Drain_Action['State'][24] = {'hp' => [100, 100, nil, true, true]}

 

end

 

#==============================================================================

# ■ Atoa Module

#==============================================================================

$atoa_script = {} if $atoa_script.nil?

$atoa_script['Atoa Drain'] = true

 

#==============================================================================

# ■ Game_Battler

#------------------------------------------------------------------------------

# Esta classe gerencia os jogadores da batalha.

# Esta classe identifica os Aliados ou Heróis como (Game_Actor) e

# os Inimigos como (Game_Enemy).

#==============================================================================

 

class Game_Battler

  #--------------------------------------------------------------------------

  # Variáveis Públicas

  #--------------------------------------------------------------------------

  attr_accessor :base_absorb

  #--------------------------------------------------------------------------

  # Inicialização do Objeto

  #--------------------------------------------------------------------------

  alias initialize_drain initialize

  def initialize

    initialize_drain

    @base_absorb = 0

  end

end

 

#==============================================================================

# ■ Scene_Battle

#------------------------------------------------------------------------------

# Esta classe processa a tela de Batalha

#==============================================================================

 

class Scene_Battle

  #--------------------------------------------------------------------------

  # Atualização da fase 4 do personagem (parte 1)

  #     battler : Battler ativo

  #--------------------------------------------------------------------------

  alias step4_part2_drain step4_part2

  def step4_part2(battler)

    step4_part2_drain(battler)

    set_drain_damage(battler)

  end

  #--------------------------------------------------------------------------

  # Atualização da fase 4 do personagem (parte 3)

  #     battler : Battler ativo

  #--------------------------------------------------------------------------

  alias step4_part3_drain step4_part3

  def step4_part3(battler)

    step4_part3_drain(battler)

    action = battler.now_action

    if action != nil and Drain_Action[action.type_name] != nil and

       Drain_Action[action.type_name].include?(action_id(action))

      absorb_damage(battler, battler.base_absorb, Drain_Action[action.type_name][action_id(action)].dup)

    end

      #Drain State 

      if battler.states == [24]

        absorb_damage(battler, battler.base_absorb, Drain_Action['State'][24].dup)

      end

  end

  #--------------------------------------------------------------------------

  # Definir dano do dreno

  #     battler : Battler ativo

  #--------------------------------------------------------------------------

  def set_drain_damage(battler)

    battler.base_absorb = 0

    for target in battler.target_battlers

      battler.base_absorb += target.damage if target.damage.numeric?

    end

  end

  #--------------------------------------------------------------------------

  # Absover dano

  #     battler : Battler ativo

  #     absorb  : valor de absorção

  #     action  : Ação

  #--------------------------------------------------------------------------

  def absorb_damage(battler, absorb, action)

    for type in action.keys

      if type == 'hp' and (action[type][0] >= rand(100))

        base_absorb = ((absorb * action[type][1]) / 100).to_i

        if base_absorb > 0

          difference = battler.maxhp - battler.hp

          base_absorb = [base_absorb, difference].min

        elsif base_absorb < 0

          base_absorb = [base_absorb, - battler.hp].max

        end

        if base_absorb != 0

          battler.damage = - base_absorb

          battler.hp -= battler.damage

          battler.animation_id = action[type][2].nil? ? 0 : action[type][2]

          battler.damage_pop = action[type][3]

          wait(3) if battler.damage != 0

        end

      end

      if type == 'sp' and (action[type][0] >= rand(100))

        base_absorb = ((absorb * action[type][1]) / 100).to_i

        if base_absorb > 0

          difference = battler.maxsp - battler.sp

          base_absorb = [base_absorb, difference].min

        elsif base_absorb < 0

          base_absorb = [base_absorb, - battler.sp].max

        end

        if base_absorb != 0

          battler.damage = - base_absorb

          battler.sp -= battler.damage

          battler.animation_id = action[type][2].nil? ? 0 : action[type][2]

          battler.damage_pop = action[type][3]

          battler.sp_damage = action[type][3]

          wait(3) if battler.damage != 0

        end

      end

    end

  end

end
 
Thank you so much for helping me. Btw. you dont need to apologize. I know that you as a staff have other things to care first.
To the script. You said that it will only drain HP from single monster, but its also drains HP or SP from more than just one monster, when I use magic which deals dmg to many monsters it also heals me. Well, thats the way I wanted it anyway^^

I made some bug test and Im going to test it more in the coming week, I didint found bugs aside from what you've posted.

However, there are some things that disturb me.
1. When I use the state Berserk (it makes the player auto attack randomly) on me (and I also have the drain state) why doesnt it drain HP when he (the player) auto attacks monsters on his will? Normally it does and normally it should. But it doesnt.
EDIT:
2. Now, this is a big bug. If my hero also haves another state like regeneation besides the drain state, no HP or SP will be drained. Any Ideas how to fix this?
3. What do I have to do or what do I have to edit if I want to make another state drains?
for example, I've now the state 24 and I want to create another such state for SP, what do I need to add?
Thanks, very much^^
 
Under line 35 make a new Drain_Action['State'][Whatever#You'reUsing]

Then at line#96, where it says #Drain State, Copy the 3 lines from If to End and paste it underneath that. Then just Change what you just copied from State #24 to whatever you're going to use. So basically it'll run 2 "if" statements: if state 24, if state whatever.

About the bugs. You might check the other states in the database to make use they aren't erasing the drain state.
I don't know how the Berserk state works, but I would guess it's the same reason you can't drain multiple targets. It can't drain a target because it doesn't know what the target is. Or it's handled in a different method, in a different script. Idk
 
coyotecraft":20vnx7hn said:
Under line 35 make a new Drain_Action['State'][Whatever#You'reUsing]

Then at line#96, where it says #Drain State, Copy the 3 lines from If to End and paste it underneath that. Then just Change what you just copied from State #24 to whatever you're going to use. So basically it'll run 2 "if" statements: if state 24, if state whatever.

About the bugs. You might check the other states in the database to make use they aren't erasing the drain state.
I don't know how the Berserk state works, but I would guess it's the same reason you can't drain multiple targets. It can't drain a target because it doesn't know what the target is. Or it's handled in a different method, in a different script. Idk
Thanks.
I think I know what caused the bug when another state i applied on the actor and that no absorb is done.
You have wrriten:
if battler.states == [24]
That means that absorb wil ONLY take place when only state 24 is applied but it wont take place when the actor has more states besides the 24.
I've changed the line to:
if battler.states.include?(120)
And it worked.^^
Btw. absorb does take place when multiple targets are effected.
Is there a way to fix the bug that healing also deals damage?
 
Maybe it was just the version of Atoas CBS that I was using. The character with a boomerang wasn't draining attacks.

Are you sure you want to fix the healing damage? Imo, it's a nice balance to not be able to heal themselves or others by nature of being a vampire or that a target might be undead. A blessing and a curse.

You can code in restrictions like, no drain if damage is negative (healing) or target is self.
 
Hmm. Dont know.
My caracter does it.
Well, if its fixable, I'm going to do that.

But the problem is: How do I code that? Because Im nor a programmer nor a coder.
I only knew the "if battler.states.include?(120)" line because it was on another script and I had a similar issue.
 
Well...
At line 82 I added this underline bit excuse me, blue bit (so you can see the underscore)
set_drain_damage(battler) unless battler.target_battlers.include?(battler)

This prevents the character from draining themselves.

and/or

And at line 108
battler.base_absorb += target.damage if target.damage.numeric? and target.damage > 0

That'll stop drain damage from a healing attack, like say a monster absorbed fire.
 
Solution
coyotecraft":2geciayu said:
Well...
At line 82 I added this underline bit excuse me, blue bit (so you can see the underscore)
set_drain_damage(battler) unless battler.target_battlers.include?(battler)

This prevents the character from draining themselves.

and/or

And at line 108
battler.base_absorb += target.damage if target.damage.numeric? and target.damage > 0

That'll stop drain damage from a healing attack, like say a monster absorbed fire.

Hm.. I did the both edits as you said, but now its vice versa.
My actor is still getting drain from a healing item, but this time not as a dmg but rather as a healing for himself.. So, its a double heal.
I wounder what it causes it.
Btw. thanks for the quick reply.

EDIT: I only edited the line 108 and left the line 82 as it was, it worked perfectly.
Thanks^^


I bumped on accident, please lock this topic.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top