- Add Review
- Subscribe
- Nominate
- Submit Media
- RSS
Artificial Intelligence
- Rhyme
- 04/08/2011 06:32 PM
- 2846 views
Garden is boring so I'll share some tricks~
RMVX's auto battle is most times silly and unreliable.
So I decided to try and fix that.
First, I need to make my own AI, but I'm not that much of a scripter to be able to code advanced stuff like that, so a workaround is in order.
I decided to make my partner's AI the same way I make enemy AI:
This not only allows me to control it's behavior to an extent, but it also allows the AI to be a little more wary of his/her own status instead of mindlessly using the highest damage skill over and over. His/her actions will change according to how much Hp/Mp he/she has, and whether a state is active, or what turn he/she is on, etcetera. Much more control than previous AI, much more flexibility, much more character.
Now for the more difficult part: Using an Enemy's behavior for an Actor.
This goes a bit into Scripting, so don't hurt me :<
Game_Actor has something called "def make_action" to determine it's action for Auto-Battle actors.
Game_Enemy also has that method! However, it's different than the one on Game_Actor.
What I first did was copy over the Enemy's method to Actor's method.
def make_action
@action.clear
return unless movable?
available_actions =
rating_max = 0
for action in enemy.actions
next unless conditions_met?(action)
if action.kind == 1
next unless skill_can_use?($data_skills)
end
available_actions.push(action)
rating_max = .max
end
ratings_total = 0
rating_zero = rating_max - 3
for action in available_actions
next if action.rating <= rating_zero
ratings_total += action.rating - rating_zero
end
return if ratings_total == 0
value = rand(ratings_total)
for action in available_actions
next if action.rating <= rating_zero
if value < action.rating - rating_zero
@action.kind = action.kind
@action.basic = action.basic
@action.skill_id = action.skill_id
@action.decide_random_target
return
else
value -= action.rating - rating_zero
end
end
end
But this brings up a problem: the definition tries to find "enemy".
Which is averted by adding:
after the line
ENEMY_AI_ID being the ID of the Enemy you used to store AI in.
Now the method looks for "conditions_met?". This is much easier:
I copied the entire
method from Game_Enemy and pasted it in Game_Actor.
It didn't seem to require any modification!
After that, assuming that everything has gone correctly, we now have smarter AI!
It's actually an effective workaround!
RMVX's auto battle is most times silly and unreliable.
So I decided to try and fix that.
First, I need to make my own AI, but I'm not that much of a scripter to be able to code advanced stuff like that, so a workaround is in order.
I decided to make my partner's AI the same way I make enemy AI:
This not only allows me to control it's behavior to an extent, but it also allows the AI to be a little more wary of his/her own status instead of mindlessly using the highest damage skill over and over. His/her actions will change according to how much Hp/Mp he/she has, and whether a state is active, or what turn he/she is on, etcetera. Much more control than previous AI, much more flexibility, much more character.
Now for the more difficult part: Using an Enemy's behavior for an Actor.
This goes a bit into Scripting, so don't hurt me :<
Game_Actor has something called "def make_action" to determine it's action for Auto-Battle actors.
Game_Enemy also has that method! However, it's different than the one on Game_Actor.
What I first did was copy over the Enemy's method to Actor's method.
def make_action
@action.clear
return unless movable?
available_actions =
rating_max = 0
for action in enemy.actions
next unless conditions_met?(action)
if action.kind == 1
next unless skill_can_use?($data_skills)
end
available_actions.push(action)
rating_max = .max
end
ratings_total = 0
rating_zero = rating_max - 3
for action in available_actions
next if action.rating <= rating_zero
ratings_total += action.rating - rating_zero
end
return if ratings_total == 0
value = rand(ratings_total)
for action in available_actions
next if action.rating <= rating_zero
if value < action.rating - rating_zero
@action.kind = action.kind
@action.basic = action.basic
@action.skill_id = action.skill_id
@action.decide_random_target
return
else
value -= action.rating - rating_zero
end
end
end
But this brings up a problem: the definition tries to find "enemy".
Which is averted by adding:
enemy = $data_enemies[ENEMY_AI_ID]
after the line
def make_action
ENEMY_AI_ID being the ID of the Enemy you used to store AI in.
Now the method looks for "conditions_met?". This is much easier:
I copied the entire
def conditions_met?(action)
method from Game_Enemy and pasted it in Game_Actor.
It didn't seem to require any modification!
After that, assuming that everything has gone correctly, we now have smarter AI!
It's actually an effective workaround!
Posts
Pages:
1
GUYS auto-battle can be awesome now.
Artificial Intelligence Story #1
Just a while ago, I was testing my second boss. He killed me, leaving my AI friend to fend for himself. He was being smashed to the ground without me healing him.
The boss missed an attack. It was his chance. I called out to him "Attack!" "Do it now!"
He used Soul Cleanse (Heal 100% Sp in exchange for 50% Hp)
The boss slammed him to the wall, leaving him with ~200 Hp. I was anxious. We're going to lose.
It's his turn again. He mustered up the last of his strength to Heavy Slash him. Good! Defeat him and win!
It missed. The boss looked at him and clawed him down. I thought he would die.
Left with ~10 Hp (from a max of 2000 mind you), he uses up the last of his Sp to cast Life on me. Running out of Sp, he died, saving me.
Artificial Intelligence Story #1
Just a while ago, I was testing my second boss. He killed me, leaving my AI friend to fend for himself. He was being smashed to the ground without me healing him.
The boss missed an attack. It was his chance. I called out to him "Attack!" "Do it now!"
He used Soul Cleanse (Heal 100% Sp in exchange for 50% Hp)
The boss slammed him to the wall, leaving him with ~200 Hp. I was anxious. We're going to lose.
It's his turn again. He mustered up the last of his strength to Heavy Slash him. Good! Defeat him and win!
It missed. The boss looked at him and clawed him down. I thought he would die.
Left with ~10 Hp (from a max of 2000 mind you), he uses up the last of his Sp to cast Life on me. Running out of Sp, he died, saving me.
author=ldida1
Yes, turn this into a tutorial. Battles that only involve the computer fighting... here i come!
Yeah, that sounds like shit loads of fun...
Pages:
1