[XP] Modified SP problem

Started by Kirye, November 28, 2012, 04:40:10 pm

Previous topic - Next topic

Kirye

I'm making a game using the DBS, with some modifications *None of which would affect what I need*. Basically, each character has 100 Max SP, and starts each battle with 20. In battle, SP is gained through regular attacks and defending. What i'm trying to figure out is how to make it so when you attack or defend, that specific actor gains SP.

For example, if Actor A attacks he gains 10 SP, while Actor B defended so he gains 20 SP.

I'm looking at the default battle scripts, but I can't find where i'd make that specific index actor gain SP, nor do I know which script command increases SP. I'd greatly appreciate help on this!

Spoiler: ShowHide

ThallionDarkshine

Check Game_Battler. There's a method called attack_effect. You can just check if the attacker is an actor with
VARIABLE_NAME.is_a?(Game_Actor)

If it is an actor, you can add sp through:
VARIABLE_NAME.sp += VALUE

Kirye

I don't wanna sound completely incompetent, but I have absolutely no idea what to do with that. >< I'm still learning.

Spoiler: ShowHide

ThallionDarkshine

November 28, 2012, 08:22:57 pm #3 Last Edit: December 14, 2012, 07:51:24 pm by KK20
Try this little script I wrote.


module SP_Gain_Config
  # the sp gains in percent by action id
  #   action_ids
  #     0 - Attack
  #     1 - Guard
  #     2 - Escape
  #     3 - Do Nothing
  #     4 - Use Skill
  #   ex. when any actor attacks, he/she will gain 10% of their sp
  #        and when any actor guards, he/she will gain 2% of their sp
  def self.sp_gain(action_id)
    case action_id
    when 0 then return 10
    when 1 then return 2
    else return 0
    end
  end
end

class Scene_Battle
  alias tdks_spg_make_basic_action_result make_basic_action_result
  def make_basic_action_result
    if @active_battler.is_a?(Game_Actor)
      sp_gain = SP_Gain_Config.sp_gain(@active_battler.current_action.basic)
      @active_battler.sp += @active_battler.maxsp * sp_gain / 100
    end
    tdks_spg_make_basic_action_result
  end
 
  alias tdks_spg_make_skill_action_result make_skill_action_result
  def make_skill_action_result
    if @active_battler.is_a?(Game_Actor)
      sp_gain = SP_Gain_Config.sp_gain(4)
      @active_battler.sp += @active_battler.maxsp * sp_gain / 100
    end
    tdks_spg_make_skill_action_result
  end
end

Kirye

Sorry for the late response, work's been hell.

The script crashes at line 12. D: Even if I don't modify anything. Thanks so much for taking the time to help me btw, I appreciate it!

Spoiler: ShowHide

Kirye

Quote from: KK20 on December 01, 2012, 01:22:43 am
lol you forgot the case TD
  def self.sp_gain(action_id)
    case action_id
    when 0 then return 10
    when 1 then return 2
    else return 0
  end



Still doesn't work, but now it has a syntax error at line 37 rather than 12. ._. Line 37 being the final line.

Spoiler: ShowHide

KK20

lol you forgot the case TD
  def self.sp_gain(action_id)
    case action_id
    when 0 then return 10
    when 1 then return 2
    else return 0
    end
  end


edit: whoops didn't see the missing 'end'.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Kirye

It works! It's allliiiiive!

Thanks so much, both of you. :D I sincerely appreciate it!

Just a heads up btw if you decide on putting this script in the database. The parts in the script that check max_sp are supposed to be maxsp, and also the skill part of the script clashes with Tons of Add ons. I only needed the basic action result section anyway, so it works out!

Spoiler: ShowHide

KK20

Just saw this too:
Quotealias tdks_spg_make_skill_action_result make_skill_action_result
  def make_basic_action_result #<- should be that  ^^^
    if @active_battler.is_a?(Game_Actor)
      sp_gain = SP_Gain_Config.sp_gain(4)
      @active_battler.sp += @active_battler.max_sp * sp_gain / 100
    end
    tdks_spg_make_skill_action_result
  end

Probably why it didn't work.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!