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.
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.
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
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
Can you put multiple skills in the index and if so, how?
Can you also check for skill-types (like magic, techniques etc) instead of specific skills?
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
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])
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:
("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)
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:
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.
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^^)
I'm wondering if I may be putting too many things into one map. A story, within a story, within a story . . . it's fun, but I can't shake the feeling that it may be better to scrap some of it, and use it for another map. I'm not sure what to do.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.