Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Kirye on November 28, 2012, 04:40:10 pm

Title: [XP] Modified SP problem
Post by: Kirye on November 28, 2012, 04:40:10 pm
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!
Title: Re: [XP] Modified SP problem
Post by: ThallionDarkshine on November 28, 2012, 05:21:52 pm
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
Title: Re: [XP] Modified SP problem
Post by: Kirye on November 28, 2012, 07:36:23 pm
I don't wanna sound completely incompetent, but I have absolutely no idea what to do with that. >< I'm still learning.
Title: Re: [XP] Modified SP problem
Post by: ThallionDarkshine on November 28, 2012, 08:22:57 pm
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
Title: Re: [XP] Modified SP problem
Post by: Kirye on December 01, 2012, 01:11:00 am
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!
Title: Re: [XP] Modified SP problem
Post by: Kirye on December 01, 2012, 01:31:10 am
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.
Title: Re: [XP] Modified SP problem
Post by: KK20 on December 01, 2012, 01:37:12 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
  end


edit: whoops didn't see the missing 'end'.
Title: Re: [XP] Modified SP problem
Post by: Kirye on December 01, 2012, 01:56:47 am
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!
Title: Re: [XP] Modified SP problem
Post by: KK20 on December 01, 2012, 11:28:11 pm
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.