Solid Enemy Action Script

rapiermother

RapierMother
Member
Joined
Apr 9, 2014
Messages
29
Reaction score
4
First Language
English
Primarily Uses
Hey all,
 
What I'm looking for is a script that slightly adjusts how the game processes enemy actions, and allows for conditions to be typed in the notes. Sounds like a lot of the existing scripts out there, but I'm looking for something with a bit more predictable behaviour.
 
If I have something like this for one of my enemies:
 

Action Patterns:

Skill Condition R———————————————————————————Heal Spell    Always    1Fire Spell    Always    1Attack        Always    1Notes:

<action:1>hp < 25%;rand(100) < 75;</action><action:2>rand(100) < 25;</action>then I'd like for it to use the given Ruby script inserted into the tags as conditionals for the given conditions, much like other scripts. But the key is the behaviour. With the above example, I'd like for the following to happen:

If the enemy has <25% HP, there is a 75% chance it will cast the heal spell and a 25% chance the next action on the list will be considered

If the enemy has >= 25% HP, there is a 25% chance it will cast the fire spell, and a 75% chance of the next action (Attack). This means (among other things) that the enemy will never cast the heal spell with high HP%.

The key here is the behaviour. I want the game to look at the top enemy action on the list first, regardless of what its assigned rank or condition within the editor. I want it to only evaluate the Ruby script condition(s) input into the enemy's notes. If one or more of those conditions is false, I want the game to check the next action on the list the same way, and so on.

Essentially, I want the actions on the list to be evaluated from top to bottom, like program code. This script would enable anyone to make the enemy AI system work just like the gambit system for ff12 (for example), as well as solving a key issue in my current project.

Please help!
 

rapiermother

RapierMother
Member
Joined
Apr 9, 2014
Messages
29
Reaction score
4
First Language
English
Primarily Uses
Well simply put, I haven't been able to find anything that processes enemy commands that way. What I mean is, if the conditions for command 1 are true, then it will always be executed without exception; otherwise, if the conditions for the second command are true, it will always execute (until the condition becomes true for the first command). Just like the gambit system, or a do loop that contains only an if statement that has a number of elseif clauses.

Where I have yet to see success is the consistency. Ive used a couple of scripts to try to achieve this goal, but essentially, I get 'misbehaviour', like the enemy in the above scenario casting the heal spell while already at full HP.

As yet, every script I've seen so far uses a numerical rating system to assign relative probabilities to each command. Where my request strongly varies is that I want to do away with that concept, and simply process them from top to bottom in the list of enemy actions, based on their conditons alone. If I want to increase or decrease the likelihood a command will be used, I could do that with conditions.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
As yet, every script I've seen so far uses a numerical rating system to assign relative probabilities to each command. Where my request strongly varies is that I want to do away with that concept, and simply process them from top to bottom in the list of enemy actions, based on their conditons alone. If I want to increase or decrease the likelihood a command will be used, I could do that with conditions.
What have you seen so far?
 
Last edited by a moderator:

rapiermother

RapierMother
Member
Joined
Apr 9, 2014
Messages
29
Reaction score
4
First Language
English
Primarily Uses
@Engr. Adiktuzmiko: That script looks fantastic, but I don't seem to be able to get it to work. I have attached a shot of the enemy setup in question. The enemy in question seems to perform the action patterns on the left as normal, rather than the instructions on the right. I pasted your script into the materials section.

What have I done wrong here?

Untitled.png
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
@Engr. Adiktuzmiko: That script looks fantastic, but I don't seem to be able to get it to work. I have attached a shot of the enemy setup in question. The enemy in question seems to perform the action patterns on the left as normal, rather than the instructions on the right. I pasted your script into the materials section.


What have I done wrong here?
Nothing...


It was a problem with the script itself, there was something wrong with the set-up that could cause A LOT of problems (luckily Tsukihime noted that it was crash/error prone so I got to realize it)


I needed to change the tags, it will now be


<ruby_actions>


formula


<end_ruby_actions>


Get the updated script and it should work fine now. :)
 
Last edited by a moderator:

ShadowLurk

Tanoshii~
Veteran
Joined
Feb 14, 2014
Messages
226
Reaction score
53
Primarily Uses
The editor's default action list will pick possible actions with the highest rating, with cutoff of 3. For example, when you set Healmore's rating to 4 and leave everything else 1, the enemy will always use Healmore whenever possible, only when it became impossible then will it consider other actions. You just need to set Healmore's condition to 0~25%. For extra conditions, just use Hime's Action Condition script.

