Skill formula doesn't work for enemy characters

(This "bug" was found using a modification to the basic combat system, using Yanfly battle system -> http://yanflychannel.wordpress.com/ )

I'm having some trouble with sklls in general, when used by enemies.

All skills I'm currently using are kinda like this:

"Wasp Eye Kick"

c = (1+rand(20)) + a.atk; if c> b.luk; c=(1+rand(1)+a.mat) else c=0; end; c

Where "atk" would be a "accuracy" stat and "luk" a "target number to be hit" (or Armor, for simplicity sake).

When a player character uses the skill, it works perfectly.

When a enemy tries using the same skill, they simply "miss" the attack.

I've tried checking and changing the stats of all the parties involved. I tried giving the playing characters low luk scores and even tried raising the atk stat of the enemies to really high numbers (My test was an 150 missing a 10 luk target).

What exactly is the problem? Does it has to do with Yanfly system and I'm out of luck? Is there something obvious over the regular, vanilla combat system that I didn't take in consideration?
c = (1+rand(20)) + a.atk; if c> b.luk; c=(1+rand(1)+a.mat) else c=0; end; c
Please check if there is a typo - 1+rand(1)+a.mat as written in your post would always be the same as 1+a.mat, because rand(1) would always be zero after rounding.

One possible reason for this error might be that problem with float being cut-off when converting to integer.
Please check if there is a typo - 1+rand(1)+a.mat as written in your post would always be the same as 1+a.mat, because rand(1) would always be zero after rounding.

One possible reason for this error might be that problem with float being cut-off when converting to integer.
Thank you for catching that! I didn't even realize the typo.

Anyway I tried the skill and it works exactly like it should work for playing characters, however enemies just miss.

Here are the stats:

Enemy

MHP 8 

MMP 0

Atk 12

Def 2

ATM 1

DFM 10

Agi 1

LUK 10

 

vs

 

PC

MHP 12

MMP 0

Atk 8

Def 2

ATM 1

DFM 10

Agi 2

LUK 9

 

 

The PC character hits more often than not, but there is still a possibility for it to miss.

However the Enemy character -always- misses. 

 

Where lies the problem?

 

EXTRA INFO:

"ATM" deals with damage as evidencied with that particular formula, while "DEF" deals with damage reduction (irrelevant for us at the moment since this skill ignores def). DFM is not used for anything, AGI is used as it is with the vanilla rpg maker and the LUK stat became the "armor" stat.

 

One possible reason for this error might be that problem with float being cut-off when converting to integer.
 

If this is happening, it's happening exclusively with the "enemy side" of the battle. Is there anything I can do to fix it? Try using/coding something that expands on formulas so it doesn't get cutoff? I though the vanilla formula calculation system could handle this, since it's working so well for PCs.
Which formula fails?


It is important to remember that certain properties are only available to actors, such as levels or equips.
Which formula fails?

It is important to remember that certain properties are only available to actors, such as levels or equips.
This exact formula works for PCs but apparently doesn't work for "enemy" type characters:

c = (1+rand(20)) + a.atk; if c> b.luk; c=(1+rand(1))+a.mat else c=0; end; c

When a PC uses a skill with this particular formula, he has a chance to miss or hit first, then damage is calculated.

When a enemy uses said skill, it always misses, no matter how high I make their "atk" stat.

Is there anything in said formula that is exclusive to actors? If so, what can I actually use from the stats for "enemy" type characters in a formula?

After consulting the help file provided with the program, I couldn't find said list.

It does however asigns some pretty "in stone" uses for parameters such as 

"

Luck LUK Affects chance of adding state or debuffing a parameter "

Is it ok for me to try to mess it around using the vanilla system and asigning formulas to parameters as I see fit or I should try this formula using a script that adds/replaces the basic parameters because the parameters as "if" already have specific functions tied to them?
One way to debug damage formulas is to explicitly call methods from the formula

Code:
class Game_Battler  def custom_formula(a, b, v)    a.atk * 4 - b.def * 2  endend
And in the formula you call it like

Code:
a.custom_formula(a, b, v)
Then you can insert print statements to check what it's actually doing.
your formula still doesn't make much sense.

I suggest that instead of writing that mathematical formula, you describe what you want the skills to do - that way we can check if your logik is correct, because I think you made a mistake in the logic area, not in the mathematical area.

And you should use different variables for your plans, variable names that display your intention - especially because the use of the variable switches from an accuracy to a damage value - different values should be storedin different variables to prevent logic mistakes...

Edit:

And you still haven't corrected the mistake that I pointed out earlier - the rand(1) part is still useless, that's the main reason why I think that you have a logical error in your formula.

your formula still doesn't make much sense.
Here is the logic, please feel free to point any mistakes:

Instead of using the built in ex-parameter  "accuracy" system for the rpg maker vx ace, I tried to create my own based on tabletop gaming in the sense that there is a visible parameter that is a static number instead of a per cent value for the attack to hit. Hence: For the skill to "hit" and "cause damage", first a number between 1 or 20 is generated, then the user "atk" is added. If said number is superior to the foe's "luk" stat, damage occurs. Said damage is a number between 1 or 2, plus their "mat" stat.

c = (1+rand(20)) + a.atk; if c> b.luk; c=(1+rand(1))+a.mat else c=0; end; c

I'd love for you to explain to me what is wrong with the formula, if the logic I'm using does actually work or if I should just try to play around with the ex-parameters,

I do however, found out what is the problem and I wish to apologize to all of you. 

See, when I was creating new enemies to test a couple different skills, i forgot to actually GIVE them any ex-parameters! Because I though I already had devised a "to hit" system, I completely forgot that the RPG Maker Engine is built in to use said ex-parameters! So just by adding a "100%" accuracy rate to the enemy character, the skill worked as intended. 

I made a really noobish mistake so I'm sorry for wasting your time. I do however would like to hear the problems with this formula system I'm trying to use before the thread lock, if possible.
There are two things that I consider problematic in that formula:

1) the use of c as a variable with two functions

I would suggest rewriting that as

hc = (1+rand(20)) + a.atk; if hc> b.luk; dam=(1+rand(1))+a.mat else dam=0; end; damwhere hc stands for hit-chance and dam for damage

this way there is less chance of getting the wrong number if you make a typo in a formula that uses c for two functions and rewrites c several times.

2) the use of rand(1)

OK, here I need to say that I'm a programmer, but haven't checked how ruby's randomizer behaves.

But in many other languages, the result of the randomising function switches if the function is called with an argument of 1

rand(20) would result in an integer ranging from 0, 1, .., 18, 19

rand(1) would result in a float ranging from 0.0, 0.1x, ..., 0.999x, 1.0

If rand(1) in ruby gives only the two single results of 0 and 1, each 50% of the time, then your formula would work as intended.

But in other programming languages, rand(1) would return a float value that could be anything between 0 and 1, rarely getting the 1 as a result.

If my assumptions about the return value of rand(1) in ruby are correct, then that result would be cut down to zero by float-to-integer-conversion almst all the time.
If my assumptions about the return value of rand(1) in ruby are correct, then that result would be cut down to zero by float-to-integer-conversion almst all the time.
I was aware of every bit of information thanks to the informative thread we got here about formulas, however I didn't realize the float-to-integer issue. Thank you for opening my eyes, I'll have to rework the entire stat system from scratch with this in mind.

The "hc" change will be put to the test, I'll see which one returns more consistent results but I think your formula is just more neat. 
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/skill-formula-doesnt-work-for-enemy-characters.20559/