RMMV How to set an actor or party member to a specific level

OpenTangent

Villager
Member
Joined
Mar 15, 2020
Messages
13
Reaction score
3
First Language
English
Primarily Uses
RMMV
I'm using DreamX's [Capture Enemies] plugin and I would like to make it that if the player has already captured a specific creature and then captures that type of creature again I'd like to give the player the impression that the previous creature is replaced by the newly captured one. For my needs all that's really important is to change the creature's actor level. I have the new creature's level and I have the corresponding actor object.
JavaScript:
DreamX.CaptureEnemy.levelUpDuplicateActors = function (actorId, target) {
        for (var i = 0; i < $gameParty.allMembers().length; i++) {
            var actor = $gameParty.allMembers()[i];
            if (actor.actorId() === actorId || actor.baseActorId() === actorId) {
                //var newExp = actor.currentExp() + actor.nextRequiredExp();
                //actor.changeExp(newExp, paramDefaultLevelUpMsg);
                actor._level = target.level; // OpenTangent attempt 1
                actor.change_level(target.level, false); // OpenTangent attempt 2
            }
        }
    };
DreamX's code simply increments the level of the existing captured creature by 1 regardless of the target creatures stats so I've commented out that code. I made two attempts at explicitly setting the actor's level. Attempt 1 seems to work but then the game almost immediately sets the level back to what is was before. Attempt 2 throws an exception saying "change_level is not a function". Would I need to calculate experience and use actor.changeExp()? If so how would I do that? Any help is greatly appreciated.
 

OpenTangent

Villager
Member
Joined
Mar 15, 2020
Messages
13
Reaction score
3
First Language
English
Primarily Uses
RMMV
I can't thank you enough @SeaPhoenix that worked perfectly. And thanks for the link to the Script Call List, that's going to make my life a lot easier.

Here's the final levelUpDuplicateActors function code. If the level of the enemy is higher than the existing capture's level then it changes it to that level, otherwise it just increases by 1.
JavaScript:
DreamX.CaptureEnemy.levelUpDuplicateActors = function (actorId, target) {
        console.log(target);
        for (var i = 0; i < $gameParty.allMembers().length; i++) {
            var actor = $gameParty.allMembers()[i];
            if (actor.actorId() === actorId || actor.baseActorId() === actorId) {
                if (actor._level < target.level) {
                    actor.changeLevel(target.level, false);
                } else {
                    var newExp = actor.currentExp() + actor.nextRequiredExp();
                    actor.changeExp(newExp, paramDefaultLevelUpMsg);
                }
            }
        }
    };
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Its been almost 6 months since i've been here last and 5 years before that. the worst part is losing the game you were working on in a cpu fire.

Well time to go at it again.
my game is coming together im so happy
In this day and age, i might switch back to RMXP. I’ve lost faith in all the new plugins.
Wow it's been forever since I last logged in! I STILL want to make a game... I'll start it one day for sure!! It's a dream of mine.
This days I couldn't do anything... My mind is so confused and I couldn't work at all, I only wanted to play video games with my friends and that made all my projects delay a lot. Someone else feels this kind of thing sometimes? :/

Forum statistics

Threads
104,286
Messages
1,005,261
Members
135,797
Latest member
Famas
Top