Status
Not open for further replies.

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
Hi all!

I'm trying to set up a common event to permanently remove dead party members (but only those with IDs greater than 10) from my party during battle.

I'm having a lot of trouble getting it to work - I don't know if it's an error in the code or in not implementing the common event properly. I have the common event being triggered every time someone attacks, but if anyone knows a more elegant way to do it, that would be great!

The screenshot only shows half of the event - it runs the same block four times, once for each party member.

Any assistance would be greatly appreciated :)

EDIT--- I just realised I can use Visustella's battle core to run a common event at the end of every battle. However, the below code is definitely not working.



1610600567068.png
 
Last edited:

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,987
Reaction score
1,450
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi there!
I'm on celphine so I don't know if it will work.
You can try a script call:

$gameParty.battleMembers().forEach(member => {
If(member._actorId > 10 && member.isDead()) {
$gameParty.removeActor(member._actorId)
}
})

The "member" word should return a $gameActor object.

I don't know if the function "isDead" is the correct one to know if an actor is dead.

I also don't remember if the $gameParty.removeActor is the right one to remove an actor from the party.

If no one answers until tomorrow, when I wake up, I will try this out.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,463
Reaction score
14,816
First Language
English
Primarily Uses
RMMV
$gameParty.battleMembers(1) is not valid. $gameParty.battleMembers() returns an array, so you need to use $gameParty.battleMembers()[1] which will be the second party member (the first is [0]). You can't use that to retrieve an actor, because it IS an actor.

Everything you have there can be done with event commands, so I would try using those rather than script calls. That will at least eliminate mistakes due to wrong syntax or commands.

Also, you should start checking from the last party member rather than the first, otherwise every time you remove an actor you're going to skip the next one because they've slid up into the now-vacant spot and you'll move on to whoever is now where they used to be.

Example - your lineup is actors 12, 13, 14 and 15, and 13 and 14 are dead. You check slot 1 and actor 12 is fine so you move on. You check slot 2 and actor 13 is dead, so you remove him. Actor 14 and 15 move into slot 2 and 3. But you've done slot 2 so you move to 3 and check actor 15, who is fine. You skipped actor 14 because they moved into the slot you just checked.
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
$gameParty.battleMembers(1) is not valid. $gameParty.battleMembers() returns an array, so you need to use $gameParty.battleMembers()[1] which will be the second party member (the first is [0]). You can't use that to retrieve an actor, because it IS an actor.

Everything you have there can be done with event commands, so I would try using those rather than script calls. That will at least eliminate mistakes due to wrong syntax or commands.

Also, you should start checking from the last party member rather than the first, otherwise every time you remove an actor you're going to skip the next one because they've slid up into the now-vacant spot and you'll move on to whoever is now where they used to be.

Example - your lineup is actors 12, 13, 14 and 15, and 13 and 14 are dead. You check slot 1 and actor 12 is fine so you move on. You check slot 2 and actor 13 is dead, so you remove him. Actor 14 and 15 move into slot 2 and 3. But you've done slot 2 so you move to 3 and check actor 15, who is fine. You skipped actor 14 because they moved into the slot you just checked.
Hi Shaz,
Thanks for the reply.
I wanted to do it using event commands but, as the dead member to be removed could be one of 50 or so characters, I couldn't figure out how I would do it without scripts. There could also be more than one of these types of characters in the party, and they could be in any order :/
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,463
Reaction score
14,816
First Language
English
Primarily Uses
RMMV
I don't understand your logic.

Control Variables will let you put a battler id into a variable. Conditional Branch will let you determine if the id is > 10, and another conditional branch will let you see if that actor is dead. initMembers is an invalid command the way you are using it, and Show Text will work just the same as you have it.

Remove Actor is the only one that needs a script call. How many actors can you have in a battle at a time?
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
I don't understand your logic.

Control Variables will let you put a battler id into a variable. Conditional Branch will let you determine if the id is > 10, and another conditional branch will let you see if that actor is dead. initMembers is an invalid command the way you are using it, and Show Text will work just the same as you have it.

Remove Actor is the only one that needs a script call. How many actors can you have in a battle at a time?
As I understand it (probably incorrectly), when doing the conditional branch to see if the actor is dead, I need to manually select the name of the actor - I can't see a way to make that take a variable. As I won't know which monster party members are in the party at any given time, I don't know how to do that.

