Check if an enemy can act

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
327
Reaction score
471
First Language
German
Primarily Uses
RMMV
My problem is a short one.

I want to check whether or not an enemy can act or not during the battle.
There is one part of the battle where I force an enemy (force action) to perform a slew of consecutive actions.
However, the enemy should only do this action when he can (i.e. is not hindered by any negative status effect like stun or paralyze)

There are a lot of different states in my game that hinder the ability to act and I don't want to make
disgusting-looking conditional trees checking for every state I have.

Is there any way to make that happen?
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,239
Reaction score
1,231
First Language
Spanish
Primarily Uses
RMVXA
make an array with all the state IDs that can prevent action, and check for the enemy not having any.

that's actually what happens within the battle code: the manager checks for not-paralyzed, not-stunned, not-dead, etc, which are each related to a state, but since they're external methods to that check they can be made to return a check to multiple states.
if the validation implies not-any-of-these, simply gather all the IDs without any middle grouping, and compare them with the enemy.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
274
First Language
German
Primarily Uses
You could try to use this command in a conditional branch to check if a skill or item is usable:

battler.canUse($dataSkills[ID])

battler:
$gameTroop.members()[Index] for the index-th enemy in the troop (starting at 0)
$gameParty.members()[Index] for the index-th party member (starting at 0)
$gameActors.actor(ID) for the actor with the corresponding database ID

ID: Database ID of the skill
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
327
Reaction score
471
First Language
German
Primarily Uses
RMMV
@gstv87 & @Another Fen
Thanks for your replies, both of you.

I was looking for something simple and for specific cases only.
So I am going with your idea, @Another Fen.
I tested it and it seems to work like I want it to, thank you.

But while i am at it, I have some more questions for you @Another Fen

  1. Can you put multiple skills in the index and if so, how?
  2. Can you also check for skill-types (like magic, techniques etc) instead of specific skills?
  3. And how would that command look like with items instead of skills (since you mentioned that)?

I'm pretty bad at JS so I struggle with doing stuff like that myself. Sorry for bugging you :D
 
Last edited:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
274
First Language
German
Primarily Uses
One thing I forgot last time is that for the purpose of the command I posted a confused battler is still technically allowed to use all their skills (the game will just replace their actions in battle, but the player is allowed to make a party member cure their own confusion outside of combat through the skill menu for example). Complete paralysis is covered by the function though.

If you want to check for confusion too the entire command could look like this instead:
!battler.isConfused() && battler.canUse($dataSkills[ID])

1. Can you put multiple skills in the index and if so, how?
The function only allows to check for one skill at once.
However in Javascript you can always combine multiple conditions into one using && ("and"-operator, all linked conditions must be fulfilled) or || ("or"-operator, at least one condition must be fulfilled):
battler.canUse($dataSkills[12]) && battler.canUse($dataSkills[13])
would require the battler to be able to use both skill 12 and 13 to fulfill the condition for example.

If you have multiple skills to test and don't want to copy the same condition for every one of them, the recommended way to shorten it would be to use an array:
- You replace the variable part of your condition with - well - a variable (in this case the variable part would be the ID of your skill)
- Then you cycle through all the IDs you want to test, using the variable.

Arrays also have a simple way to test conditions against all their contents through either
every (all elements have to pass the condition) or
some (at least one element has to pass the condition)


The result might look a bit weird, but something like this should work:

[1, 2, 3, 11, 12, 13, 20].every(function(skillId) { return battler.canUse($dataSkills[skillId]); })

("skillId" is just the name of the variable here. It acts as a placeholder for each array element passed through the condition function and does not have to be changed)
2. Can you also check for skill-types (like magic, techniques etc) instead of specific skills?
If you want to check if a specific skill type is sealed, you can use

battler.isSkillTypeSealed(ID)

but this will only check for that specific feature, not if the corresponding skills are prohibited through other means.
If you want to check if a battler could use all or at least any skill of a specific type, you could use the array command from the spoiler above and apply it to all skills:
$dataSkills.filter(function(skill) { return skill && skill.stypeId === ID; }).every(function(skill) { return battler.canUse(skill); })

Note:
- array.filter( ... ) is a reduced array with only the elements that passed the first condition function (skills that exist and have the right skill type).
- ID should be replaced by the wanted skill type ID in the database.
- every can be replaced with some if you only need the battler to be able to use any one of the skills
- Because the $dataSkills array contains actual skill objects rather than numbers, you don't need to translate them into skills using $dataSkills[...] later in the condition functions.
3. And how would that command look like with items instead of skills (since you mentioned that)?
You can use $dataItems[ID] instead of $dataSkills[ID] for items. It's a bit uncommon to use it for enemies since those don't have their own inventory by default and would use the partys though.


(This post has become a bit Javascripty, but I hope it helps anyways^^)
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
327
Reaction score
471
First Language
German
Primarily Uses
RMMV
@Another Fen
Yes I did understand everything you said.
The array worked for me and is sufficient for keeping things organized and orderly.

I don't mind if it got Javascripty, I intend to learn it anyway at some point.

Thank you very much for your help :kaojoy:
 
Last edited:

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

Latest Threads

Latest Profile Posts

currently listening to Driftwood Gaming streaming some MZ dev time and it's delightful! had no idea they were this entertaining, love it
In quarantine, will be tested soon. This year is really something... special.
I was at another orientation yesterday and I realized I'll be working with an old friend! We met at the local water park a few years back and it was so nice to see her again! We had a chat, and next week when I officially start, I'll see if maybe we can trade our Zoom IDs so we can talk!
I made some sideview closets for MV!
You can find them in my MV resource thread.

Forum statistics

Threads
105,512
Messages
1,014,334
Members
137,198
Latest member
mmc1980
Top