Jump to content
Fomar0153

How to make the most of custom formulae. Part #1

Recommended Posts

I have what I think is a very simple formula, but it keeps giving me an error.

a.atk*(100/(100+b.def).to_f)

it's expecting another ')'  but I have 2 open and 2 close, so is it the .to_f that is giving me the error?

*Edit, seemed that the enemies' skill was the one with the missing  ')' not the actor, I feel silly now
Disregard me.

 

*Edit 2

 

Now it's saying that my Game_Battler code isn't working. I haven't messed with it but it is saying that

"NoMethodError occurred undefined method '>' for nil:NilClass"   on the @state_turns line.

 


  #--------------------------------------------------------------------------
  # * Update State Turn Count
  #--------------------------------------------------------------------------
  def update_state_turns
    states.each do |state|
      @state_turns[state.id] -= 1 if @state_turns[state.id] > 0
    end
  end
Edited by Rominova

Share this post


Link to post
Share on other sites

So I have this formula that is Supposed to have a 1 in 3 chance to deal a lot of damage, and else wise deal a little damage to the caster instead.

The problem is that although I get it to deal damage to itself it still deals damage to the enemy as well. I'm sure that I just forgot something in here, but I'm clueless to this sort of thing.

 

The formula is as follows:

c=rand(3); if c==1; a.atk * 3; else;d=a.mhp/10; a.hp-=d; end

 

I'll be waiting with patience. ^_^

Share this post


Link to post
Share on other sites

I also have a formula to ask, it sounds easy, but maybe does it need a script ?

 

It's an attack that deal simple HP damage (let's go with 4 * a.atk - 2 * b.def), but which also increase the user's MP by user's_level / 10. So if the user is LV3, he'll recover 3MP and deal HP damage, whatever these damage are...

I'm a beginner at formulas and not into this "if switch" or "if partymember[4]"...yet =w=

 

Thanks in advance for the help.

 

Ah and also is there a kind of page that shows all the terms usable in formula ? (from the user's attack,

to the condition that takes the value of the variable 97 divided by the variable set to 46 if actor 6 is in the party and set to 29 if actor 15 has at least 87% of health)

Edited by MaxSword

Share this post


Link to post
Share on other sites

I also have a formula to ask, it sounds easy, but maybe does it need a script ?

 

It's an attack that deal simple HP damage (let's go with 4 * a.atk - 2 * b.def), but which also increase the user's MP by user's_level / 10. So if the user is LV3, he'll recover 3MP and deal HP damage, whatever these damage are...

I'm a beginner at formulas and not into this "if switch" or "if partymember[4]"...yet =w=

 

Thanks in advance for the help.

 

Ah and also is there a kind of page that shows all the terms usable in formula ? (from the user's attack,

to the condition that takes the value of the variable 97 divided by the variable set to 46 if actor 6 is in the party and set to 29 if actor 15 has at least 87% of health)

For the Level think,I believe you juist need to use the term "Level" I may be wrong though,as for the second question,is this what you're looking for? http://www.rpgmakervxace.net/topic/8986-skill-ideas-you-can-do-with-custom-formula/

Share this post


Link to post
Share on other sites

Kind of. I must have been visiting this topic quickly once, but since it only showed at the top the basic parameters, I didn't pay attention to what was after. Thanks, the second question is fulfilled.

By the way I like your pony mod, finally something that has other characters than the provided actors by the default engine, and above all, ponies. Don't forget you can't do anything about Flootershai is best poni. By the way what script did you used to show on the main menu (with item, skills, status, save...) to show the ponies' graphic vertically and not horizontally by default ? =w=

 

Now I'm left with : how could I write a formula that heals the user's MP, but deal HP damage to an enemy ?

Share this post


Link to post
Share on other sites

Not sure if this was asked before, but is there a way to make a skill add a buff to you then after that is finished add a debuff?

Share this post


Link to post
Share on other sites

