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.

HP Requirement Skills (Skills require certain hp)

Alright, I am not too sure how to go about this, but I would like to make a script that allows the player to use skills if their hp is at a certain point or below/above.

Example:
Suffer - Player's hp must be below 50% in order to use this ability.
Renew - Player's hp must be above 90% in order to use this ability.

I am not sure how to set it up, but I was thinking something like this?

when {skillID} then return [hp percentage requirement, "above/below"]

Code:
      when 1 then return [50, "below"] #requires 50% or less health

      when 2 then return [90, "above"] #requires 90% or more health

If this is possible, I would love to have this working! :P Thanks for anyone who can help me!
 
I know one thing, with scripting arrays, you won't need names; skills/items/etc are only identified by ID. Also, a suggestion for "renew"-ish skills if your working on a game: Modify it's function to something more useful. I mean like: Player's hp must be in the range of 50%-70% but not 80% or higher in order to use this ability. This doesn't make such skills useless at max HP and still offers a mid-point healing/save skill.
 
Thats not the point...lol, I just need a script that can help me do this. :P Then the implements can be changed later on. :) But a health range percentage would be cool to have in there. :P But that does make sense. :D And the ability Renew is only usable with a certain amount of life. :) The ability heals status effects from allies and recovers some HP. :D
 

Atoa

Member

Well i have an script that do this (and more)

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

# Skills Conditions

# by Atoa

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

# This script allows to set special Conditions by some skills to be used

#

#  You can set variables, switches, hp, sp or states necessary for the skill

#  usage to be enabled.

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

 

module Atoa

  # Do not remove these lines

  Skill_State_On = {}

  Skill_State_Off = {}

  Skill_Sw_On = {}

  Skill_Sw_Off = {}

  Skill_Var = {}

  Skill_Hp = {}

  Skill_Sp = {}

  # Do not remove these lines

  

  

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

  # Conditions by active states

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

  # These skills can be used only if the user is under one or a set of states

  #

  # Skill_State_On[Skill ID] = {'include' => [States ID]}

  # Skill_State_On[Skill ID] = {'set' => [States ID]}

  #

  #  'include' => [States ID]

  #    The battler can only use the skill if he under one of the listed states

  #   

  #  'set' => [States ID]

  #    The battler can only use the skill if he under *all* the listed states

  

   Skill_State_On[68] = {'include' => [3]} # This example the skill 68 can only be used

                                           # if the actor is undes the state ID 3.

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

 

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

  # Conditions by not active states

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

  # These skills can be used only if the user is not under one or a set of states

  #

  # Skill_State_Off[Skill ID] = {'include' => [States ID]}

  # Skill_State_Off[Skill ID] = {'set' => [States ID]}

  #

  #  'include' => [States ID]

  #    The battler can only use the skill if he isn't under one of the listed states

  #   

  #  'set' => [States ID]

  #    The battler can only use the skill if he isn't under *all* the listed states

  

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

 

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

  # Conditions by active Switches

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

  # These skills can be used only if one or a set of switches is turned on

  #

  # Skill_Sw_On[Skill ID] = {'include' => [States ID]}

  # Skill_Sw_On[Skill ID] = {'set' => [States ID]}

  #

  #  'include' => [ID dos Switches]

  #    The battler can only use the skill if one of the listed switches is ON

  #   

  #  'set' => [ID dos Switches]

  #    The battler can only use the skill if *all* the listed switches is ON

  

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

  

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

  # Conditions by not active Switches

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

  # These skills can be used only if one or a set of switches is turned off

  #

  # Skill_Sw_Off[Skill ID] = {'include' => [Switches ID]}

  # Skill_Sw_Off[Skill ID] = {'set' => [Switches ID]}

  #

  #  'include' => [Switches ID]

  #    The battler can only use the skill if one of the listed switches is OFF

  #   

  #  'set' => [Switches ID]

  #    The battler can only use the skill if *all* the listed switches is OFF

 

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

  

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

  # Conditions by Variables

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

  # These skills can be used only if the variable met the set condition

  #

  # Skill_Var[Skill ID] = {Variable ID => 'Condition'}

  #

  #  'Variable ID' = Variable ID used. Numeric Value

  #   

  #  'Condition' = Condition needed to allow the skill usage, must be *always*

  #    an sting with an contional sign followed bya number.

  #    Ex.:

  #       '<= 20'   - This mean that the condition will be met if the variable

  #                   is lower or equal to 20.

  #

  #   ** See bellow an list of possible signs. **

  

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

  

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

  # Conditions by HP

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

  # Theses skills can be used only if the user HP met an certai condition

  #

  # Skill_Hp[Skill ID] = {'rate' => 'Condition'}

  # Skill_Hp[Skill ID] = {'integer' => 'Condition'}

  #

  #  'rate' => 'Condition'

  #    The comparison is made using the value as rate

  #     Ex.: 'rate' => '>= 50'

  #           This mean that the HP must be higher or equal to 50% of the max hp.

  #

  #  'integer' => 'Condition'

  #    The comparison is made using the integer value

  #     Ex.: 'integer' => '<= 150' 

  #           This mean that the SP must be lower or equal to 150.

  #   

  #  'Condition' = Condition needed to allow the skill usage, must be *always*

  #    an sting with an contional sign followed bya number.

  #    Ex.:

  #       '<= 20'   - This mean that the condition will be met if the variable

  #                   is lower or equal to 20.

  #

  #   ** See bellow an list of possible signs. **

  

  Skill_Hp[57] = {'rate' => '>= 50'} # This example, the skill 57 can be used

                                     # only if the hp is equal or higher than 50%

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

  

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

  # Conditions by SP

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

  # Theses skills can be used only if the user HP met an certai condition

  #

  # Skill_Hp[Skill ID] = {'rate' => 'Condition'}

  # Skill_Hp[Skill ID] = {'integer' => 'Condition'}

  #

  #  'rate' => 'Condition'

  #    The comparison is made using the value as rate

  #     Ex.: 'rate' => '>= 50'

  #           This mean that the SP must be higher or equal to 50% of the max hp.

  #

  #  'integer' => 'Condição'

  #    The comparison is made using the integer value

  #     Ex.: 'integer' => '<= 150' 

  #           This mean that the SP must be lower or equal to 150.

  #   

  #  'Condition' = Condition needed to allow the skill usage, must be *always*

  #    an sting with an contional sign followed bya number.

  #    Ex.:

  #       '<= 20'   - This mean that the condition will be met if the variable

  #                   is lower or equal to 20.

  #

  #   ** See bellow an list of possible signs. **

    

  Skill_Hp[8] = {'integer' => '< 400'} # This example, the skill 8 can be used

                                       # onlyg if the sp is lower than 400

  

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

 

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

  # SIGNS FOR CONDTIONS

  #  <   - Lower than

  #  >   - Higher than

  #  <=  - Lower or Equal

  #  >=  - Higher or Equal

  #  ==  - Equal

  #  !=  - Different

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

