Status
Not open for further replies.

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
361
Reaction score
100
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
195
Reaction score
173
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
152
Reaction score
126
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
324
Reaction score
188
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
44,646
Reaction score
15,732
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
361
Reaction score
100
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
324
Reaction score
188
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
44,646
Reaction score
15,732
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 Profile Posts

Did you check out the new Restaff yet? ;3
I am proud of how much my friends are pure talent. This one is making my game possibilities bigger and bigger and I wanna share his word:
Fun fact. Today it's exactly 2600 days since I met my now gf for the first time. Sometimes being a programmer can be really useful. O:)
Is RPG Maker VX (rgss2) still relevant? xD

Forum statistics

Threads
118,471
Messages
1,116,172
Members
155,452
Latest member
astoryinpieces
Top