Alright, so admittedly I am new to this, and have no knowledge on scripting. That said, just by going on what I've read on this thread, I think I am doing this right. Just need a check real quick.

What I am trying to do is mimic the d20 system for physical battle without implementing a thrid party script, which I haven't been able to locate, in any event. This is what I came up with for the basic attack skill...

(rand(20) + a.luk) - b.def <= 0 ? 0 : a.atk + a.luk - 1

Where a.luk acts like a baseline strength bonus to hit for the character based on class and level or based on enemy type, and a.atk is the baseline damage based on the attack bonus given by the weapon being used(typically 1, though the exceptions are when I want 2d or 3d, or a + bonus;which is why I left it in there), or the general attack stat of an enemy. -1 to the damage due to the minimum of 1 in class Attack parameter. This formula seems to be working well as a fundemental d20 attack resolution.

Then I apply an almost identical skill attached to the weapon stating:

(rand(20) + a.luk) - b.def <= 0 ? 0 : a.atk + a.luk - 1 + rand(x)

x being the damage range of the weapon(3 for 1d4(as the baseline of 1 is already the a.atk of the weapon),5 for 1d6, etc).

Obviously, this requires I make a seperate skill for each weapon and enemy... and I gotta think there has to be an easier way, but I'm so new, I'm still trying to wrap my head around variables....

It seems to work, as far as the formula goes.  But, another problem is that while I can make the enemies use their new attack skill always, I have no such option to apply the weapon's damage automatically, and have to set the skill to Special in order for the character to be able to even use the weapon... otherwise, even though they have the weapon equipped, if they don't actively use the attack skill assigned to that weapon under the Special option to calculate the weapon's damage, and instead use the basic Attack option, they just get the base damage... it's like running around slapping baddies in the face while carrying a sword in your free hand. I tried applying the weapon skill as a state while the weapon was equipped, but the same issue arises. only now there is no option to use the weapon skill at all.

I have a feeling I'm making this a heck of a lot more complicated than it needs to be, I just can't see where I'm going wrong... any help would be appreciated.


Edit: So, yeah, I'm a bonehead.

I was, in fact, making it a whole lot more complicated than it needed to be.

((rand(20) + a.atk) - 1) - b.def = 0 ? 0 : a.atk + rand(a.luk) - 1

is the solution to a d20 system. Changed the base stat to atk, which reflects the character's strength stat based on class and strength boost items or states, or the enemy's base strength, and changed range of damage to luk. These changes are just term preferences. What's important was I was attempting to use x in the original formula to, in essence, create a term that didn't exist, that being something like Weapon Damage Range, when all I needed to do was use one of the parameters already in existence.

The way this works is an actor's attack parameter is their baseline strength damage(the -1's are there to counter the fact there cannot be an attack parameter of 0).  A weapon's Attack bonus is equivalent to the number of dice being rolled and any bonuses being applied to that roll. For instance, a weapon's Attack would be 1 if it had a damage roll of 1d6, or 5 if it had a damage roll of 2d6+3(2 for the number of dice being rolled and 3 for the +3 bonus). The luk parameter of a 1d6 weapon would be 5(a weapon's luk must always be 1 less than the desired remainder of total damage after the number of dice and any bonuses have been subtracted, due to the fact that 0 can't be rolled as a random number), giving a possible damage of 2-6, without any strength bonus.  I know that technically, it should be 1-6 damage, but I need to keep the actor's minimum luck bonus intact. If I put another -1 to account for the minimum luk parameter of 1 for actors, then that could result in a weaponless actor without any strength bonus scoring a hit on an enemy, but not effecting any damage on that enemy, and that just doesn't seem fair...lol  If anyone can think of a solution to that problem, please let me know.  For the 2d6+3 weapon, atk would be 5 and luk would be 9, resulting in 6-15 damage.

