VoxSyreni

Veteran
Veteran
Joined
Nov 25, 2020
Messages
34
Reaction score
7
First Language
Danish
Primarily Uses
N/A
Hi there. I am trying to Remove an actor and Replace it with a different one in a common event.

I am using Copy Actors from other plugins, what these do is replicate identical actors with unique ID's that start in the thousands, which means I can't guarantee the instance of an actor has the same ID every time.

What I want to do is

Common Event
-Locate the Class_ID of the Actor in party. (I have unique classes for all Actors)

-Use Class_ID to Identify Actor ID

-Store Actor_ID in variable

-Confirm Actor_ID has met Required Level. If not, check if there are other actors with the same class ID that might do.

-Use Actor_ID Variable to remove actor.


I don't know how to find Class_ID in party. Much less how to use that to identify Actor ID.
I am also unsure about how to tie that Actor ID to a variable.

I am also not sure what to do if there is multiple actors with the same class_ID.

Alternately I could try and find Actor by name instead of Class_ID or by Notetag. What matters is if I can locate the actor and get the ID so I can set it to variable to check level and then potentially remove the actor.

I am assuming, I will have to do a scripthcall to Remove the Actor by variable instead of by ID.

This is my current attempt

If there is anyone out there who can help me?
 

Attachments

  • Failure.PNG
    Failure.PNG
    47.9 KB · Views: 4
Last edited:

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
491
Reaction score
460
First Language
german
Primarily Uses
RMMZ
I'm not 100% sure what you are trying, but I give my best.

Looking at your screenshot:
1. line:
Code:
$gameParty.members._currentClass(25)
is not a valid line, as "members" returns an array. It could be
Code:
$gameParty.members()[0]._currentClass
then you would get the class of the leader of the party.

