New Actor Level = Party Average Level

Status
Not open for further replies.

Yawgmoth

Veteran
Veteran
Joined
Jan 9, 2018
Messages
138
Reaction score
11
First Language
English
Primarily Uses
RMMV
Hi all,

I would like to know how to event a new actor's level to be equal to the average level of the party. Reserve members not included. I'm assuming I need to use variables which I have just started diving into so I don't have much experience with them. I'm sure this can be done lots of different ways but I would prefer to learn the proper way to event this so next time I would hopefully not have to ask for help. I would rather not copy and paste someone's script.

Thanks in advance for any and all help.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,608
Reaction score
4,616
First Language
English
Primarily Uses
RMMV
You can calculate the average party level, store the value in a variable, and then set the level of the new actor to the value of that variable. For example, if I use variable #5:

Code:
var totalLevel = 0;
for (var i = 0 ; i < $gameParty.members().length; i++) {
   var ac = $gameParty.members()[i];
   totalLevel += ac.level;
}
var averageLevel = Math.round(totalLevel / $gameParty.members().length);
$gameVariables.setValue(5, averageLevel);
1) Insert that code as a script BEFORE adding the new actor to the party.
2) Add the new actor to the party.
3) Set the new actor's level to the value of variable 5. If you want to change the variable ID, change the number 5 to the desired variable ID in the last line of the code.

Note that I did not test the code and I hope that it's bug free lol.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,077
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
@Yawgmoth 's Bargain was to get an answer on eventing this.

"I would like to know how to event a new actor's level..."


So here I go:


How to fetch the level data to a variable?
Solution:
Game Progression > Control Variables > Game Data > Actior > HeroNameHERE > Level

So you can set a variable with A specific actor's level.
Thus you can use a variable for each actor to fetch the data.

The problem is, who of the actors is in your party and who is not.
Solution:

Create a variable named LVLSUM
Set it to 0
Create a Condiotional Branch
Second Tab gives you the option to choose if a specific actor is in the party.
IF he is, then add to LVLSUM the fetched data for that hero.

Create also a variable for the Sum of actors.
Set it to 0
For each actor in the respective conditional branch, if he /she is in the party, add +1


So SUM of LVL/ SUM of actors = the average level.
and you set the new level.

Just remember to always initialize to 0 all the involved variables.

You're welcome.
 

Yawgmoth

Veteran
Veteran
Joined
Jan 9, 2018
Messages
138
Reaction score
11
First Language
English
Primarily Uses
RMMV
Thank you both so much! Now I have an example of two ways to go about doing this. I did get this to work too so thank you both for your time. and Happy RPG Making to you both!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,617
Reaction score
5,157
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Job concerns. Love where I work, but I have severe anxiety while I'm outside at night.
It's nice to see the evolution of my game: Here is a video with the first WIP:
Sparky89 wrote on ShadowHawkDragon's profile.
Your Art and work look incredible! Thankyou!

Forum statistics

Threads
104,377
Messages
1,005,964
Members
135,904
Latest member
Luchalu97
Top