Anyway, using this method as a base attack formula for the Attack skill means that I no longer have to create a skill for each enemy and weapon in the game, and can still keep to a d20 system. It was one of those situations where I had an idea and tried to force the script to comply, rather than seeing the simple solution it had to offer right in front of me. I'm learning to let the program guide me along.... slowly...

2nd Edit... Getting 1d6 to mean 1d6(not 2d3), and working on the problem of hit chance accuracy

Ok, it took me every single character, all 100, in the formula box to do it, but this is how to implement the d20 battle system without risking having hits that result in zero damage.  There's probably an easier way, but this is how I got there...


(rand(20) + a.atk) - 1 - b.def <= 0 ? 0 : a.atk + rand(a.luk) - 2 <= 0 ? 1 : a.atk + rand(a.luk) - 2

You would set all HIT rates of actors and enemies to 100%, and remove all evasion features, as these are being determined by the formula, itself. When setting up actors and enemies, base defense should be 10. Total Armor defense on even the toughest enemies should not be much higher than 20. The formula allows to subtract 2 for the minimum atk and luk parameters of 1, but if the attack check hits and scores a result of 0 damage, it gives 1 as the result. I don't know enough yet to know if attack or luck can be brought below 0 due to states, which is why I kept the <= in there. Using this formula, if you want the weapon used to do 1d6 damage, 1 would be the attack parameter of the weapon, and 6 would be the luck paramter. A 2d6+3 weapon would be 5 attack and 10 luck.

Now, there's a problem with d20 hit accuracy using this formula, because we're taking the number of dice rolled and any bonus to damage and adding it to the base chance to hit. We could fix the hit accuracy problem by just keeping the total damage in the weapon's luk parameter. however, if you do that for a 2d6+3 weapon, you end up with a result between 1-15, when it should be 5-15, and we don't want the most powerful weapons in the game scoring damage of 1. If there were more room in the formula box, we could introduce another parameter to reflect the number of dice and damage bonus, but there isn't, at least the way I've written it.

So, what I'm doing instead is raising the defense bonuses of tougher enemies.  This presents another problem though, in that when striking an enemy with 20 def, if the actor is using a 1d weapon with no bonuses, it's impossible to hit them, even on a roll of 20.

So, this is what I need to make this system work right.

1. A way to shorten the formula so that I can add another paramter which represents the number of dice rolled and any inherent damage bonus done by the weapon.
2. A way to assure that if a 20 is rolled, there is a hit

possibly 3. I'm pretty sure I could work out both these issues on my own if I had more room in the formula box. I don't want to use third party scripts, but I will if I have to, so if anyone knows of a script that can increase the character count of the formula field, I'd appreciate being pointed in that direction.

 

Edit: random roll correction

 

Last edit, to this point.  I didn't realize when a random roll was used, it started the range at 0.  rand(6) results in a range from 0-5.  That taken into account, the actual formula I'm using now is:

 

(rand(20) + a.atk) - b.def <= 0 ? 0 : a.atk + rand(a.luk) - 1 <= 0 ? 1 : a.atk + rand(a.luk) - 1

Edited by JohnPalb

Share this post


Link to post
Share on other sites

HI! I'm trying to make a skill that will make the user lose a certain amount of HP to heal an ally. I used common events to get this to work (The user loses 30 HP to heal 90 HP + 1%) except the user can use this on themselves which I don't want. Is there a way to make it so the user can only use a skill on allies but not on themselves, or some work around?

Share this post


Link to post
Share on other sites

HI! I'm trying to make a skill that will make the user lose a certain amount of HP to heal an ally. I used common events to get this to work (The user loses 30 HP to heal 90 HP + 1%) except the user can use this on themselves which I don't want. Is there a way to make it so the user can only use a skill on allies but not on themselves, or some work around?

A conditional branch should solve that problem easily enough. I would try something like
 
If b.id==a.id;a.hp-=30;else;a.hp-=30;c=b.mhp*0.01+90;b.hp+=c;end
 
