New Actor Level = Party Average Level

Status
Not open for further replies.

Yawgmoth

Veteran
Veteran
Joined
Jan 9, 2018
Messages
114
Reaction score
10
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
Moderator
Joined
Nov 18, 2015
Messages
1,975
Reaction score
3,418
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.
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,850
Reaction score
2,509
First Language
Greek
Primarily Uses
RMMV
@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
114
Reaction score
10
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
5,892
Reaction score
4,217
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

Quon is watching you
Quon blessed your good efforts
I have tried, several times to understand how Markiplier is popular. You can't deny his popularity. I can only get through a few minutes of his vids, though. He's cringier than ANY cringe comp I've ever watched. When I was a kid, if you acted like that, 0 friends and 100% no dates for you. Times have changed XD
Sometimes you may feel helpless and defeated. But everyone loses from time to time. It's okay to be tired. Take a breather. Have a good cry if you need to. You gotta take breaks from your workout, or you'll collapse before you can get stronger.
So, my roommates wrote a news article in English, translated it into Bengali with google translate and now I'm helping them fix the monstrosity which was the result. Making English the medium of education is fine... but not to an extent that we forget how to write properly in our own language :")
Stream will be live shortly with some more Minecraft spriting! Feel free to drop by~

Forum statistics

Threads
93,544
Messages
913,362
Members
123,074
Latest member
leonking
Top