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.

[Battle] HP

Hey. I'm looking for a script that alters the way you lose SP and HP. Basically, what would happen is all skills would have one of two elements attached to one of them. When, say, ElementA is attached to a skill then instead of losing SP you lose the same amount of HP as is in the SP COST form. When ElementB is attached to a skill, then instead of losing HP you lose MaxHP. So when you use skills you either lose HP which can be replenished or the maximum HP you can get to is lowered.

If it wouldn't put you out too much, would you also be able to tell me how I can alter the menu/ battle system so it only shows HP and gets rid of SP, so I don't have any useless stuff on the display... I can't really do anything to repay you, apart from, obviously, credits, and I could provide story criticism or something, if it would help. If anyone could do this I'd be really grateful =]
 
Okay, first to get rid of all the actors sp drawn of different places in the game, we have to remove some lines. (from three different scripts i think)
First go to Window_MenuStatus and remove line 35: draw_actor_sp(actor, x + 236, y + 64)
Then go to Window_Status and remove line 29: draw_actor_sp(@actor, 96, 144, 172)
The go to Window_BattleStatus and remove line 41 : draw_actor_sp(actor, actor_x, 64, 120)

Then when you've done that, put this script in an empty section above main:
Code:
#==============================================================================
# ** Scene_Battle (part 4)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

Element_HP = 1
Element_MaxpHP = 2

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Get Maximum HP
  #--------------------------------------------------------------------------
  def maxhp
    n = [[base_maxhp + @maxhp_plus, 1].max, 9999].min
    for i in @states
      n *= $data_states[i].maxhp_rate / 100.0
    end
    n = [[Integer(n), 1].max, 9999].min
    return n
  end
  #--------------------------------------------------------------------------
  # * Get Basic Maximum HP
  #--------------------------------------------------------------------------
  def base_maxhp
    return $data_actors[@actor_id].parameters[0, @level]
  end
  #--------------------------------------------------------------------------
  # * Make Skill Action Results
  #--------------------------------------------------------------------------
  def make_skill_action_result
    # Get skill
    @skill = $data_skills[@active_battler.current_action.skill_id]
    # If not a forcing action
    unless @active_battler.current_action.forcing
      # If unable to use due to SP running out
      unless @active_battler.skill_can_use?(@skill.id)
        # Clear battler being forced into action
        $game_temp.forcing_battler = nil
        # Shift to step 1
        @phase4_step = 1
        return
      end
    end
    if @skill.element_set.include?(Element_HP)
      # Use up HP
      @active_battler.hp -= @skill.sp_cost
      @active_battler.damage = @skill.sp_cost
      @active_battler.damage_pop = true
    elsif @skill.element_set.include?(Element_MaxpHP)
      # Use up Max_HP
      @active_battler.maxhp -= @skill.sp_cost
      @active_battler.damage = @skill.sp_cost
      @active_battler.damage_pop = true
    end
    # Refresh status window
    @status_window.refresh
    # Show skill name on help window
    @help_window.set_text(@skill.name, 1)
    # Set animation ID
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    # Set command event ID
    @common_event_id = @skill.common_event_id
    # Set target battlers
    set_target_battlers(@skill.scope)
    # Apply skill effect
    for target in @target_battlers
      target.skill_effect(@active_battler, @skill)
    end
  end
end

And replace the numbers in "Element_HP" and "Element_MaxpHP" with the elements you wish to have. By default,
Element_HP = 1
Element_MaxpHP = 2

It means that if a skill has the fire elemental(1), it will loose the sp cost in hp instead,
And if a skill has the Ice elemental(2), the actor will loose the sp cost in max hp.

Alhough you can still have skills that does not have these elements but those skills won't cost either sp or hp.
So remember to set the element of the skills.
I think that this is what you asked for. If not, tell me and i'll change it! :thumb:

Over and out - Gando
 

poccil

Sponsor

[ I didn't make it in time, but the post above does explain how the menu code can be rewritten. ]

In lines 175-177 of the script section Game_Battler 3, add the lines in bold:

# Replace MAXHP_ELEMENT with the element ID for max HP
  if skill.element_set.include?(MAXHP_ELEMENT)
      # Subtract damage from MaxHP
      last_hp = self.maxhp
      self.maxhp -= self.damage
      effective |= self.maxhp != last_hp
  else

      # Subtract damage from HP
      last_hp = self.hp
      self.hp -= self.damage
      effective |= self.hp != last_hp
  end

In lines 14-17 of the script section Game_Battler 3, replace those lines with the following:

Code:
    # Replace SPCOST_ELEMENT with the element ID for SP cost
    compareSP = (skill.element_set.include?(SPCOST_ELEMENT)) ? self.sp : self.hp
    # If there's not enough SP, the skill cannot be used.
    if $data_skills[skill_id].sp_cost > compareSP
      return false
    end

Replace line 341 of the script section Scene_Battle 4 (which reads: "@active_battler.sp -= @skill.sp_cost") with the following:

Code:
    # Replace SPCOST_ELEMENT with the element ID for SP cost
    if skill.element_set.include?(SPCOST_ELEMENT)
        @active_battler.hp -= @skill.sp_cost
    else
        @active_battler.sp -= @skill.sp_cost
    end

I hope this helps.
 
Using Gandos method, in a new project, the system works perfectly - thanks!
However, and I should have mentioned this in the beginning post, I am using the Wild Arms Hex battle system, and when it comes to using the actual skill (i.e. I've positioned the cursor over an enemy and pressed ENTER) it comes up with

http://img81.imageshack.us/img81/8906/errorhpxe8.png[/img]

Which is
Code:
    set_target_battlers(@skill.scope)

I'm going to try poccils method to see if it avoids this problem and I'll get back to you. This is really helpful, thanks =]

EDIT:

When I tried poccils method, when I tried pressing the SKILL button it came up with

http://img79.imageshack.us/img79/7678/errorhp2wo6.png[/img]

EDIT: This occurs also when the battle system is not on place...

Sorry to be such a pain about all this guys =] would you like me to put up the battle system I'm using?
 
Okaay, i'm not sure if this will work. I havn't tried it since the battlesystem needed a lot of graphics that i don't have but you can try this and tell me if it works or not. Remove the old script that i gave you, and replace your battle script with this:

Edit: Code to long, ill upload the script data..

Edit2: Here it is: http://www.box.net/shared/yjbujjjsww
I just relised that i commented out some of the scripts, so just copy over the battle script to you project.
Go to lines 75-76 to edit the Element_HP and Element_MaxHP.
 
Okay, it's not that hard really.
Let's take the regular Scene_Battle, just for the sake of it being less code and easier to read.
In the method make_skill_action_result is the setup for some things that happens when you use a skill.
And if you look at line 341: @active_battler.sp -= @skill.sp_cost
@active_battler simply means the person using the skill, the person that is "active".  And the ".sp" is the sp, so what And the @skill.sp_cost is the sp cost of the skill that is being used. So what line 341 does is that it gets the active battlers current sp and decrease it by the skills sp cost.
But since we didn't want to use sp, but hp instead we needed to get the active battlers hp instead of the sp. so that means that we need to add ".hp" instead of ".sp": @active_battler.hp -= @skill.sp_cost

To check if something has a certain element, you use this line: .element_set.include?(id)
And since we needed to check if the skill being used had that certain id we used an if statement:
if @skill.element_set.include?(Hex::Element_HP)

And the Hex::Element_HP gets the value/id stored in the "Element_HP" inside the module "Hex".

These lines are the lines that will display the damage dealt whenever a person uses a skill:
@active_battler.damage = @skill.sp_cost
@active_battler.damage_pop = true

And pretty much the same thing goes for the max_hp stuff. And that leaves it to instead of line 341 in Scene_Battle4.
We replace that line with this:
Code:
      if @skill.element_set.include?(Hex::Element_HP)                #checks if the skill has the element id stored in Element_HP

        # If the skill has that certain element, everything below happens until it comes to the elsif statement.

        @active_battler.hp -= @skill.sp_cost                   #Removes hp equal to the skills sp_cost
        @active_battler.damage = @skill.sp_cost              # Sets the damage popup to the skills sp_cost
        @active_battler.damage_pop = true                     # true means that it will display the damage.

      #if the skill doesn't have that element it checks if the skill has the element id stored in Element_MaxHP
      elsif @skill.element_set.include?(Hex::Element_MaxHP)

        # If the skill has that certain element, everything below happens.

        @active_battler.maxhp -= @skill.sp_cost               #decreases the max_hp equal to the skills sp_cost
        @active_battler.damage = @skill.sp_cost               # Sets the damage popup to the skills sp_cost
        @active_battler.damage_pop = true                      # true means that it will display the damage.
      end

I hope i didn't confuse you too much. If you have any further questions don't hesitate to ask. :thumb:

Over and out - Gando
 

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