With the default rating system, you can make at most four distinct stages like these (10, 7, 4, 1).
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
The difference between Action Conditions and this "action selection condition" request is that the action conditions filter out what can or cannot be used, and the action selection condition actually picks what can be used.


The default project does have an action selection condition, except it's basically "pick a random valid action", using the priority/rating as the weights. Of course, given that only actions with a priority difference of up to 3 are considered valid, they all pretty much have equal chance to get picked anyways.


If you wanted Heal to be used only when the enemy's HP is less than 50%, you can do that easily using the built-in action. Now, if you wanted the chance of the enemy to use heal to be proportional to the amount of HP it has relative to its max HP, you can't, cause you can only filter out actions based on priority and booleans, and then when it comes time to determine whether an action can be selected, it's a random pick.


However, as you mentioned, it is somewhat possible to accomplish this using action condition formulas.


Suppose if I have 10% HP, then I want 90% chance to cast heal. I write a simple formula that will grab the ratio and do some math to give me 90%.


I would then bump this priority to 10 and then make everything else less than 7. This way, 90% of the time I will only cast heal since that's the only valid action, and 10% time is something else.


Now this is nice for simple cases, but what happens if I multiple conditions? Then you really need to simply go and directly assign conditions to whether the action will be selected or not.


Adik's decided to just ignore action list completely, which works I suppose, but if anything that's like choosing not to use something that is perfectly usable, especially if we want to start talking about database refactoring where a piece of code simply goes through all database and event objects and changes ID's accordingly. Not going to happen with note-tags.


I think the priority system is useful and should be used in conjunction with selection conditions, simply because it provides an easy way to filter out actions that you don't want.
 
Last edited by a moderator:

rapiermother

RapierMother
Member
Joined
Apr 9, 2014
Messages
29
Reaction score
4
First Language
English
Primarily Uses
@Engr. Adiktuzmiko: The new version of your script works flawlessly, and accomplishes exactly what I need. I have to thank you for not only taking the time to write the script, but to tweak it and monitor its success!

@Shadowlurk: Your "excerpt from RPG Maker's help file" probably belongs in a tutorial thread rather than this one; I'd say it's pretty clear that everyone involved in this conversation is fully well aware of the information you posted. Thanks anyway, though—help is always appreciated.

@Tsukihime: I appreciate the breakdown of how the engine makes decisions. I have to say though, in this case, I don't think i can really use the priority system... and here's why:

  •In the above-listed example, there are two cases: HP<19, and HP >=19.

  •In the HP<19 case, there should be an exactly 75% chance of Healmore being used, 6.25% chance of Hurtmore, and an 18.75% chance of Attack.

  •In the HP >= 19 case, there should be a 0% chance of Healmore, a 25% chance of Hurtmore, and a 75% chance of Attack.

I just don't see how the priority system can handle this, because there are two different cases. One solution I considered was having a second copy of each enemy that has different actions, and using troop events to switch the versions out for each other during battle based on HP level (only enemies under 25% maxHP should cast Heal spells). That works in a way (without the percentages being correct), but it's far more work than pasting 43 lines of script so thoughtfully perpared by Engr. Adiktuzmiko!

Thanks to everyone who contributed!
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
@Hime - well I could surely just fetch the usable ones from the list, it's just that I'm a fan of giving them full control (and responsibility over that control)... Plus since they'll be using the script anyways, I think it's better to just keep it all to 1 set-up rather than put up the skills and set-up priorities and such on the default method then adjust them on the tags...


I could always make a version that uses the database if the need arises (or if I get motivation for that one).
 
Last edited by a moderator:

ShadowLurk

Tanoshii~
Veteran
Joined
Feb 14, 2014
Messages
226
Reaction score
53
Primarily Uses
@rapier - I think this setup with Hime's action condition script will do the same.

Code:
Healmore  0~25%   10Hurtmore  Always  7Attack    Always  4
Code:
<action condition: 1>rand < 0.9</action condition><action condition: 2>rand < 0.25</action condition>
Although, Shana's script does allow direct control to action selection behavior.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,570
Latest member
fgfhdfg
Top