Creating a state that tracks the hits an actor lands on enemies.

GHNeko

Sega Stockholm Syndrome.
Veteran
Joined
May 28, 2018
Messages
37
Reaction score
2
First Language
English
Primarily Uses
RMMZ
I'm trying to figure out how to create a state, that while active, tracks each hit the actor does with non-magic attacks (certain hit and physical only), including each individual hit from attacking multiple enemies, and store that value in a variable (through $gameVariable if possible) for me to use.

I kinda have a starting point from http://yanfly.moe/2016/04/16/tips-tricks-bide-pokemon-rpg-maker-mv/

but i havnt been able to find documentation to help me point out where to go.

ive been using https://kinoar.github.io/rmmv-doc-web/globals.html as well as the google docs link that has a bunch of RMMV script calls but I think I'm still missing a few pieces to make this all work together.

the variable that sorts how many times the actor, under said state, lands their hits is to be then put into a state counter (which i know how to do) and used to fuel an effect that occurs when said state ends.

help, guidance, answers, and more would be greatly appreciated. sorry for the trouble.
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
747
Reaction score
256
First Language
Vietnamese
Primarily Uses
RMMV
I think you can use Yanfly Buffs & States Core + Auto Passive State to do.
- Auto Passive State allows you to activate/deactivate your state automatically via certain conditions.
- Buffs & States Core helps you track the number of hits which are landed on the enemies.

I will try to make one for example, but i'm not sure it will work correctly because i have nothing to test it at this moment, but you can give it a try.
- For example, i will create a passive state which is activated automatically when user's HP is lower than 50%. Below is the note tag for this state to check if conditions are met (Remember to give this state to your actor by using note tag <Passive State: x> where X is the state ID):
Code:
<Custom Passive Condition>
//if user's HP is more than 50%, activate the state
if (user.hpRate() <= 0.5) {
//activate the state
condition = true;
//set this flag to track the number of hits landed later
user._hitCounter = user._hitCounter || 0;
} else {
//deactivate the state
condition = false;
//reset the hit counter to 0
user._hitCounter = 0;
//store it in variable X. Change X to your variable ID
$gameVariables.setValue(x, user._hitCounter);
}
</Custom Passive Condition>

- To track the number of hits landed, use this note tag for the same state:
Code:
<Custom Establish Effect>
//check if this is not a magical attack, and it deals damage to the target
if (!this.isMagical() && this.isDamage()){
//increase the hit counter by 1
user._hitCounter +=1;
//store it in variable X. Change X to your variable ID
$gameVariables.setValue(x, user._hitCounter);}
</Custom Establish Effect>
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,834
Reaction score
1,892
First Language
Spanish
Primarily Uses
RMVXA
or, hack into executedamage() and use the action's own validation to check for type of damage.

Code:
orig_execute_damage = Game_Action.prototype.executeDamage

Game_Action.prototype.executeDamage = function(target, value) {
  orig_execute_damage.call(this)
  if (target.isEnemy() && this.isPhysical()) {
    if (this.subject().isStateAffected(id)) {
     $gameVariables[id] += 1;
    };
  };
};


you don't need a cannon to kill a mosquito.
 

GHNeko

Sega Stockholm Syndrome.
Veteran
Joined
May 28, 2018
Messages
37
Reaction score
2
First Language
English
Primarily Uses
RMMZ
or, hack into executedamage() and use the action's own validation to check for type of damage.

Code:
orig_execute_damage = Game_Action.prototype.executeDamage

Game_Action.prototype.executeDamage = function(target, value) {
  orig_execute_damage.call(this)
  if (target.isEnemy() && this.isPhysical()) {
    if (this.subject().isStateAffected(id)) {
     $gameVariables[id] += 1;
    };
  };
};


you don't need a cannon to kill a mosquito.

so it would look something like this right?

8488b4ffc3.png


this is the edit i made in rpg_objects.js. i added in the snippet with changes as needed within the function (namely checking to see if the attack is physical or a certain hit).
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,834
Reaction score
1,892
First Language
Spanish
Primarily Uses
RMVXA
no.
Code:
orig_execute_damage = Game_Action.prototype.executeDamage
is, by definition,
Code:
Game_Action.prototype.executeDamage = function(target, value) {...};

Code:
Game_Action.prototype.executeDamage = function(target, value) {...};
is "A"

you're ordering, "take A, and name it B".
Code:
orig_execute_damage = Game_Action.prototype.executeDamage

now, take A, and define it A'.
Code:
Game_Action.prototype.executeDamage = function(target, value) {
  orig_execute_damage.call(this)
  if (target.isEnemy() && this.isPhysical()) {
   if (this.subject().isStateAffected(id)) {
    $gameVariables[id] += 1;
   };
  };
};
now, every time A is called, A' will be triggered.

