When a battler executes an action, following steps are taken:
The attackers
use_item method is called once, passing the skill/item used.
The targets
item_apply method is called, passing the attacker and the skill/item used. This method is called once for every target and every repeat of the action item.
If you wanted to grant a fixed amount of experience for every use of a specific action I would have recommended to extend
use_item, since it is called once regardless of the number of targets
(even if there is no target at all).
If you want to reward every hit regarding on its result, I'd stick with
item_apply instead
:
class Game_Battler alias_method
🙂item_apply_with_skill_points, :item_apply) def item_apply(user, item) item_apply_with_skill_points(user, item) # Here goes skill point calculation and distribution endendStill to do:
- You probably want to check if the user is actually your actor and not an enemy attacking you.
- You probably want to check which skill/item is being used to determine the amount of experience. It could be any item with a scope other than "None", including "Defense", a (healing) spell or a potion.
- You have to determine which weapon type is currently being used by the actor. You might have to consider an actor can carry up to two weapons by default.
- Grant the experience.
A modification of Shaz' solution
(not perfect, but it is almost 5 am... ^^):
Spoiler
Code:
class RPG::Weapons < RPG::EquipItem def is_melee? @note =~ /<Weapon Class: Melee>/i end def is_ranged? @note =~ /<Weapon Class: Ranged>/i end def is_improvised? @note =~ /<Weapon Class: Improvised>/i endendclass Game_Battler alias_method(:item_apply_with_skill_points, :item_apply) def item_apply(user, item) item_apply_with_skill_points(user, item) user.add_skill_points # <- Grant the User Skill Points end def add_skill_points if actor? # <- Attacker must be an actor to achieve Skill Points. weapon_set = weapons.compact # <- List of all equipped weapons. $game_variables[15] += 1 if weapon_set.any? { |w| w.is_melee? } $game_variables[16] += 1 if weapon_set.any? { |w| w.is_ranged? } $game_variables[17] += 1 if weapon_set.any? { |w| w.is_improvised? } end endend
This solution uses variable 15-17 from the "event" variable set, since that saves the trouble keeping them synchronized with the savestate. However, for more flexibility I'd recomment using instance variables instead, which are unique for every actor.