2. line: You usually don't do a ; within brackets.
Code:
$gameParty.members()[$gameVariables.value(xy)
will work fine

Use Class_ID to Identify Actor ID
So this is the line that I don't understand yet. In RM, every actor has one class, but there's no link back AFAIK. So what we can do, is to go through all the actors and check if he has the class that you are looking for. Use this line

Code:
const filtered = $gameParty.members().filter(actor => actor.currentClass().id == YOUR_CLASS_ID;
const actor = filtered.length > 0 ? filtered[0] : null;
const level = actor ? actor._level : -1;

As you can see, actor can be null when there's no actor having this class. If so, the variable level is -1.
 

VoxSyreni

Veteran
Veteran
Joined
Nov 25, 2020
Messages
34
Reaction score
7
First Language
Danish
Primarily Uses
N/A
I'm not 100% sure what you are trying, but I give my best.

Looking at your screenshot:
1. line:
Code:
$gameParty.members._currentClass(25)
is not a valid line, as "members" returns an array. It could be
Code:
$gameParty.members()[0]._currentClass
then you would get the class of the leader of the party.

2. line: You usually don't do a ; within brackets.
Code:
$gameParty.members()[$gameVariables.value(xy)
will work fine


So this is the line that I don't understand yet. In RM, every actor has one class, but there's no link back AFAIK. So what we can do, is to go through all the actors and check if he has the class that you are looking for. Use this line

Code:
const filtered = $gameParty.members().filter(actor => actor.currentClass().id == YOUR_CLASS_ID;
const actor = filtered.length > 0 ? filtered[0] : null;
const level = actor ? actor._level : -1;

As you can see, actor can be null when there's no actor having this class. If so, the variable level is -1.


Thank you so much for taking your time to reply.

I must probably make this perfectly clear, I can't read Javascripth. What I done is scour forums and trying to construct something based on similar strings. So if my lines don't make much sense, it might be because I am way off the mark.

1. Line
Is not a valid line, that is quite too bad. I don't want the Class of any particular party member. I want to find out which partymembers has class 25. It might be the leader, it might be position 4 or 8. Given that my game gives huge freedom to team composition.

I was trying to set that data to Variable 7. For example. If the 3rd Party member has Class 25. I want to set Variable 7 to 2*. But in all honesty this was a means to an end.

2. Line
So this here should work fine?
$gameParty.members()[$gameVariables.value(7).level

This should check the level of the actor in the position that Variable 7 has? Following our example would be the Level of Actor in position 3.



Going back to what I said earlier in this post. It is a means to an end.
Ultimately the goal is to *Remove an actor* without knowing their actorId or their Party position before hand. I was thinking I could use the class to pinpoint the actor. But if there is a better solution I am open to alternatives.
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
491
Reaction score
460
First Language
german
Primarily Uses
RMMZ
2. Line
So this here should work fine?
$gameParty.members()[$gameVariables.value(7).level
Sorry, I accidently dropped the closing ]
Code:
$gameParty.members()[$gameVariables.value(7).level]
is the line to get the actor, but this would get you any actor, but we want the actor with a specific class.

Okay, I would recommend you to use pure JS instead of a mix of JS and Eventing.

Code:
// get all actors having class 25 and Level below 6
const actors = $gameParty.members()
    .filter(actor => actor.currentClass().id() == 25)
    .filter(actor => actor._level < 6);

// remove them
actors.forEach(actor => $gameParty.removeActor(actor.actorId()));

This snippets removes all actors from the Party having the specific class and level below 6
 

VoxSyreni

Veteran
Veteran
Joined
Nov 25, 2020
Messages
34
Reaction score
7
First Language
Danish
Primarily Uses
N/A
Sorry, I accidently dropped the closing ]
Code:
$gameParty.members()[$gameVariables.value(7).level]
is the line to get the actor, but this would get you any actor, but we want the actor with a specific class.

Okay, I would recommend you to use pure JS instead of a mix of JS and Eventing.

Code:
// get all actors having class 25 and Level below 6
const actors = $gameParty.members()
    .filter(actor => actor.currentClass().id() == 25)
    .filter(actor => actor._level < 6);

// remove them
actors.forEach(actor => $gameParty.removeActor(actor.actorId()));

This snippets removes all actors from the Party having the specific class and level below 6

I need it to remove on =, but that is just changing the < to =.

I just tested it and the code worked perfectly!

Just one thing and that is on me for being an idiot. I should have mentioned in the first place. I wanted within the same event also to add an actor, but only if something gets removed.

I planned to accomplish this by using conditional branch to say
"If: ActorXY Level = 6"
remove actor
Add actor

I assumed that regardless of what solution I found to the first problem, it wouldn't interfere with the Add Actor part and left it out to not distract from the main issue.

Is there anyway to add an "If remove add actor"?

I am so sorry for asking about more stuff now. I am very grateful for the help you provided thus far.
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
491
Reaction score
460
First Language
german
Primarily Uses
RMMZ
Okay, so first we "extend" this line
Code:
actors.forEach(actor => $gameParty.removeActor(actor.actorId()));
, "forEach" is fine when using just one method, but having multiple actions it's better having a simple for loop. So replace this line with this code snippet please:

Code:
for (let actor of actors) {
    $gameParty.removeActor(actor.actorId());
    $gameParty.addActor(ACTOR_ID); // replace ACTOR_ID with a number
}

But which actor do you want to add then?
 

VoxSyreni

Veteran
Veteran
Joined
Nov 25, 2020
Messages
34
Reaction score
7
First Language
Danish
Primarily Uses
N/A
Okay, so first we "extend" this line
Code:
actors.forEach(actor => $gameParty.removeActor(actor.actorId()));
, "forEach" is fine when using just one method, but having multiple actions it's better having a simple for loop. So replace this line with this code snippet please:

Code:
for (let actor of actors) {
    $gameParty.removeActor(actor.actorId());
    $gameParty.addActor(ACTOR_ID); // replace ACTOR_ID with a number
}

But which actor do you want to add then?

It seems like I can't get it to work again. And the changed code doesn't work either :/

I am trying to add actor 26.
I'll attach the actors in question.
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
491
Reaction score
460
First Language
german
Primarily Uses
RMMZ
Ahhh you want an "Evolve"-System? Then I was slightly on the wrong track. By the way, we do the coding, I don't need the images of your enemies, but it made me giggle :D

I extended the code a bit to make it a little bit more flexible:

Code:
const classId = $gameVariables.value(xy);
const level = $gameVariables.value(yz);

const actors = $gameParty.members()
    .filter(actor => actor.currentClass().id == classId)
    .filter(actor => actor._level == level);

for (let actor of actors) {
    $gameParty.removeActor(actor.actorId());
    $gameParty.addActor(actor.actorId() + 1);
}

Replace xy and yz with your Variable Ids. Then, finally, you can set your Variables with common Eventing and call this JS Code snippet. All characters having this class and this level, will be replaced by their respective actor + 1. So actor with Id 42 is replaced by Actor 43.

If you still get any error message, please make a screenshot so I can see better where I was wrong. I don't know all of the commands and attributes by heart.
 

VoxSyreni

Veteran
Veteran
Joined
Nov 25, 2020
Messages
34
Reaction score
7
First Language
Danish
Primarily Uses
N/A
Ahhh you want an "Evolve"-System? Then I was slightly on the wrong track. By the way, we do the coding, I don't need the images of your enemies, but it made me giggle :D

I extended the code a bit to make it a little bit more flexible:

Code:
const classId = $gameVariables.value(xy);
const level = $gameVariables.value(yz);

const actors = $gameParty.members()
    .filter(actor => actor.currentClass().id == classId)
    .filter(actor => actor._level == level);

for (let actor of actors) {
    $gameParty.removeActor(actor.actorId());
    $gameParty.addActor(actor.actorId() + 1);
}

Replace xy and yz with your Variable Ids. Then, finally, you can set your Variables with common Eventing and call this JS Code snippet. All characters having this class and this level, will be replaced by their respective actor + 1. So actor with Id 42 is replaced by Actor 43.

If you still get any error message, please make a screenshot so I can see better where I was wrong. I don't know all of the commands and attributes by heart.


Oh I thought you asked out of curiosity so I showed them. I removed them again now that I know you seen them. I am not quite ready for them to be super public.

If Variable 7 is set to class 25
And variable 1 is set to level 6

Code:
const classId = $gameVariables.value(7);
const level = $gameVariables.value(1);

const actors = $gameParty.members()
    .filter(actor => actor.currentClass().id == classId)
    .filter(actor => actor._level == level);

for (let actor of actors) {
    $gameParty.removeActor(actor.actorId());
    $gameParty.addActor(actor.actorId() + 1);
}
this should work as a singular scripth?

EDIT: Man you did it! It works like smooth butter now! this is amazing! thank you so many time!
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
491
Reaction score
460
First Language
german
Primarily Uses
RMMZ
Im glad it works :)

It's a single script, making it as a Plugin is possible but would be too much imo.
 

VoxSyreni

Veteran
Veteran
Joined
Nov 25, 2020
Messages
34
Reaction score
7
First Language
Danish
Primarily Uses
N/A
Im glad it works :)

It's a single script, making it as a Plugin is possible but would be too much imo.

I don't mind using it as a script. Whatever works right? ^^

Also for future people who finds this

$gameMessage.add("X got swapped for Y");

Adding this between the 2 bottom lines doesn't break the code and is a good way to make a visual indicator for what just happened.
 

Latest Threads

Latest Posts

Latest Profile Posts

After so many hours of debugging, losing data to crashes, and slight adjustments.
BlackJack now deals cards perfectly! Time to adjust the background and implement the game logic so you can actually play it.BlackJack.png
I once thought about a boss gauntled game. I actually did it.
Stream will be live shortly with some Gex 3! Feel free to drop by!
Snippet from a game I'm working on. Not much happening here. Mostly look at atmosphere. May upload a longer version. Still need to make up some enemy arts.

Forum statistics

Threads
109,060
Messages
1,041,716
Members
141,550
Latest member
Leekit
Top