from A', call B,
Code:
Game_Action.prototype.executeDamage = function(target, value) {
  orig_execute_damage.call(this)

and then run the extra code.
Code:
if (target.isEnemy() && this.isPhysical()) {
   if (this.subject().isStateAffected(id)) {
    $gameVariables[id] += 1;
   };
  };
};
you don't need to add anything to the original A.

"Aliasing". Look it up.

also, Boolean logic basics:
A && B || A && C = A && (B || C)
I assumed that "certain" can be either "physical" OR "magical", so by validating "physical" alone as "not magical", it would also include "certain", discarding "magical certain"
you make the validation as you see fit, but only evaluate isStateAffected() as it's own thing, so you can pass over that part if the target is not an enemy, or otherwise not valid.
 
Last edited:

GHNeko

Sega Stockholm Syndrome.
Veteran
Joined
May 28, 2018
Messages
37
Reaction score
2
First Language
English
Primarily Uses
RMMZ
Mmm...I dont think I understand 100%.

I get the
Code:
orig_execute_damage
part because i'm creating a new object from the method (?) that is executeDamage.

what i think i don't understand is
Code:
Game_Action.prototype.executeDamage = function(target, value) {
  orig_execute_damage.call(this)
  if (target.isEnemy() && this.isPhysical()) {
   if (this.subject().isStateAffected(id)) {
   $gameVariables[id] += 1;
   };
  };
};

if im understanding right, you're basically calling B (which contains the entirety of A) within a modified A (or A`) and then after B is called, the extra code (if target and if physical) is run afterwards.

so while it looks like this

Code:
Game_Action.prototype.executeDamage = function(target, value) {
  orig_execute_damage.call(this)
  if (target.isEnemy() && this.isPhysical()) {
   if (this.subject().isStateAffected(id)) {
   $gameVariables[id] += 1;
   };
  };
};

the reality is that it's similar to this

Code:
Game_Action.prototype.executeDamage = function(target, value) {
//This is contained within orig_execute_damage (B, a copy of A)
    var result = target.result();
    if (value === 0) {
        result.critical = false;
    }
    if (this.isHpEffect()) {
        this.executeHpDamage(target, value);
    }
    if (this.isMpEffect()) {
        this.executeMpDamage(target, value);
    }
//The extra code
if (target.isEnemy() && this.isPhysical()) {
   if (this.subject().isStateAffected(id)) {
   $gameVariables[id] += 1;
   };
  };
};

am i understanding this correctly? i'm trying not to walk away without an understanding of a solution i've been given.
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,834
Reaction score
1,892
First Language
Spanish
Primarily Uses
RMVXA
pretty much, yes.

you alias a function in order to not overwrite the function if what you need to run will be run after the code of the original function anyways.

adding the code into the original function would be effectively *overwriting* the function.

you can outright overwrite it if you don't care, but just in case there's something else running also hooked up to that function, you alias it, so it's always run if the other code assumes it should be run unmodified.... and, you can still disable your addition, and that'll effectively revert the original function to it's unmodified state without having to modify *it* back.
 

GHNeko

Sega Stockholm Syndrome.
Veteran
Joined
May 28, 2018
Messages
37
Reaction score
2
First Language
English
Primarily Uses
RMMZ
pretty much, yes.

you alias a function in order to not overwrite the function if what you need to run will be run after the code of the original function anyways.

adding the code into the original function would be effectively *overwriting* the function.

you can outright overwrite it if you don't care, but just in case there's something else running also hooked up to that function, you alias it, so it's always run if the other code assumes it should be run unmodified.... and, you can still disable your addition, and that'll effectively revert the original function to it's unmodified state without having to modify *it* back.

great i'm glad i understand then. thank you for your help and thanks for the education/lesson. i really appreciate it.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,834
Reaction score
1,892
First Language
Spanish
Primarily Uses
RMVXA
if what you need to run will be run after the code
or, before.

you alias a function if you don't intend to modify the internal logic of the function itself, but you need to hook code into it, before or after.
 

GHNeko

Sega Stockholm Syndrome.
Veteran
Joined
May 28, 2018
Messages
37
Reaction score
2
First Language
English
Primarily Uses
RMMZ
yeah i understand now. it makes a lot of sense too.
 

Latest Threads

Latest Profile Posts

I remade/fixed my Elf XP Mack Templates. The Ears are looking better now.
Male Update.pngFemale Update.png
You can check them out, they are in 12 recolours, both Human and Elf Versions!
I'M BACK BABEY!!!
College is hitting me a lil' softer than I expected, so I'm back on MV!
And to kick things off, here's a lil' test of a tileset edit I made today! (Took me, like, 5 hours, considering this was the first time I've EVER used GraphicsGale...)Edit test SUCCESS.PNG

Forum statistics

Threads
124,603
Messages
1,164,685
Members
163,425
Latest member
monmamamon
Top