This is only a guess since I can't test it right now.Oh and in standard tier form it would look like this:
If b.id==a.id
   a.hp-=30
 else
   a.hp-=30
   c=b.mhp*0.01+90
   b.hp+=c
end

Share this post


Link to post
Share on other sites

HI! I'm trying to make a skill that will make the user lose a certain amount of HP to heal an ally. I used common events to get this to work (The user loses 30 HP to heal 90 HP + 1%) except the user can use this on themselves which I don't want. Is there a way to make it so the user can only use a skill on allies but not on themselves, or some work around?

 

By default, RPG Maker VX Ace collects all alive battle members if you declare a skill's scope to "one ally". So if you want to delete the caster from the target list of a skill, you have to modify the script.

 

The simplest workaround is to make the skill do nothing if it cast to the user, else it will recover 90 + 1% of HP:

if a==b;0;else;a.hp-=30;b.hp+=(90+0.01*b.mhp);end

Share this post


Link to post
Share on other sites

If b.id==a.id;a.hp-=30;else;a.hp-=30;c=b.mhp*0.01+90;b.hp+=c;end   <---- This one ends up in an error message when I try to use the skill

if a==b;0;else;a.hp-=30;b.hp+=(90+0.01*b.mhp);end   <---- This one heals for full mhp+90+0.01*mhp

 

I spent about half an hour fiddling with both, rearranging and trying out different things (I tried 90+0.01*b.mhp-b.mhp to get rid of the extra healing it was doing and it 

ended up doing some really weird stuff like raising the casters maximum HP to 65000 or raising the MHP of the one it was casted on to 65000.)

 

I'm only just now learning more about this formula thing so I don't really know how to pick out the problem.

 

EDIT: I found that the raising of the maximum HP to 65000(which is more like 15000) is only a graphical error and the hp is actually correctly done. But it's still an error nonetheless. >_<

Edited by HeroicCookie

Share this post


Link to post
Share on other sites

If b.id==a.id;a.hp-=30;else;a.hp-=30;c=b.mhp*0.01+90;b.hp+=c;end <---- This one ends up in an error message when I try to use the skill

if a==b;0;else;a.hp-=30;b.hp+=(90+0.01*b.mhp);end <---- This one heals for full mhp+90+0.01*mhp

 

I spent about half an hour fiddling with both, rearranging and trying out different things (I tried 90+0.01*b.mhp-b.mhp to get rid of the extra healing it was doing and it

ended up doing some really weird stuff like raising the casters maximum HP to 65000 or raising the MHP of the one it was casted on to 65000.)

 

I'm only just now learning more about this formula thing so I don't really know how to pick out the problem.

 

EDIT: I found that the raising of the maximum HP to 65000(which is more like 15000) is only a graphical error and the hp is actually correctly done. But it's still an error nonetheless. >_<

If you give me the error I can figure out what is wrong. Edited by kurashi

Share this post


Link to post
Share on other sites

Script "Game_Battler' line 352: SyntaxError occurred.

 

unexpected keyword_else, expecting $end

If b.id==a.id;a.hp-=30;else;a.hp-=30;c=b.mhp*0.01+90;b.hp+=c;end

Edited by HeroicCookie

Share this post


Link to post
Share on other sites

Script "Game_Battler' line 352: SyntaxError occurred.

 

unexpected keyword_else, expecting $end

If b.id==a.id;a.hp-=30;else;a.hp-=30;c=b.mhp*0.01+90;b.hp+=c;end

Try replacing 'else' with 'elsif'

If that doesn't work try 'elsif b.id != a.id'

Edited by kurashi

Share this post


Link to post
Share on other sites

Neither of those worked, but it's ok because I figured it out.

 

I took "if a==b;0;else;a.hp-=30;b.hp+=(90+0.01*b.mhp);end" and removed the part where it says "b.hp+=" because that part seemed

to be healing for the hp of target b. So I ended up with "if a==b;0;else;a.hp-=30;(90+0.01*b.mhp);end"

 