end

 

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

# ■ Atoa Module

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

$atoa_script = {} if $atoa_script.nil?

$atoa_script['Atoa Skill Condition'] = 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

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

  # Inclurir modulo de configuração

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

  include Atoa

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

  # Definir Habilidades Usáveis

  #     skill_id : ID da habilidade

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

  alias stat_skill_can_use skill_can_use?

  def skill_can_use?(skill_id)

    return false if Skill_State_On[skill_id] != nil and not skill_state_on(skill_id)

    return false if Skill_State_Off[skill_id] != nil and not skill_state_off(skill_id)

    return false if Skill_Sw_On[skill_id] != nil and not skill_sw_on(skill_id)

    return false if Skill_Sw_Off[skill_id] != nil and not skill_sw_off(skill_id)

    return false if Skill_Var[skill_id] != nil and not skill_var(skill_id)

    return false if Skill_Hp[skill_id] != nil and not skill_hp(skill_id)

    return false if Skill_Sp[skill_id] != nil and not skill_sp(skill_id)

    return stat_skill_can_use(skill_id)

  end

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

  # Verificação de condição de efeito ativo

  #     id : ID da Habilidade

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

  def skill_state_on(id)

    if Skill_State_On[id]['include'] != nil

      for i in Skill_State[id]['include']

        return true if @state.include?(i)

      end

    end

    if Skill_State[id]['set'] != nil

      for i in Skill_State[id]['set']

        return false unless @state.include?(i)

      end

      return true

    end

    return false

  end

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

  # Verificação de condição de efeito inativo

  #     id : ID da Habilidade

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

  def skill_state_off(id)

    if Skill_State_On[id]['include'] != nil

      for i in Skill_State[id]['include']

        return false if @state.include?(i)

      end

    end

    if Skill_State[id]['set'] != nil

      for i in Skill_State[id]['set']

        return true unless @state.include?(i)

      end

      return false

    end

    return true

  end

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

  # Verificação de condição de switch ativo

  #     id : ID da Habilidade

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

  def skill_sw_on(id)

    if Skill_Sw_On[id]['include'] != nil

      for i in Skill_Sw_On[id]['include']

        return true if $game_switches[i]

      end

    end

    if Skill_Sw_On[id]['set'] != nil

      for i in Skill_Sw_On[id]['set']

        return false unless $game_switches[i]

      end

      return true

    end

    return false    

  end 

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

  # Verificação de condição de switch inativo

  #     id : ID da Habilidade

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

  def skill_sw_off(id)

    if Skill_Sw_Off[id]['include'] != nil

      for i in Skill_Sw_Off[id]['include']

        return true if $game_switches[i] == false

      end

    end

    if Skill_Sw_Off[id]['set'] != nil

      for i in Skill_Sw_Off[id]['set']

        return false unless $game_switches[i] == false

      end

      return true

    end

    return false    

  end

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

  # Verificação de condição de variável

  #     id : ID da Habilidade

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

  def skill_var(id)

    for var in Skill_Var[id]

      return true if eval("$game_variables[#{var[0]}] #{var[1]}")

    end

    return false    

  end

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

  # Verificação de condição de HP

  #     id : ID da Habilidade

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

  def skill_hp(id)

    if Skill_Hp[id]['integer'] != nil

      return true if eval("self.hp #{Skill_Hp[id]['integer']}")

    end

    if Skill_Hp[id]['rate'] != nil

      return true if eval("(self.hp / self.maxhp * 100) #{Skill_Hp[id]['rate']}")

    end

    return false

  end

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

  # Verificação de condição de SP

  #     id : ID da Habilidade

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

  def skill_sp(id)

    if Skill_Sp[id]['integer'] != nil

      return true if eval("self.sp #{Skill_Sp[id]['integer']}")

    end

    if Skill_Sp[id]['rate'] != nil

      return true if eval("(self.sp / [self.maxsp, 1].max * 100) #{Skill_Sp[id]['rate']}")

    end

    return false    

  end

