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.

New Character has same level as party

Not quite sure if a script is neccesary for this or not. What I'm looking for is a script for when a new member joins that they r at the same level as the majority of the party. I say this because I do not want to make a game where someone is forced to train a character from level 1 to 34 so that they can be up to the level with the party.
 
Set hero's lv in database to 1. Set variables for each party member's level. Divide by amount of party members. (Note: This is optional; you might as well just do one variable for one member's level). Do this final variable -1, make the new character join and set the level + the variable.
 
You should learn how to use variables, they're very helpful. Tons of tutorials on lots of sites like this too, so you have no excuse not to learn. Anyway, what you need to do is assign a variable to do this.

To do this, go to "control variable" and pick one of the numbers. Name it something like "level setter." Now, the first time a character joins the party, you'll have to do the following:

Call this variable in control variables. When you go to control variables, you'll get a window that asks you to fill out 3 different things: Variable, Operation, and Operand.
Under variable, pick your variable that you named.
Under operation, select "+" (the addition sign)
And under operand, select "actor" then select one of the characters in the party in the drop down box, then select "EXP."

Keep on doing this for every character in the party at that time.
After all this, go to "control variable" again, but this time set the operation to "/" (division) and under operand select "constant" and set the number in that box to the amount of characters that are in the party at that moment. This is basic averaging.

Next, go to control variable yet again, but this time set operation to "-" (subtraction) and set the operand to 1. This will take that variable and -1 from the number you get after doing all this algebra. Next, have the character join the party, and increase his EXP by the variable (this is simply done by selecting the operand and making it the variable that you've been working with all this time).

And that's it. Of course, this version actually takes an average of EXP from all the characters. It'll do the same, but if you want the new character to start at a slight disadvantage, just make it so that when you select EXP on the first step, make it level.

Now go learn variables ^_^
 
Thank you very much everyone Kain I'm jsut confused about one thing. where do I put the scripts???I have never added one. U just make a new one and copy and paste the writing????
 
Anytime you have a custom script, you paste it below "Scene_Debug" and "main" in the script editor list. Here, I've revised this and made an actual scriptlet for it, so let me post that for ya...

Code:
#===============================================================================

# ** Actor : Average Level Join

#===============================================================================

 

if Object.const_defined?(:SDK)

  SDK.log("Actors.StatAveraging", "Kain Nobel", 0, "04.05.2009")

end

 

#===============================================================================

# ** Game_Actor

#===============================================================================

 

class Game_Actor < Game_Battler

  #-----------------------------------------------------------------------------

  # * Level Up

  #-----------------------------------------------------------------------------

  unless self.method_defined?(:level_up)

    def level_up

      @level += 1

      for j in $data_classes[@class_id].learnings

        if j.level == @level

          learn_skill(j.skill_id)

        end

      end

    end

  end

  #-----------------------------------------------------------------------------

  # * Level Down

  #-----------------------------------------------------------------------------

  unless self.method_defined?(:level_down)

    def level_down

      @level -= 1

    end

  end

end

 

#===============================================================================

# ** Game_Actors

#===============================================================================

 

class Game_Actors

  #-----------------------------------------------------------------------------

  # * Name      : Average

  #   Info      : Returns average of all actors' stats, based on parameter

  #   Author    : Kain Nobel

  #   Call Info : Parameter is a string representing parameter in question

  #-----------------------------------------------------------------------------

  def average(stat)

    avg = 0

    for i in 1...$data_actors.size

      case stat

      when 'hp'     ; avg += self[i].hp

      when 'maxhp'  ; avg += self[i].maxhp

      when 'sp'     ; avg += self[i].sp

      when 'maxsp'  ; avg += self[i].maxsp

      when 'level'  ; avg += self[i].level

      when 'exp'    ; avg += self[i].exp

      when 'str'    ; avg += self[i].str

      when 'dex'    ; avg += self[i].dex

      when 'agi'    ; avg += self[i].agi

      when 'int'    ; avg += self[i].int

      when 'atk'    ; avg += self[i].atk

      when 'pdef'   ; avg += self[i].pdef

      when 'mdef'   ; avg += self[i].mdef

      when 'eva'    ; avg += self[i].eva

      end

    end

    return (avg / $data_actors.size - 1)

  end

end

 

#===============================================================================

# ** Game_Party

#===============================================================================

 

class Game_Party

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_accessor :gold # This is set so you can do $game_party.gold = n

  #-----------------------------------------------------------------------------

  # * Name      : Average

  #   Info      : Returns average of party's stats, based on parameter

  #   Author    : Kain Nobel

  #   Call Info : Parameter is a string representing parameter in question

 #-----------------------------------------------------------------------------

  def average(stat)

    return 0 if @actors.size == 0

    avg = 0

    case stat

    when 'hp'    ; @actors.each_index {|i| avg += @actors[i].hp}

    when 'maxhp' ; @actors.each_index {|i| avg += @actors[i].maxhp}

    when 'sp'    ; @actors.each_index {|i| avg += @actors[i].sp}

    when 'maxsp' ; @actors.each_index {|i| avg += @actors[i].maxsp}

    when 'level' ; @actors.each_index {|i| avg += @actors[i].level}

    when 'exp'   ; @actors.each_index {|i| avg += @actors[i].exp}

    when 'str'   ; @actors.each_index {|i| avg += @actors[i].str}

    when 'dex'   ; @actors.each_index {|i| avg += @actors[i].dex}

    when 'agi'   ; @actors.each_index {|i| avg += @actors[i].agi}

    when 'int'   ; @actors.each_index {|i| avg += @actors[i].int}

    when 'atk'   ; @actors.each_index {|i| avg += @actors[i].atk}

    when 'pdef'  ; @actors.each_index {|i| avg += @actors[i].pdef}

    when 'mdef'  ; @actors.each_index {|i| avg += @actors[i].mdef}

    when 'eva'   ; @actors.each_index {|i| avg += @actors[i].eva}

    end

    return (avg / @actors.size)

  end

end

 

#===============================================================================

# ** Interpreter

#===============================================================================

 

class Interpreter

  #-----------------------------------------------------------------------------

  # * Set Actor Average

  #-----------------------------------------------------------------------------

  def actor_average(id, stat, percent = nil, local = nil)

    temp = percent

    unless percent.kind_of?(Numeric)

      percent = local.kind_of?(Numeric) ? local : 100

    end

    unless local.is_a?(TrueClass) || local.is_a?(FalseClass)

      local = (temp == true || temp == false) ? temp : true

    end

    actor = $game_actors[id]

    value = (local ? $game_party.average(stat) : $game_actors.average(stat))

    value *= percent / 100.0

    value = Integer(value)

    case stat

    when 'hp'     then actor.hp    = value

    when 'maxhp'  then actor.maxhp = value

    when 'sp'     then actor.sp    = value

    when 'maxsp'  then actor.maxsp = value

    when 'level'

      begin

        actor.level_down if actor.level > value

        actor.level_up   if actor.level < value

      end until actor.level == [[value, 1].max, 99].min

    when 'exp'    then actor.exp  = value

    when 'str'    then actor.str  = value

    when 'dex'    then actor.dex  = value

    when 'agi'    then actor.agi  = value

    when 'int'    then actor.int  = value

    end

  end

end

 

...Okay, now basically you'll have the freedom of making a simple call script to set any stat on any actor to an average stat with an optional modifier. All of this is done though call scripts.

Okay, go ahead and make an event and open up the commands list and go to Call Script command (last command on last page). Now, we'll take your 2nd actor and lets say you want ALL of his/her stats to be the base average of the current party's stats. You'll put this in your call script box

Code:
actor_average(2, 'hp')

actor_average(2, 'maxhp')

actor_average(2, 'sp')

actor_average(2, 'maxsp')

actor_average(2, 'str')

actor_average(2, 'dex')

actor_average(2, 'agi')

actor_average(2, 'int')

The first argument represents the actor's ID, the second argument is the stat that you want to average so if you wanted to average an actors Strength you'd do (2, 'str')

Please keep in mind, this won't do anything with .atk, .pdef, .mdef or .eva because those are equipment stats, they can't be directly modified in an actor unless you've got another script for that.

In the first example, you can see the basic syntax is simple and if you read the example you'll know that argument 1 is actor's ID and argument 2 is the stat (in 'string' form). Now, the 3rd argument is percent, how much percent do you want the stat to be raised/lowered? By default, this is always 100 so if you'd want Basil to join with a little bit more HP than most you'd do...

Code:
actor_average(2, 'maxhp', 125)

...meaning Basil now has 25% more HP than his average peers, or...

Code:
actor_average(2, 'maxhp', 50)

...meaning Basil now has 50% less HP than his average peers.

Lastly, there is an optional FOURTH argument you can use with this and you're probably wondering what it means. By default, when you call the command it'll average the stat of just the actors in the party because it is set to false (by default.) When you set it to true then it is going to set the average stat compared to every actor in your database and not just the members of your party.

Code:
actor_average(2, 'maxhp', 125, true)

The first two arguments are standard and must always be called, like...

Code:
actor_average(id, stat)

The third and fourth arguments are interchangeable and optional, one must always be a true/false and the other must always be a number, so long as one or the other is called it'll know what to do with them and switch them. So in other words, you can call it like so...

Code:
actor_average(id, stat, percent)

actor_average(id, stat, local)

actor_average(id, stat, percent, local)

actor_average(id, stat, local, percent)

Hope I've helped ya some. Basically with this system, to do what you want to do, you simply use the Add Party Member command, then you use the call script like I showed you in the many descriptive examples above and it'll set the averages individually how you want them, this has gotta be the easiest way in the world to do what you're wanting to do.

Enjoy :thumb:
 

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