Pretty simple solution, I'm surprised I didn't find it earlier. Thanks for all the help guys :)

Share this post


Link to post
Share on other sites

Let's say I have a spell that does fire damage. If the spell is used by Actor 2 I want it to do damage equal to

100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25

 

If the spell is used by anyone else I want it to do

100 +a.mat*4 -b.mdf*2

damage

 

I tried the following:

 

a.id==2 ? 100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25 : 100 +a.mat*4 -b.mdf*2; 

However, every time an enemy uses the skill it does no damage to the target (the enemy has 25 MAttack and Mdefense). What am I doing wrong? I get the feeling I'm overlooking something really simple...

Share this post


Link to post
Share on other sites

 

Let's say I have a spell that does fire damage. If the spell is used by Actor 2 I want it to do damage equal to

100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25

If the spell is used by anyone else I want it to do

100 +a.mat*4 -b.mdf*2
damage

 

I tried the following:

a.id==2 ? 100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25 : 100 +a.mat*4 -b.mdf*2; 
However, every time an enemy uses the skill it does no damage to the target (the enemy has 25 MAttack and Mdefense). What am I doing wrong? I get the feeling I'm overlooking something really simple...

1.can I see a screenshot of this skill in the database?

2.have you tried using it with another actor?

3.what manages Variable 85?

4.what are your 2nd actor's attributes?

Edited by kurashi

Share this post


Link to post
Share on other sites

I did some more testing, and at the end of it all I have to ask: Is it possible for a skill to check if the user is an Actor or an Enemy, and do different damage based on that?

 

I created a new project (with no scripts), added a third type of skill called "Elemental", and used Eric and Natalie for testing (their stats are the default ones, without a single change). The testing event increases variable 85 by 2 before the battle and as expected Natalie does more damage with the skill than Eric because she's Actor 2 and so gets extra damage from the skill. However, an enemy using the skill deals no damage with it.

 

The formulas I tried:

a.id==2 ? 100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25 : 100 +a.mat*4 -b.mdf*2;

- The same as above, but with Variance set to 0

100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25 
100+a.mat*4-b.mdf*2+(a.id==2?v[85]*25:0)
(a.id==2?$game_variables[85]*25:0)+100+a.mat*4-b.mdf*2
100+a.mat*4-b.mdf*2+(a.id==2?25:0);

The only one that works for both actors and enemies is the one that does not check if a.id==2. All the other formulas work for actors, but not for enemies (i..e enemies using the skill do no damage).

 

I know I can just copy the skill and have the copy used by enemies, but I wanted to see if there's a way to make the skill usable by both enemies and actors while at the same time giving Actor 2 increased damage based on a variable.

 

P.S.: The test enemy using the skill has 25 Attack, Defense, Magic Attack and Magic Defense.

post-14621-0-78237200-1374311843_thumb.jpg

Edited by shadowblack

Share this post


Link to post
Share on other sites

@shadowblack

 

OK, I was on steam and just received a reply that told me basic what I'm sure you already figured out: the actor id reference is the problem. The reason for this is the fact that the monsters are not associated with an id. Kind of odd, but that is the reason why it won't work. I think their is a way to check, but I may be thinking about a script I was reading before. If so then the script would be useless to you because it was used to reference values of the monsters for a battle system.

 

Sorry I couldn't help more. If you wan't to look at the steam post it is as follows:

steamcommunity.com/app/220700/discussions/0/864973955142337095

Edited by kurashi

Share this post


Link to post
Share on other sites

I see. Well, thanks anyway. At least I learned a bit more about working with formulas. :)

Share this post


Link to post
Share on other sites

(a.class == Game_Actor && a.id == 2) ? 100 + a.mat * 4 - b.mdf * 2 + $game_variables[85] * 25 : 100 + a.mat * 4 - b.mdf * 2

 

somehow this formula works.

  • Like 1