end
The instructions are on the Script header, if you have any problem just ask
 
Okay, there is actually an error when I try to run this script. This happens when I run the skills scene.

20tgg3o.png


Help please? :(
 

Atoa

Member

I forget to include the module on the Game Battler (i copied this one from my ACBS since i didn't find the non-ACBS one, and the ACBS already have the module included).

Just add it below the 'class Game_Battler':
include Atoa

Or copy the code again, i edited it xD
 
Re-EDIT:
Okay, so, it kind of works. When I use a skill to make my character's life go down, or an enemy attacks them, the ability activates instead of when the character's life is down below 50% or 30%...the skills are just usable. So, why is that? I can re-look at the algorithm used to check percentage, but this has not been working...it works just fine for the integers, but when it comes to percentage, it just doesn't work. :(
 
Here is what I did.

Skill_Hp[2] = {'rate' => '<= 50'}
Skill_Hp[5] = {'rate' => '<= 30'}


Skill_Hp[11] = {'rate' => '>= 80'}
Skill_Hp[12] = {'rate' => '== 100'}
Skill_Hp[13] = {'rate' => '<= 20'}
Skill_Hp[14] = {'rate' => '<= 20'}
 

Atoa

Member

Skill_Hp[2] = {'rate' => '<= 50'}
this skill will be able to be used if the HP is lower or equal to 50%, is that what you want?

The script set conditions to you use the skill, if the conditions aren't met the skill will be grayed out and can't be used.

I just tested it here, and worked fine.

Maybe another script is causing some incompatibility, try putting this script bellow all other scripts, just above main.
 
Yeah, I don't know what it is, because if the skill is
Skill_Hp[2] = {'rate' => '<= 50'}

then it only works if my life has been lost some way, then if the skill is
Skill_Hp[11] = {'rate' => '>= 80'}
then the skill will only work if my life is full...

I am not understanding why it is doing this to me. :( It makes me sad because I really need this for the character rotations in my game. :(
 

Atoa

Member

Yeah, I don't know what it is, because if the skill is
Skill_Hp[2] = {'rate' => '<= 50'}

then it only works if my life has been lost some way, then if the skill is
Skill_Hp[11] = {'rate' => '>= 80'}
then the skill will only work if my life is full...
But that is the way

Skill_Hp[2] = {'rate' => '<= 50'} means the skill will work only if you have less than 50%

Try it on an fresh demo and tell me the results.
 
Okay, I even tested it in a new demo, and even then, whenever the actor loses ANY HP at all, they can use the skills that require them to have less than even 20% life.

So, basically, this is what is happening with the skills.
Skill_Hp[2] = {'rate' => '<= 50'} = The actor may only use the skill if life has been lost.
Skill_Hp[11] = {'rate' => '>= 80'} = The actor may only use the skill if life hasn't been lost.

I know it has something to do with the way this is setup, but I don't understand what the last part does, because it works with the integer requirements, just not the percentages:
if Skill_Hp[id]['rate'] != nil
return true if eval("(self.hp / self.maxhp * 100) #{Skill_Hp[id]['rate']}")
end



And in this, it works:
if Skill_Hp[id]['integer'] != nil
return true if eval("self.hp #{Skill_Hp[id]['integer']}")
end


So...how come this isn't working? :(
 

Atoa

Member

I just tested it here on an fresh demo and works fine... are you sure you're puting the script on the right place? between Scene_Debug and Main.
post an screen of your script editor.
 
Lol, Atoa, I am not a newb at scripting or making games, I just think something I am using is not compatible with it...it's fine, I am just using the script to make it so skills either require full life, or some damage to use skills; I am sure it is conflicting with my breaking limits script, but it's fine, I will work with what I have because this still makes my skills work the way I want them to. :) Thank you, Atoa!
 

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