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.

SP to Percent in battle

hi there
can someone do a quick script for me to show the SP cost as a percent while in battle.
i have my HP and SP as percents while in battle but when i go to use a skill it says the amount of SP it costs(example Fire I costs 100SP) if i had 100% SP and my 100% was really 1000SP i want the skill Fire I to say 10% instead of 100SP.

thanx
 
How I love you, search function. :)

This one's by SephirothSpawn

Code:
#==============================================================================
# ** Draw HP, SP & Exp With Percents By SephirothSpawn
#==============================================================================

#==============================================================================
# ** Window_Base
#==============================================================================

class Window_Base
  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw "HP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
    # Gets Percent
    p = Integer(actor.hp / actor.maxhp.to_f * 100)
    p = "#{p} %"
    # Draw HP
    self.contents.font.color = actor.hp == 0 ? knockout_color :
      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
    pw = self.contents.text_size(p).width
    self.contents.draw_text(x + width - pw, y, pw, 32, p, 2)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_sp(actor, x, y, width = 144)
    # Draw "SP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
    # Gets Percent
    p = Integer(actor.sp / actor.maxsp.to_f * 100)
    p = "#{p} %"
    # Draw SP
    self.contents.font.color = actor.sp == 0 ? knockout_color :
      actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    pw = self.contents.text_size(p).width
    self.contents.draw_text(x + width - pw, y, pw, 32, p, 2)
  end
  #--------------------------------------------------------------------------
  # * Draw EXP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_actor_exp(actor, x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 24, 32, "E")
    self.contents.font.color = normal_color
    s = "#{actor.next_exp_percent} %"
    self.contents.draw_text(x + 24, y, 180, 32, s)
  end
end

#==============================================================================
# ** Game_Actor
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Get Next Exp Percent
  #--------------------------------------------------------------------------
  def next_exp_percent
    lst = @exp_list[@level] > 0     ? @exp_list[@level]     : 0
    nxt = @exp_list[@level + 1] > 0 ? @exp_list[@level + 1] : 0
    rst = nxt - @exp
    begin
      return 100 - Integer( rst.to_f / (nxt - lst) * 100 )
    rescue
      return 100
    end
  end
end
 
xthexendxhasxcomex;259370 said:
thats still not what i want, it does the same thing as my script, it only makes the HP SP and EXP percents but it doesnt change the cost to percents.

Ah, I think I get it now; basically you want to restore that little feature in RM2K3 where you can set a spell to cost a certain % of MP?
 
Do you mean like this:

Let's say Arshes has 1000 MP in maximum (Lv 1). He has Fire 1 (150 MP) and Fire All (200 MP). In the skill selection window, Fire 1 will be 15% and Fire All will be 20% instead of being 150 and 200. When Arshes levels up (lv 2) so he has 2000 MP, Fire 1 is 7.5% and Fire All is 10%.

If that's the case, maybe I can help, but I must know what the skill selection window looks like (since you're using CBS, you might not use the standard skill selection window).

EDIT:
It just popped in my mind that I might not need to know your skill selection window. Here's the quick fix:

1. Find your Window_Skill class, method draw_item(item).
2. Find this line:
Code:
self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
and replace it with these:
Code:
    sp_percent = (skill.sp_cost.to_f / @actor.maxsp.to_f * 100.0).round.to_s + "%"
    self.contents.draw_text(x + 232, y, 48, 32, sp_percent, 2)

Note that skill values in menu will also change to percent. If this is not what you want, let me know.

Anyway, if the values are inaccurate, you might want to replace round by:
ceil to round up, regardless the decimal point (0.1 will be rounded up to 1)
floor to round down, regardless the decimal point (0.6 will be rounded down to 0)
truncate to discard the decimal points (all 0.1, 0.12, 0.6 will result to 0)
If you need to be exact in X decimal points, let me know
 
Oh god thank you!!

it works!!

finally someone did it

can you make it work with this
Code:
class Window_Skill < Window_Selectable
  alias xrxs_mp18_draw_item draw_item
  def draw_item(index)
    xrxs_mp18_draw_item(index)
    skill = @data[index]
    if skill.sp_cost == 0
      h = ((defined? line_height) ? self.line_height : 32)
      x = 4 + index % @column_max * (288 + 32)
      y = index / @column_max * h
      rect = Rect.new(x + 264, y, 16, h)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    end
  end
end

it makes it so if the cost of the skill is 0 then it just wont show the zero.
here is what it should look like.. but when it added that percent part it didnt work anymore, here's a screenshot.

thanx
 
To tell you the truth, I was really confused about your problem. Programmatically, my fix is correct: when a skill has 0 SP, it will still count and display 0%. I tried it on a fresh project and it worked.

Until I installed your script... yes, the % was missing! But what shocked me till I laughed at myself was the fact that the script actually worked by covering the text "0%" with a rectangle! It wasn't big enough, though, so it only covered up the %, not the 0.

OK, to make it works so your player won't see 0% or just 0, do this:

From your script, find this line:
Code:
rect = Rect.new(x + 264, y, 16, h)
and replace it with this one:
Code:
rect = Rect.new(x + 248, y, 32, h)
See the difference? If by a chance (since you use a different font) it's still showing some part of our unwanted 0, decrease 248 and increase 32 a little bit until you get satisfactory result.

Hope that helps ;)
 

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