Counting actor's deaths

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I need to have a variable count the number of times a specific actor has died in battle, but cannot find how to do this.

Can anyone tell me how this is done?

Thanks.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,669
First Language
German
Primarily Uses
RMMV
I would start by counting how many times the death state has been removed, and adding one if the actor is currently dead.
That would be much easier to implement as it requires specific skills or items to remove the death state - much easier than trying to check for all forms of damage or continually checking if the death state is applied or removed.

If the actor is autorevived without specific skill/item use, then you either need a way to count the autorevive or you'll have to add a script changing the death state coding in the default engine.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Andar No autorevive in this instance, so that's one complication less. Presumably the item, or skill, would have to call a common event which would run a conditional to see which actor it was being used on, then if it is the correct actor, add to a variable, and then do its reviving stuff.

Is that what you mean?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,669
First Language
German
Primarily Uses
RMMV
Basically yes, that is one way to handle it.
It could also be handled with code in the damage formula, but that would be a bit more complex depending on how many actors - but sometimes easier if there is a problem with using common events.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Andar What would the code be in the damage formula? This would only ever apply to one particular actor, which should reduce the complexity, and might in the long run be easier than using common events.
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
Would be a really easy code snip, but I'm stuck at work for another three hours...

A damage formula isn't very reliable here since other calculations occur after the formula is evaluated. Guard rate, element rate, critical damage...
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Rinobi If you're prepared to work your scripting magic, I'm more than happy to wait.
Thank you.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz So the full note would read
onadd: b.actor_id?(5); v(61) +=1

Something feels wrong about that, but I can't identify what it is.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
there is a function that handles death all by itself.
just tap into that and run your counter from there, that way you can use the actor object's own id function to point to an array.

Code:
class Game_Battler < Game_BattlerBase
 alias die_stock die
 def die
  die_stock
  $game_variables[61][id] += 1 if actor?
 end
end
?
 
  • Like
Reactions: Kes

Milennin

"With a bang and a boom!"
Veteran
Joined
Feb 7, 2013
Messages
2,511
Reaction score
1,642
First Language
English
Primarily Uses
RMMV
In battle event that plays during every action, have a variable branch that checks if the actor is knocked out, then another branch within it that checks if death switch is off. If off, turn it on and add +1 to death count. If the actor is not knocked out, turn the switch off.
 
  • Like
Reactions: Kes

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
You would need to make sure b is an actor, and not an enemy.

It would be something like:

onadd: \v[61] += 1 if b.is_actor? && b.actor_id == 5

I'm not sure about the method names or if \v is available in this script (I suspect it is, because I use b.-stuff- in one of the examples and where b is available, \v should be as well)

I'm on my work computer, so I can't check the syntax until a bit later.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@gstv87 and @Milennin
Thanks for these suggestions. However, having seen the script that Shaz linked to, I'm probably going to go with that, as I can think of a number of other uses for this script, once I've got the hang of the commands to put in the note box. It opens up a range of possibilities.

EDIT
@Shaz You posted just as I was typing my reply.
I've tested this, and no error message, but the variable was not increased.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
okay - seems that was an old version where I had some issues with the order of things. Can you please download and try again?

This is a method in the battler class, so you can use any commands for a battler (ie - leave out the b. - it just works on the target by default).

The correct command to add to the state is:

onadd: $game_variables[61] += 1 if actor? && id == 5

However, in testing, I noticed a weird situation occurs - when the actor is first set up, their HP starts at 0 before it's initialized to the correct value. And the test to "apply the death state if HP is 0" gets run. So as soon as you start a new game, the death state is applied, the onadd script is run and the variable is incremented.

To get around this, you just need to set the variable to 0 at the start of the game (or at the time you add the actor to your party and initialize them).

Seems to work after that.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Tested and it works perfectly for me. Once more you come to my rescue.
Thank you very much for this.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top