Make Enemies cast revive 'smart'?

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
In battle sometimes enemies cast "revive" even when there is no fallen enemy on the field. This obviously looks pretty dumb.


I was looking for some option/conditional in the database to only cast it when another enemy is dead. But the only option I had for conditions is whenever the enemy itself has the state "death" applied. That's no good.


This must be a common issue I guess. How did other people solve it?
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
The selection process for enemies is fairly random with weight only given toward the 'value' of the action. See Game_Enemy#make_actions, Game_Enemy#select_enemy_action, Game_Enemy#action_valid?. An easy way to solve this problem is to have Game_Enemy#action_valid? return false if the action only targets dead allies and there are no dead allies. You could do the same in this method for any action that predicts an empty target group, as such an action probably shouldn't be valid.


You can also use a similar process to the already existing actor auto battle to make enemies more carefully select their actions (See: the method chain from Game_Action#evaluate, Game_Actor#make_action_list, and Game_Actor#make_auto_battle_actions). These assign a weight to actions based on predicted effectiveness.
 

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
640
Reaction score
353
First Language
English
Primarily Uses
RMMV
Let's say a Priest enemy can resurrect Soldier enemies, and you have a troop with one Priest and two Soldiers.

You could do a troop page that does "When the end of the turn," set to "turn" span, and it checks if enemy 2 or enemy 3 has the death state applied. If so, it could apply a dummy state (no icon, no name) to the Priest, or perhaps could turn on a switch called "UseRevive." If neither of the Soldiers have the death state applied, then remove the dummy state from the priest or turn the switch off. Then, in the Priest enemy's action patterns, set the ability "Revive" to require the condition that the dummy state is applied or the switch is on.

This will basically make it so that the Priest can only use revive if, at the end of the previous turn, one of the soldiers was dead.
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
Ah okay. I couldn't imagine that we had to use scripts for this. Especially because Raise is build-in whenever you start a new project.

But those methods helped me a lot and with that info I created a quick-fix (not fully tested but so far it works, just set "Raise"-skill priority to 10):

#sb:nap_smart_raise [battle]=beginAuthor: NapoleonVersion: 1.00About: Now enemies only use the revive/raise skill when there is at least one       dead ally on their side.License: CC0 or Public DomainThanks: Mithran=end$imported ||= {}$imported[:nap_smart_raise] = 1.00#===============================================================================# Game Enemy#===============================================================================class Game_Enemy < Game_Battler  #-----------------------------------------------------------------------------  # Skill Conditions Met?                                                [ALIAS]  # Only cast raise/revive and such when atleast one ally is actually dead.  #-----------------------------------------------------------------------------  alias nap_smart_raise_skill_conditions_met? skill_conditions_met?  def skill_conditions_met?(skill)    nap_smart_raise_skill_conditions_met?(skill) &&    (!skill.scope.between?(9, 10) || $game_troop.dead_members.length > 0)  endendAbout using battle-event-pages, I rather not use a loop to check for every enemy if all other enemies are dead anytime you perform a skill and then flip a switch and then check that switch.
 
Last edited by a moderator:

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
640
Reaction score
353
First Language
English
Primarily Uses
RMMV
Probably the scripting solution is going to be simpler, but you misunderstand what I'm suggesting - I'm not saying to call a common event via a skill every time it's used. In the enemies tab, where you assign skills, you can set action patterns to have conditions for use. The default is "always," but you can also make them only use it every certain number of turns, at a certain percentage of HP, etc. You can make an enemy only use a particular skill if a certain switch is on or a certain state is applied - in which case, if you didn't want to do scripting, you could just make a troop event page that either applies the state or turns on a switch if an enemy is killed. You wouldn't be checking the switch or checking every enemy every time a skill is used, it would be checked once a turn via the troop event.

However, as I mentioned, the script will be simpler and less time-consuming.
 
Last edited by a moderator:

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
Ooooh. I totally forgot about that. You can indeed set it in the database. Still a good tip :)
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,787
Reaction score
939
First Language
Chinese
Primarily Uses
N/A
(As an excuse to promote my script)Maybe my targeting ai script combined with some battle events can help here:

http://forums.rpgmakerweb.com/index.php?/topic/24892-doublex-rmvxa-targeting-ai/

Talk about battle events first. Their aim is to check if any enemy died as it's pointless for enemies to cast revive to their allies when they're all alive.

First use a game switch with id x used for checking this only. It's true if and only if as least 1 enemy died. Enemies need this switch to be true to cast revive.

Then use a battle event page with the below code or something like that(conditional branches also work):

$game_switches[x] = $game_troop.dead_members.size > 0 ? true : falseFor the default RMVXA battle system, setting its span as turn should be enough. If it's to be checked right after each action though, you can use the below trick:

1. Set its condition as Switch [y:] is ON

2. Set its Span as moment

3. Add "Call Common Event: Event B" at the bottom of this battle event page

4. Set game switch y as off in Event B

5. Add "Common Event [Event A]" to the effects of all skills reviving or killing enemies

6. Set game switch y as on in Event A

Now right after those skills are used, Event A will be called which flips game switch y on, thus calling the above battle event page. When that battle event page calls Event B, game switch y will be flipped off and thus stopping that battle event page. This causes that battle event page to be called once right after every use of those skills.

Now talk about my targeting ai script. Here its purpose is to cause enemies to only target the dead when they cast revive if there's any and the revive targets a single ally. Details can be found in my scripts :D

Casting revive to an alive ally is still pointless even when there's at least 1 dead ally. It seems to me that it's nearly impossible to control how enemies pick targets without create significant side effects if no custom scripts are used XD

Combining the above should cause enemies to cast revive only if there's at least one dead enemy(checked by that battle event page) and when that's the case, they only cast revive on their dead allies(done by my script).

I think such revive behaviour is smart enough as at least the revives aren't wasted :)
 
Last edited by a moderator:

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
I just noticed that if you can cast raise only on dead party members (when the player tries to use that same skill on an alive party member he get's an error beep) then this check should have been in RPG Maker Ace by default right? Because the enemies by default cast raise on ALIVE allies even though you explicitly stated in the database that it only works on "dead allies".

I do consider this to be a minor bug (which can be solved by one line of code, literally w/o the alias) from RPG Maker Ace.

@DoubleX:

Mmm I only need it for the raise/revive. I rather not add a medium/large script to the project just to accomplish that but thanks for mentioning it.
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,787
Reaction score
939
First Language
Chinese
Primarily Uses
N/A
I just noticed that if you can cast raise only on dead party members (when the player tries to use that same skill on an alive party member he get's an error beep) then this check should have been in RPG Maker Ace by default right? Because the enemies by default cast raise on ALIVE allies even though you explicitly stated in the database that it only works on "dead allies".

I do consider this to be a minor bug (which can be solved by one line of code, literally w/o the alias) from RPG Maker Ace.

@DoubleX:

Mmm I only need it for the raise/revive. I rather not add a medium/large script to the project just to accomplish that but thanks for mentioning it.
Now that I checked the issue again and I found that my script isn't even needed at all. Battle events alone would suffice. Enemies should always cast revive on their dead allies if there's any in the default RMVXA setting.

I though it was needed as I encountered some really weird cases that enemies cast revives on one of their alive allies even when there's at least 1 dead enemy. The default RMVXA shouldn't work like that so maybe my cases were due to some custom scripts(maybe one of mine :) ) changing how game actions pick targets. So at the end, a big part of my above reply ended up being a complete joke :D

P.S.: I think your fix is the best one as that's the root cause of the entire issue. That way no battle events are even needed for this.
 
Last edited by a moderator:

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,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top