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.

Average Level

Is there a script that can determine the level of all Party Members? In my game, it is played through several different view points. You start off with one character, then a different one later on. The first character is no longer present. I'd like to make it so that when the game switches to a different view point, the next character is at the same level of experience. And then, to make matters even more difficult, when the first character joins the second, or a new character joins in, they are all at the same level or close to.
 
Thanks, but for some reason, I can't get it to work. I tried placing it in Game_Party, and I tried placing it underneath every other script. Then I tried using '$game_party.average_level' as a call script when you press enter on an object.
 

Mac

Member

Add this:-

Code:
class Game_Party
  def average_level
	n = 0
	@actors.each {|a| n += a.level}
	n /= @actors.size
	return n
  end
end

Just under this part in game party

Code:
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold 
#  and items. Refer to "$game_party" for the instance of this class.
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :actors                   # actors
  attr_reader   :gold                     # amount of gold
  attr_reader   :steps                    # number of steps
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Create actor array
    @actors = []
    # Initialize amount of gold and steps
    @gold = 0
    @steps = 0
    # Create amount in possession hash for items, weapons, and armor
    @items = {}
    @weapons = {}
    @armors = {}
  end

And hopefully it shall work!
 
Okay, well, still doesn't work. I think I might know why, though. I'm using a Change Party script that was originally posted on Phlomortis(I think that's the spelling). The RGSS Section thing, anyway. Someone had modified it as a Party Changer, Leader Select, and so forth. I just have to figure out where to place the new code.
 

Kio

Member

if you put in inside Game_Party, be sure to remove "class Game_Party" and the last end from sephirothspawn's script.

Also, another way of doing it is as follows:

total_lvl = 0
for i in 0...$game_party.actors.size
total_lvl += $game_party.actors.level
end
average_lvl = total_lvl / $game_party.actors.size
 

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