1610612260693.png
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,463
Reaction score
14,816
First Language
English
Primarily Uses
RMMV
You're right - I forget sometimes which event commands allow variables and which don't.

Hopefully the other info I gave about doing it in the opposite order, and the invalid script calls, is helpful though.
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
Hi there!
I'm on celphine so I don't know if it will work.
You can try a script call:

$gameParty.battleMembers().forEach(member => {
If(member._actorId > 10 && member.isDead()) {
$gameParty.removeActor(member._actorId)
}
})

The "member" word should return a $gameActor object.

I don't know if the function "isDead" is the correct one to know if an actor is dead.

I also don't remember if the $gameParty.removeActor is the right one to remove an actor from the party.

If no one answers until tomorrow, when I wake up, I will try this out.
Hey Eliaquim,
I've tried to do what I think you mean and it's not working :( I really have no idea what I'm doing...
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
You're right - I forget sometimes which event commands allow variables and which don't.

Hopefully the other info I gave about doing it in the opposite order, and the invalid script calls, is helpful though.
The opposite order thing I definitely understand, but not sure what I should do to fix the rest. I tried this and I keep getting an error saying the objects are undefined.
Any ideas?

1610619149485.png
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,463
Reaction score
14,816
First Language
English
Primarily Uses
RMMV
$gameParty.battleMembers()[4] gives you an actor object, not a number. Some of your script calls need a number, and some of them need the actor, not the id. $gameParty.members needs an index, not an actor id.

Control Variables: 10 = $gameParty.battleMembers()[4].actorId()

If Script: $gameActors.actor($gameVariables.value(10)).isDead()

$gameParty.removeActor($gameVariables.value(10))


Actually, @Eliaquim's method should work perfectly - just one script call is all you need - no variables, no looping - replace everything you have in the common event with just that script call. If you try it and it's not working, show us a screenshot. It just won't show the text.
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
$gameParty.battleMembers()[4] gives you an actor object, not a number. Some of your script calls need a number, and some of them need the actor, not the id. $gameParty.members needs an index, not an actor id.

Control Variables: 10 = $gameParty.battleMembers()[4].actorId()

If Script: $gameActors.actor($gameVariables.value(10)).isDead()

$gameParty.removeActor($gameVariables.value(10))


Actually, @Eliaquim's method should work perfectly - just one script call is all you need - no variables, no looping - replace everything you have in the common event with just that script call. If you try it and it's not working, show us a screenshot. It just won't show the text.
And @Shaz with your suggestion (if I'm implementing it correctly) I get this error:

1610623483846.png
1610623534519.png
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,463
Reaction score
14,816
First Language
English
Primarily Uses
RMMV
For Eliaquim's idea, use a lower case i for if, not If.

For mine, is it possible that you don't have 4 party members? Maybe you should put each block inside a conditional branch to check that there are 4 or more members in the battle party. Also remember what I said about the first party member being [0] and not [1]. So if you can have 4 battlers, your first block would look like this:

If: Script: $gameParty.battleMembers().length >= 4
Control Variables: 10 = $gameParty.battleMembers()[3].actorId()

But Eliaquim's solution is nicer, as long as you don't mind the text not showing or can figure out another way to show it.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,468
Reaction score
1,863
First Language
EN
Primarily Uses
RMMZ
Eliaquim's solution uses forEach, which I think processes elements in ascending order...? However, like Shaz says, you probably want reverse order here.

Instead, I'd suggest something like this in a Script command:
JavaScript:
const members = $gameParty.members();
for (let n = members.length; n--;) {   // loop end-to-start
  const m = members[n];
  if (m) {   // check they exist, just in case
    const id = m.actorId();
    // remove any dead actors with ID > 10
    if (id > 10 && m.isDead()) $gameParty.removeActor(id);
  }
}
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
For Eliaquim's idea, use a lower case i for if, not If.

For mine, is it possible that you don't have 4 party members? Maybe you should put each block inside a conditional branch to check that there are 4 or more members in the battle party. Also remember what I said about the first party member being [0] and not [1]. So if you can have 4 battlers, your first block would look like this:

If: Script: $gameParty.battleMembers().length >= 4
Control Variables: 10 = $gameParty.battleMembers()[3].actorId()

But Eliaquim's solution is nicer, as long as you don't mind the text not showing or can figure out another way to show it.
Oooh, @Eliaquim's solution works an absolute treat! Thanks so much both of you! :D :D
I added the text like this:
1610631319721.png
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,987
Reaction score
1,450
First Language
Portuguese - Br
Primarily Uses
RMMZ
[EDIT] Ops, see that you already solve it. Sorry ^^''
Was a challenge for me type that on my cellphone xD
As Shaz said, I believe you just need to correct the capitalization of the If:

JavaScript:
$gameParty.members().forEach(member => {
    If(member._actorId > 10 && member.isDead()) {
        $gameParty.removeActor(member._actorId)
    }
});

You can replace $gameParty.battleMembers() with just $gameParty.members(). If you are in battle it will return just the battle members anyway.

Or do as Caethril said.
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
Eliaquim's solution uses forEach, which I think processes elements in ascending order...? However, like Shaz says, you probably want reverse order here.

Instead, I'd suggest something like this in a Script command:
JavaScript:
const members = $gameParty.members();
for (let n = members.length; n--;) {   // loop end-to-start
  const m = members[n];
  if (m) {   // check they exist, just in case
[QUOTE="caethyril, post: 1154984, member: 118196"]
Eliaquim's solution uses [icode]forEach[/icode], which I think processes elements in ascending order...? However, like Shaz says, you probably want reverse order here.

Instead, I'd suggest something like this in a [B]Script[/B] command:
[code=javascript]const members = $gameParty.members();
for (let n = members.length; n--;) {   // loop end-to-start
  const m = members[n];
  if (m) {   // check they exist, just in case
    const id = m.actorId();
    // remove any dead actors with ID > 10
    if (id > 10 && m.isDead()) $gameParty.removeActor(id);
  }
}

const id = m.actorId();
// remove any dead actors with ID > 10
if (id > 10 && m.isDead()) $gameParty.removeActor(id);
}
}[/code]
[/QUOTE]

Oh, so many responses, now I don't know what to do! :D
I used Eliaquim's solution with Shaz's fix, and there were party members to remove in the third and fourt party member positions, but they both removed fine. Does that mean the ascending order thing might not be a problem?
 

Rixxus

Veteran
Veteran
Joined
Oct 23, 2020
Messages
45
Reaction score
8
First Language
English
Primarily Uses
RMMZ
[EDIT] Ops, see that you already solve it. Sorry ^^''

Was a challenge for me type that on my cellphone xD
As Shaz said, I believe you just need to correct the capitalization of the If:

JavaScript:
$gameParty.members().forEach(member => {
    If(member._actorId > 10 && member.isDead()) {
        $gameParty.removeActor(member._actorId)
    }
});

You can replace $gameParty.battleMembers() with just $gameParty.members(). If you are in battle it will return just the battle members anyway.

Or do as Caethril said.
Why do you think I should replace $gameParty.battleMembers() with $gameParty.members()?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,468
Reaction score
1,863
First Language
EN
Primarily Uses
RMMZ
I used Eliaquim's solution with Shaz's fix, and there were party members to remove in the third and fourt party member positions, but they both removed fine. Does that mean the ascending order thing might not be a problem?
Oh nice! Sounds like there's no problem, then~ :kaothx:

Why do you think I should replace $gameParty.battleMembers() with $gameParty.members()?
There's hardly any difference. By default (no plugins) they're the same when in battle. members is shorter to write, and also higher-level, i.e. it offers the best chance of being compatible with any plugins you may be using.
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
16,038
Reaction score
8,904
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

It's almost 3 month and this piece of drawing is still not finished yet.
aaaa.jpg

Really busy with other stuffs like commission and coping with personal problem.
Stella & Elyune, maybe used for promotional art if my game project finished one day.
My ex put my heart upon a self he said don't give me no lines and keep my hands to myself :,(
An Old... old Harold | RPG Maker News #71

Did a test on myself and I was negative on COVID. I was sitting near my aunt the whole time while doing stuff.

Forum statistics

Threads
112,243
Messages
1,066,801
Members
145,855
Latest member
Anvi
Top