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.

vx rpg::skill question

so what i am doing is trying to make it so if a skill has the darkness element it will subtract 10% of your current hp(when you cast that spell) here is what i have so far based on what i know about xp. i am currently getting a error on line 7, i dont want you to write the code for me i am trying to learn how to mod battle stuff myself; but i would really appreciate if you could point me in the right direction about what i need to do to get there
Code:
module Darkness

  ELEMENT = 16

end

 

class RPG::Skill

  alias Darkness_Skill

if $data_skills[@id].element_set.include?(Darkness::ELEMENT)

 

      return 

    end

end

oh ya, p.s. im new to vx just got it 3 days ago
 
RPG::Skill < RPG::UsableItem < RPG::BaseItem

In RPG::Usableitem is the element_set instance.

So:
Code:
class RPG::Skill

  def darkness_skill

    return @element_set.include?(Darkness::ELEMENT)

  end

end

So now to check if skill is a darkness skill, you check with
$data_skills[skill_id].darkness_skill

I do however don't suggest going about it this way. I instead suggest adding a hp_cost method. This way you can customize what hp cost the skill uses vs. a constant definition. This also allows you to get rid of the element set tag element as well. Something like this:
Code:
class RPG::Skill

  HP_Cost = {}

  HP_Cost.default = 0

  def hp_cost

    return HP_Cost[@id]

  end

end

Now its just a matter of checking the skill_can_use? method and the skill_effect method. Let me know if you need help with this too.
 
EDIT: Woops, Seph beat me on that one!

First of all, you don't need to modify the RPG::Skill class to do that.
Your module is ok, but your class isn't.

In your alias, you only mention the new method name and forgot the original method name.
The syntax for aliasing a method is as follow:
alias new_method_name original_method_name

It brings me to my first question, which method are you trying to alias? The only method in RPG::Skill (unless you added one your self) is initialize.

Second thing, you have an if statement directly under the class definition. normally, especially in your case, if statements should go under a method definition.
Just like that:
Code:
 

class My_Class

  

  def my_method

  

    if something

      # your code here

    end

  

  end

 

end

 
Is some cases, you can use if statements outside of methods but it's not common.

Now here's my suggestion. Forget about the RPG::Class. Instead, put your condition in Scene_Battle, under the execute_action_skill method. Take a look at the original method before modding it. You'll find all the variables you need to do what you want. You can add your element condition in there.

Hope it helps!
-Dargor
 
@seph(my hero) thanks that helps alot! and yes i would like help with that too, ive written plenty of other code before but ive allways avoided the battle system so i know knowthing about it at this minute.

@dargor: you have been helping me alot recently i think i might need to add you to my hero list :) but anyways about alais i didnt mean to put that there i dont even know how to use them to be honnest, ive allways been a bad coder, but since i am in collage now(navy in may) i am trying to learn how to do advanced stuff as fast as possible

thanks both of you guys
 
Ok. Checking if they can use a skill based off the hp_damage.

In Game_Battler, they use this method to check if you can use a skill:
Code:
  #--------------------------------------------------------------------------

  # * Determine Usable Skills

  #     skill : skill

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

  def skill_can_use?(skill)

    return false unless skill.is_a?(RPG::Skill)

    return false unless movable?

    return false if silent? and skill.spi_f > 0

    return false if calc_mp_cost(skill) > mp

    if $game_temp.in_battle

      return skill.battle_ok?

    else

      return skill.menu_ok?

    end

  end

 

So we just need to add a check for hp_cost as well.
Code:
class Game_Battler

  alias_method :seph_skillhpcost_gmbtlr_scu?, :skill_can_use?

  def skill_can_use?(skill)

    # Return false if original test fails

    return false unless seph_skillhpcost_gmbtlr_scu?(skill)

    # Get hp_cost

    hp_cost = skill.hp_cost

    # If non-zero hp_cost

    if hp_cost != 0

      # Get percent to take

      damage = Integer(maxhp * hp_cost / 100.0)

      # Return false if damage > @hp

      return false if damage > @hp

    end

    return true

  end

end

Now, just need to apply the hp damage when a skill is used. In Game_Battler, skill_effect is the method to handle all this:
Code:
  #--------------------------------------------------------------------------

  # * Apply Skill Effects

  #     user  : Skill user

  #     skill : skill

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

  def skill_effect(user, skill)

    clear_action_results

    unless skill_effective?(user, skill)

      @skipped = true

      return

    end

    if rand(100) >= calc_hit(user, skill)         # determine hit ratio

      @missed = true

      return

    end

    if rand(100) < calc_eva(user, skill)          # determine evasion rate

      @evaded = true

      return

    end

    make_obj_damage_value(user, skill)            # calculate damage

    make_obj_absorb_effect(user, skill)           # calculate absorption effect

    execute_damage(user)                          # damage reflection

    if skill.physical_attack and @hp_damage == 0  # physical no damage?

      return                                    

    end

    apply_state_changes(skill)                    # state change

  end

 

Once again, just alias the method, check if skill was used (@skipped == false) and apply hp_cost to the user.
Code:
class Game_Battler

  alias_method :seph_skillhpcost_gmbtlr_se, :skill_effect

  def skill_effect(user, skill)

    # Original skill effect

    seph_skillhpcost_gmbtlr_se(user, skill)

    # If skill was used

    unless @skipped

      # Get hp_cost

      hp_cost = skill.hp_cost

      # If non-zero hp_cost

      if hp_cost != 0

        # Get percent to take

        damage = Integer(user.maxhp * hp_cost / 100.0)

        # Subtract users hp

        user.hp -= damage

      end

    end

  end

end

That should be about all there is to it.
 

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