Status
Not open for further replies.

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
509
Reaction score
167
I have 4 variables to assign different level for actor recruitment. I would like to ask help how to set this up using the script call even function. thank you

1. New actor level is equal to average party level
2. New actor level is equal to level of member with highest level
3. New actor level is equal to level of member with lowest level
4. New actor level is equal to level of Main character (database ID actor 17), even if not in active party
 

boomy

Veteran
Veteran
Joined
Jan 6, 2013
Messages
224
Reaction score
215
First Language
English
Primarily Uses
RMMV
var avgLevel = 0;
var lowestLevel = 999;
var highestLevel = 0;
var specificLevel = 0;
for(var i = 0; i < $gameParty.members().length; i++) {
avgLevel += $gameParty.members().level;
if($gameParty.members().level > highestLevel) {
highestLevel = $gameParty.members().level;
}

if($gameParty.members().level < lowestLevel) {

lowestLevel = $gameParty.members().level;

}
if($gameParty.members().actorId() == 17) {
specificLevel = $gameParty.members().level;
break;
}


}
console.log(avgLevel / $gameParty.members().length + " / " + highestLevel + " / " + lowestLevel + " / " + specificLevel)
 
Last edited:

eomereolsson

Veteran
Veteran
Joined
Sep 29, 2021
Messages
543
Reaction score
462
First Language
German
Primarily Uses
RMMV
@boomy you seem to have missed your[i] while iterating through the members() array.
 
Last edited:

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
337
Reaction score
203
First Language
English
Primarily Uses
RMMZ
JavaScript:
// For current party only
// -> To use all members replace "battleMembers()" with "members()"
const levels = $gameParty.battleMembers().map(e => e.level);

// Average Level
let newLevel = levels.reduce((a,b) => a + b, 0) / levels.length;

// Lowest Level
let newLevel = Math.min(...levels);

// Highest Level
let newLevel = Math.max(...levels);

// Party leader
let newLevel = $gameParty.leader().level;

// Specific actor (the actual leader, as you mentioned in OP):
let newLevel = $gameActors.actor(17).level;

EDIT3 (last one I swear): Alternatively if you want all the variables in one script call, just change their names so they're unique (or call the $gameVariables.setValue(id, newLevel) after each one).

EDIT2: Actually forgot 1 more detail. After you've assigned the levels and determine which newLevel to use, then of course add the following to assign the variable:
JavaScript:
// Replace "variableId" with the ID of the variable that stores the value.
$gameVariables.setValue(variableId, newLevel);

EDIT: Okay there... I think I'm done editing my mistakes lol. Hope this helps.
 
Last edited:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
45,498
Reaction score
16,403
First Language
English
Primarily Uses
RMMV
It was added, but because it wasn't put into code tags, it was interpreted as formatting code, and everything after is showing in italics.
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
509
Reaction score
167
I tried the script command.. here are the results.. its not correct. it returns the value for the MC level.

MC = 21
Actor 2 = 9
Actor 3 = 3
Actor 4 = 16

5.25 / 21 / 21 / 21

JavaScript:
var avgLevel = 0; var lowestLevel = 999; var highestLevel = 0; var specificLevel = 0;
for(var i = 0; i < $gameParty.members().length; i++) {
avgLevel += $gameParty.members()[i].level;
if($gameParty.members()[i].level > highestLevel) { highestLevel = $gameParty.members()[i].level;}
if($gameParty.members()[i].level < lowestLevel) {lowestLevel = $gameParty.members()[i].level;}
if($gameParty.members()[i].actorId() == 17) {specificLevel = $gameParty.members()[i].level;break;}
}
console.log(avgLevel / $gameParty.members().length + " / " + highestLevel + " / " + lowestLevel + " / " + specificLevel)
$gameVariables.setValue(6,avgLevel);$gameVariables.setValue(7,highestLevel);$gameVariables.setValue(8,lowestLevel);$gameVariables.setValue(9,specificLevel);
$gameVariables.setValue(10,Math.floor(Math.random() * (highestLevel-lowestLevel)) + avgLevel);

EDIT: @lordvalinar thanks your code works
 
Last edited:

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
337
Reaction score
203
First Language
English
Primarily Uses
RMMZ
EDIT2:- Actually $gameParty.highestLevel() gets all members, not just current party.. so good to know for future :)
EDIT: Glad it could help :)

I stand corrected... (on the "last edit").. turns out Game_Party() has a function already that retrieves the highest level.

JavaScript:
// The script call
let newLevel = $gameParty.highestLevel();

// Function (basically same thing as I posted already) - rmmz_objects.js line 5529
Game_Party.prototype.highestLevel = function() {
    return Math.max(...this.members().map(actor => actor.level));
};

Or since this is actually RMMV - rpg_objects.js line 4913, but yeah same thing. All members.
 
Last edited:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
45,498
Reaction score
16,403
First Language
English
Primarily Uses
RMMV

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.

Latest Threads

Latest Posts

Latest Profile Posts

For some reason a vegan webpage was suggested for me on FB. So I thought let's troll them. Because some of the posters needed a reality check.
I intended to start losing some weight starting today but It's apparently my birthday and I was given 2 big Toblerone's. So....Tomorrow then :p
JR.png
design for 1920's Jazz-singer
(can you guess what character inspired me here? xD )
Another brief AD video. Pretty proud of this.
new to game making and open to any help on getting started

Forum statistics

Threads
129,821
Messages
1,205,503
Members
170,943
Latest member
MikeC_
Top