Status
Not open for further replies.

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
371
Reaction score
104
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
203
Reaction score
186
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
168
Reaction score
143
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
327
Reaction score
192
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,718
Reaction score
15,844
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
371
Reaction score
104
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
327
Reaction score
192
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,718
Reaction score
15,844
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

Hi, I'm a new and upcoming Indie Developer, and I could really use some help when it comes to system programming. Explorers can only go so far before needing a map, you know?
I made a comic strip with the characters of my game.Flor en la cola eng.jpg
Hey, what does it mean in settings, privacy, where it says allow users to: view your identities??????????
I have returned yet again. No reason for my hiatus; just got distracted by video games and stuff. I figured out how to make a bootleg Ys 1 Battle system using in engine scripting (The only plugin enabled is the HUD thing).
Unfortunately I have no idea how to program but-stabbing as a crit without it being even more complicated to program so this is it.

Kickstarter successful!! I'm gonna have a Hot GameDev Summer in the trenches!

Forum statistics

Threads
122,050
Messages
1,146,128
Members
160,320
Latest member
BraveHeartBrony
Top