Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Expanding on the FFX Battle Algorithms

Greetings all, once again. This time, I'm messing with battle algorithms.

I made the changes noted in this thread (http://www.rmxp.org/forums/index.php?topic=3862.0) to make physical, magical, and healing damages work as they do in FFX. So far, so good.

However, when I was doing some testing, using some of the stats from the original game to test it against (I replaced teh Ghost stats with those of the Sinscale, using the FFX STR for STR, AGI for AGI, EVA for DEX, and MAG for INT). Based on these, in FFX, you have a low level enemy (the first you face in the game, actually) that should do a decent amount of damage.

What you get instead is a enemy that can't hit the broadside of a barn.

I had assumed when I made the changes that they would affect both sides of the fight... now I wonder if this is so.

Is there only the one set of algorithms in the base setup, or is there one each for the party and for enemies? If my original assumption was correct, what changes do I need to make to get the proper return values for enemies attacking?

Or, perhaps, is this just affecting damage calculations, and NOT to-hit numbers? If this is so, an explanation of how this should work would be appriciated as well.
 
You can use  method  .is_a?(Game_Enemy) to check whether the object you're calculating the battle algorithm with is an enemy or one of your party member.

And according to the thread you gave, I think it modifies only the damage calculation part.
^ ^;;

The default script check attack result twice, the first time it is determined by the attacker's weapon hit rate
Code:
 hit_result = (rand(100) < attacker.hit)

Then , the second time, the result is determined by the target's evasion, speed and the attacker's dexterity
Code:
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)

Just modify these two parts to get the result that you want. :)  I hope this helps.
 
Indeed, it does, and confirms what I had come to suspect. Which means that I need to figure out how to modify the to-hit statements. I know HOW I want it determined, I'm just unsure how to go about it. I'm trying to interpret the two middle lines of code, hoping they'll make it obvious to me what needs to happen... IE the "hit = self.damage < 0 ? 100 : 100 - eva" line, and the one below... specifically, what the ? and : mean in RGSS.

What I BASICALLY want is an algorhythm that directly compares the attacker and defenders Accuracy (DEX) and Evasion (AGI), and then, depending on the differance, set a different "to-hit" percentage. Roughly, it would look like...

rate = attacker.dex - self.agi
if rate <= 0
(random number 0 - 100) < 25, then hit.

And then variations of that for a given differance. Any help on this front, or at least an explanation of the few lines of code in the base hit detection area, would be great.
 
Mmmm, I remember reading what that meant before, but I haven't used it in a long time, so I'm not sure.

If I'm correct,

Code:
 hit = self.damage < 0 ? 100 : 100 - eva

Is the same as

Code:
if self.damage < 0
    hit = 100
else
    hit = 100 - eva
end
 
Ok, so If/Then statements.

*mind starts to boggle* Ok, I'm trying to figure this out on the fly then. To make this work, then, in the same fashion as the FFX hit detection, I need about eight If/Thens, all relating to what the "to-hit" number would be. Follow my reasoning if you can, and tell me if it looks right... I'd rather not screw up the scripts before I have something remotely workable.

Code:
eva = attacker.dex - self.agi # Attacking DEX (Accuracy) - Defending AGI (Evasion)
   hit = self.damage < 0 ? 100 : 100 #If damage to attacker is less than 0, hit = 100. Else... (Not sure what should go here.)
   hit = eva <= 0 ? 25 :  # If EVA <= 0, then hit = 25.
   hit = eva == 1 ? 30 :  # If EVA = 1, then hit = 30.
(Etc. Etc. to set different values...)
   hit = self.cant_evade? ? 100 : hit # If defender cannot evade, set hit = 100, else "hit" (does that really make sense??)
hit_result = (rand(100) < hit) # If Random Number 0-100 is less than Hit, results in a hit to defender.

Aside from one or two points I'm still not clear on (look at the comments), this looks like it MIGHT work to me, but I'm not certain.

For comparison, the template in FFX was Accuracy - Evasion. Result of this was using in a chart, like thus:

0 (or less) - 25%
1 - 30%
2 - 30%
3 - 40%
4 - 40%
5 - 50%
6 - 60%
7 - 80%
8+ - 100%

Am I even close on the scripting?
 
I don't think you need eight if-then statements, just put it in to an array like this

Code:
hit_check_array = [25,30,30,40,40,50,60,80,100]

and then you can have
Code:
if self.damage < 0 
 hit = 100
else
  eva > 0 ? eva = [8,eva].min : eva = [0,eva].max
  hit = hit_check_array[eva]
  hit = self.cant_evade? ? 100 : hit
end
  hit_result = (rand(100) < hit)

I think this would be easier to edit and to come back and read later too : )
 
I think I follow... my only question at this point is this. Looking at the code you generated there, it all makes sense to me with two exceptions.

First, an array like you generated is great, but there are going to be results that are less than zero and greater than 8... does that line with the .min and .max handle that eventuality, or should I put in another pair of lines to cover that? (IE, eva >=8 ? 8 : eva and eva <= 0 ? 0 : eva)

Second, looking at the min/max line you have, it looks to me like the values are reversed... you have the 8 with the min and the 0 with the max... is that right? 0 would create the 25 percent chance and 8 the 100 in the system I set up. That line looks like it's reversing that.

Also, poking around in the code again, I'm seeing two places for hit detection. First Hit and Second Hit. All of this so far has centered around Second Hit. So please, if you know, whats up with there being two Hit determinations, how they relate to each other, and will I have to change the First Hit to match the Second Hit if I want only one kind of Hit calculation?

Some additional explanation would be great. Thanks for the help thus far.
 
This code actually handles the problem you address : )
Code:
eva > 0 ? eva = [8,eva].min : eva = [0,eva].max

It means that if eva is greater than 0 then you don't want it to be greater than 8
thus you'll choose the minimum number between whatver "eva" is and "8" so if eva is less than 8, then it'll choose eva. But once eva becomes greater than 8, it'll choose 8 no matter what. The same goes to if eva is less than or equal to 0.  The code will choose the maximum number between 0 and eva. So you don't have to worry about negative number, since it'll choose the maximum one, which is always 0.

As for the two hit checks, you can just delete this
Code:
    # First hit detection
    hit_result = (rand(100) < attacker.hit)
    # If hit occurs
    if hit_result == true

and ONLY ONE LINE in this
Code:
      # Second hit detection
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end  #<=== !!!!!DELETE ONLY THIS LINE!!!!!!

The second hit detection is in the if statement of the first hit detection, so just pull it out and delete the if statement.

I hope my explanation help make you understand the code better. Good luck!
 
It did indeed enlighten me... after a few tests (hardly anything in depth yet, but...) everything looks to be working as required. I wound up finding the hit rates for skill attacks as well and altered them (though that was simple, as all Magic attacks hit in FFX, as I recall). Thanks to all who assisted.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top