Share this post


Link to post
Share on other sites

there's no method id declared for Game_Enemy

 

add this method on Game_Enemy

 

def id;return @enemy_id;end

  • Like 1

Share this post


Link to post
Share on other sites

Thank you both!

 

Both ideas seem to work, but heartbreak61's means less things to write in the formula bar and thus less chance for me to make a mistake, so I'll use that one.

Share this post


Link to post
Share on other sites

Scenario: I think it has been done already, but the White Wind spell (heals HP equal to the caster's HP) from the FF games would be an HP recovery skill with the formula "a.hp"

 

That's true. I'm trying to implement the white wind spell into my game, but I run into a problem. It seems that a.hp gets updated after each actor has been healed. So I thought.. hmm this could do the trick

if a.id==b.id ; a.hp ; else ; a.hp*0.5 ; end

But then I run into the problem of if the caster does not get the full benefit of his own heal, the other party members will get reduced heals.

ie. the caster has 100/150 hp uses white wind, caster heals 100 hp, next member heals 150*0.5 = 75 hp.

 

Then again, another problem with this code is I am assuming the caster is in slot number 1.

Help!

 

Edit: I've also thought of making a temporary variable in the formula box "c = a.hp", but then c gets updated after each heal as well.

Edited by xShinryu

Share this post


Link to post
Share on other sites

 

Scenario: I think it has been done already, but the White Wind spell (heals HP equal to the caster's HP) from the FF games would be an HP recovery skill with the formula "a.hp"

 

That's true. I'm trying to implement the white wind spell into my game, but I run into a problem. It seems that a.hp gets updated after each actor has been healed. So I thought.. hmm this could do the trick

if a.id==b.id ; a.hp ; else ; a.hp*0.5 ; end

But then I run into the problem of if the caster does not get the full benefit of his own heal, the other party members will get reduced heals.

ie. the caster has 100/150 hp uses white wind, caster heals 100 hp, next member heals 150*0.5 = 75 hp.

 

Then again, another problem with this code is I am assuming the caster is in slot number 1.

Help!

 

Edit: I've also thought of making a temporary variable in the formula box "c = a.hp", but then c gets updated after each heal as well.

if @temphp==nil;@temphp=a.hp;end;if @temphp!=a.hp && a.id==b.id;@temphp=a.hp;end;@temphp

 

 

I did some more testing, and at the end of it all I have to ask: Is it possible for a skill to check if the user is an Actor or an Enemy, and do different damage based on that?

 

I created a new project (with no scripts), added a third type of skill called "Elemental", and used Eric and Natalie for testing (their stats are the default ones, without a single change). The testing event increases variable 85 by 2 before the battle and as expected Natalie does more damage with the skill than Eric because she's Actor 2 and so gets extra damage from the skill. However, an enemy using the skill deals no damage with it.

 

The formulas I tried:

a.id==2 ? 100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25 : 100 +a.mat*4 -b.mdf*2;

- The same as above, but with Variance set to 0

100 +a.mat*4 -b.mdf*2 +$game_variables[85]*25

100+a.mat*4-b.mdf*2+(a.id==2?v[85]*25:0)

(a.id==2?$game_variables[85]*25:0)+100+a.mat*4-b.mdf*2

100+a.mat*4-b.mdf*2+(a.id==2?25:0);

The only one that works for both actors and enemies is the one that does not check if a.id==2. All the other formulas work for actors, but not for enemies (i..e enemies using the skill do no damage).

 

I know I can just copy the skill and have the copy used by enemies, but I wanted to see if there's a way to make the skill usable by both enemies and actors while at the same time giving Actor 2 increased damage based on a variable.

 

P.S.: The test enemy using the skill has 25 Attack, Defense, Magic Attack and Magic Defense.

c = 100 + a.mat * 4 - b.mdf * 2;if a.actor? && a.id == 2;c += v[85] * 25;end;c

Edited by Xypher
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted