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.

Cutting SP Use Pending on HP Percentage

rexkim

Member

Is there a script to cut the use of SP in skills and the like pending on the actor's current hp?

Like...

If HP is 100%, SP use is 100%.
If HP is 10%, SP use is 50%.

Something like that.

Or even better, have a state that cuts the cost of SP usage. Thanks.
 

poccil

Sponsor

The following helping function determines the SP cost of a skill using state number 10.  It should
be placed in a new script section.

Code:
class Game_Battler
 def sp_cost(skill)
  cost=skill.sp_cost
  if self.state?(10) # assuming state 10
   cost-=Integer(cost*0.4*self.hp/self.maxhp)
  end
  return cost
 end
end

The scripts can then be modified thus:

Lines 15-17 of script section Game_Battler 3:

Code:
    if self.sp_cost($data_skills[skill_id]) > self.sp
      return false
    end

Lines 340-341 of script section Scene_Battle 4:

Code:
    # Use up SP
    @active_battler.sp -= @active_battler.sp_cost(@skill)

Line 75 of script section Window_Skill:

Code:
    self.contents.draw_text(x + 232, y, 4, 32, @actor.sp_cost(skill).to_s, 2)
 

rexkim

Member

Hmm thanks. It works but it doesn't work well for me. =/

Instead of dropping, it seems to drop, pop back up again, etc.

For example, my health was continuously dropping. Base SP cost was 10. After losing a bit of health, the cost dropped to 9. Then 8. All of a sudden, it went back to 10 the next turn when I had half or so health. =/
 

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