Ultima01

Unhinged
Veteran
Joined
Mar 13, 2013
Messages
69
Reaction score
11
First Language
English
Primarily Uses
N/A
I've been having problems with this script snippet I devised for a friend.  Said friend wanted enemies to react to getting hit with specific elements, but only if they dealt damage.  So I came up with the idea of making them react to a switch that's thrown in response to a spell dealing damage.

I've tested it, and found that the snippet nulls instead the damage outright.  Can someone help me figure out what's wrong?

 

class Game_Battler < Game_BattlerBase  def no_damage?(a, b, base_dmg, atk_mod, def_mod, switch_id)    c = ( base_dmg + ( a.atk * atk_mod ) - ( b.def * def_mod ) )    if c > 0      $game_switches[switch_id] == 1      return c    else      return 0    end  endendScript call in damage formula: 

Code:
c = no_damage(a, b, int, int, int, int); c
 

Ultima01

Unhinged
Veteran
Joined
Mar 13, 2013
Messages
69
Reaction score
11
First Language
English
Primarily Uses
N/A

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,317
Reaction score
11,738
First Language
English
Primarily Uses
RMVXA
CtelinAjira, please do not bump your topic unless it has been 72 hours later since your last post. You can review our forum rules here. Thank you.

Not only do you have to take into account differing time zones, different work/leisure schedules and the fact that everyone answering here is doing it in their free time and have other commitments as well, today is also the last day of IGMC and a lot of people are having to focus on that.  The 72 hour buffer is there for a good reason.
 

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
I'm pretty sure the $game_switches[id] returns a true/false.

$game_switches[switch_id] == 1 this line would then do absolutely nothing, and in Ruby, quite possibly return the nothing.  If you said, $game_switches[switch_id] = 1, you would still be doing it wrong I think.

$game_switches[switch_id] = true, would be correct.
 
Last edited by a moderator:

Ultima01

Unhinged
Veteran
Joined
Mar 13, 2013
Messages
69
Reaction score
11
First Language
English
Primarily Uses
N/A
I'm pretty sure the $game_switches[id] returns a true/false.

$game_switches[switch_id] == 1 this line would then do absolutely nothing, and in Ruby, quite possibly return the nothing.  If you said, $game_switches[switch_id] = 1, you would still be doing it wrong I think.

$game_switches[switch_id] = true, would be correct.
I've made these changes, and it still doesn't do everything just right.  It's still nulling the damage.

Code:
class Game_Battler < Game_BattlerBase  def no_damage?(a, b, base_dmg, atk_mod, def_mod, switch_id)    c = ( base_dmg + ( a.atk * atk_mod ) - ( b.def * def_mod ) )    if c > 0      $game_switches[switch_id] = true      return c    else      return 0    end  endend
 

Xypher

Veteran
Veteran
Joined
Apr 1, 2012
Messages
148
Reaction score
26
Primarily Uses
try 

Code:
c = a.no_damage?(a, b, int, int, int, int); c
 
Last edited by a moderator:

Ultima01

Unhinged
Veteran
Joined
Mar 13, 2013
Messages
69
Reaction score
11
First Language
English
Primarily Uses
N/A
Last edited by a moderator:

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
I should suppose you changed those 'int' to some value, right?
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,200
Reaction score
849
First Language
Hungarian
Primarily Uses
RMVXA
Add a 'p c' line above the 'if c > 0' line (without the apostrophes).


Observe your console when you use a skill, it will print out the result of your formula.


If that formula is 0 or lower (and it most probably is), than your formula returns a lower value than you expect, which is possible if the enemy's DEF is high, and/or if the actor's ATT is too low, depending on the modifiers you use.


But if you simply write this into the damage box (random arguments):

no_damage?(a, b, 100, 1.5, 1.2, 888)It will not run, because the damage formula itself is run on the RPG::UsableItem::Damage instance, and NOT on the battler. But that class got no 'no_damage?' method defined, so it returns 0 with a rescue instead of crashing. You can test this with the 'p c' line I mentioned above. The console will not print anything when you use the skill in this case.
But if you write this:

a.no_damage?(a, b, 100, 1.5, 1.2, 888)Now, this will be run on Game_Battler, so it will not fail, but it can still return a value lower than 0. You will see the result of the damage formula printed out in this case, because the method has been executed.
Also you don't need to write the 'c = formula; c' thing. You method returns a number already, so no need to store and return that number again.
 

Latest Threads

Latest Posts

Latest Profile Posts

The problem with being a perfectionist is that you are never done with something.
Our Lore Wizard, Buttercup, just emailed me a draft of one of our in-game lore books, and it's one of my favorites so far. Her books are really bringing a vibrant history to Evergloom!

I've posted it under a spoiler tag called 'A study in 43rd Century Poetry' in our development thread!
Whoops, the corner of my map is as big as GALV's whole demo map xD
wops.PNG
A little more of the CMS. #rm2k #DestinyPatch
QUhhNBK.gif
StarkSnow wrote on DisguisedCrows's profile.
Hello.

Forum statistics

Threads
112,324
Messages
1,067,347
Members
145,951
Latest member
shirako
Top