class Game_Party def member_level_avg members.compact.inject(1) { |r, i| r += i.level } / members.size end def add_soul_actor(actor_id,level=members_level_avg) add_actor(actor_id) level.times { members.last.level_up } endend
I'm pretty sure I've covered the accuracy of averaging in this very topic before... anyway, the method you're using to determine the average is inaccurate, as it deals entirely with integers which are automatically rounded to the lowest integer: if the result of the average is 5.9, it will return 5. Here:
class Game_Party def member_level_avg return nil if members.empty? (members.map(&:level).reduce

+) / members.size.to_f).round endendThis actually ensures that the average is treated as a floating point number and accurately rounds to the nearest integer. It also ensures that we won't encounter a ZeroDivisionError (or, in this method, FloatDomainError since we're casting members.size to a floating point number).It's also worth mentioning that the way the actor is being leveled will actually cause them to be a higher level than what I believe was intended (among other problems), seeing as they begin at their initial level and then increment that based on the party's average level. If you want the level of the actor to be
equal to the party's average, I'd recommend going about it in a different way. Actually, I'd handle the entire method differently:
class Game_Party def add_soul_actor(id, level = member_level_avg || 1) unless @actors.include?(id) add_actor(id) actor = members.last actor.change_exp(actor.exp_for_level(level), false) if actor.level > level actor.level_down until actor.level == level end actor.recover_all yield actor if block_given? actor end endendFirstly, your original method didn't handle trying to add an existing party member appropriately -- this one does, returning nil without any modifications to the party. Secondly, this method also ensures that the actor will level up or down appropriately (if, for instance, the actor that is added has a higher initial level than the party's average). Finally, it accurately modifies the actor's experience and initializes them with full health and mana (as is expected when a member is added to the party most of the time in my experience).
Note: leveling an actor down
does not modify their learned skills -- this is how it works in the default scripts, and honestly, isn't my problem.
On a slightly separate note, this method also actually returns the actor instance which was added to the party and yields the actor if a block is given, which is honestly much nicer than the idiotic true returned by the default Game_Party#add_actor. (Then again, a lot of the default RGSS3 return values are pretty stupid.)
Code:
# Optimize the added actor's equipment with the party's best inventory when the# actor is added via the `Game_Party#add_soul_actor` method with a block.$game_party.add_soul_actor(8) { |actor| actor.optimize_equipments }