Help with damage formula

So I am trying to make my own attack -defence system and on the regular attack I have this formula

attB = a.atk + a.agi ; rol = 1 + rand(20) + attB ; if rol > b.def ; 1 + rand(4) ; else ;0 ; end; #or I write it like this... attB = a.atk + a.agi ; rol = 1 + rand(20) + attB ; rol > b.def ? (1 + rand(5)) : 0 However I want to be able to change the rand(4) to Rand(6) when the player holds a Rapier or shortsword weapon and then to rand(8) if he equips a Longsword or Morningstar etc. (there are other things I want to do as well)
I know how to do this, however the Damage formula line restricts me to a specific number of characters.

So how can I make the damage formula run a script?

Then how can I return the value from the script?

I really need your help...

EDIT: Even though the question I ask at this post is answered, I encounter a problem with the formula... So my problem continues here : http://forums.rpgmakerweb.com/index.php?/topic/40773-problem-with-a-script/
Code:
#==============================================================================# ** Game_Battler#==============================================================================class Game_Battler < Game_BattlerBase  # You can change 'name_of_action' to whatever you want, just be sure to change  # the name of the method in the skill damage formula field.   def name_of_action(user, target)    attB = user.atk + user.agi    rol  = 1 + rand(20) + attB    # Enumerate user's weapons    user.weapons.each { |wpn|          case wpn.id        when 1 # Hand Axe          @wpn_dmg = (1 + rand(4))        when 2 # Battle Axe          @wpn_dmg = (1 + rand(6))        when 3 # Bardiche          @wpn_dmg = (1 + rand(8))#        when X # Etc ...#          @wpn_dmg = (1 + rand(X))        else          # If weapon is none of the above          @wpn_dmg = (1 + rand(5))      end            }    # Returns value to the skill damage formula    return rol > target.def ? @wpn_dmg : 0  endend # Game_Battler
Then you can toss that into the damage formula of the skill :

Code:
a.name_of_action(a,
EDIT: Oop, missed the part about the weapon. One moment ...
You can put functions into scripts and then call the functions from the damage formulae if the functions are made for a specific module/class, but you'll have to wait for a scripter to give the exact names.

Additionally you can shorten the function to gain more space like this:

Code:
1 + rand(20) + a.atk + a.agi > b.def ? (1+rand(4)) : 0
Edit: ninja'd
Do I have to place it in the Game_Battler script or can I make it an empty script page ?
NEVER place any script inside another one, they ALWAYS go into separate script slots.


If you have to edit an existing script, you'll be specifically told to do so.
But in this case it is a method of Class -> Game_Battler. 
 

So the damage formula can call a method from any script ? 
Glad to hear it. I didn't want to change the existant scripts...
I updated scriptlet in my previous comment. Kind of meh, but it will work. Just place it in a blank script slot underneath '▼ Materials' in your script editor.
I was going to do something like this for weapons 
 

weaponDmg = (1 + rand(4)) if user.weapons.include?($data_weapons[1])weaponDmg = (1 + rand(6)) if user.weapons.include?($data_weapons[2])#etc But I like your way more.... There is also space for comments next to the weapon... 
It would be much better If it was with weapon categories however ( it would take less time to enumerate , but anyway thanks )

Seems like my problem is solved
Probably a better way than assigning an instance variable for weapon damage, but I am bouncing around between whatnots and went with what worked easily. But, it will work fine. However, it is not dual-wield friendly in its current version ... as the last detected weapon will set the variable and change the damage, not add to it.
Maybe I will call the categories in a same way and have a category named special , with Unique - Legendary weapons, and have the damage selected based to weapon Id only on those with the special category... Somehow like this 

# Enumerate user's weapons@wpn_dmg = 1 + rand(6) if user.weapons[1].wtype_id == 1@wpn_dmg = 1 + rand(8) if user.weapons[1].wtype_id == 2@wpn_dmg = 1 + rand(10) if user.weapons[1].wtype_id == 3@wpn_dmg = 1 + rand(12) if user.weapons[1].wtype_id == 4#...if user.weapons[1].wtype_id == 16 # category with specials... user.weapons.each { |wpn| case wpn.id when 101 # Special Weapon 1 @wpn_dmg = (3 + rand(18)) when 102 # Special Weapon 2 @wpn_dmg = (1 + rand(6)) when 103 # Special weapon 3 @wpn_dmg = (1 + rand(8))# when X # Etc ...# @wpn_dmg = (1 + rand(X)) end }endI don't plan on having dual wield on the game... Is it allowed on default? 
There is still a problem ... 
When I keep the weapon enumerations  no sides can deal damage. 
when I comment them out, only the enemies can deal damage. 

I can't understand why this is happening. Maybe it has to do with the a and b and user and target thing....

Original thread: https://forums.rpgmakerweb.com/threads/help-with-damage-formula.40772/