Hello everyone,
I was just trying to make a script for a custom damage formula but it is not working at all. What I made is this:
class Game_Battler < Game_BattlerBase def fire_retaliation(a, b, v)#=======================================================#What I need is something to check a state on the target#and inflict damage on the user if the state is active.#======================================================= if b.state?(26) if a.hp>v a.hp-=v #if v value is not enough to kill the user it deals normal damage else a.hp=1 #if the user HP are too low then they are set to 1 end end return v endendI just put this below "Material" in the script window and I call the script in the formula box using:
v[30]=50; a.fire_retaliation(a, b, v[30]); v[30]This is the only script I am using so it cannot be a compatibility related issue.
I feel like I am missing something obvious...
EDIT: if i write it in the formula box it works, but it needs too many characters to use it in skills with complex formulae.
r=Y; if b.state?(X) (a.hp-=r; if a.hp==0 a.add_state(1); end); end; rI ran tests with Y=50 and 0% variance.
This formula is written manually (I didn't use copy-paste) since I don't have the project with me at the moment. It is possible it contains typos.
So I should change the script to this:
class Game_Battler < Game_BattlerBase def fire_retaliation(a, b, v) #======================================================= #What I need is something to check a state on the target #and inflict damage on the user if the state is active. #======================================================= if b.state?(X) #X is a place holder a.hp-=v if a.hp==0 a.add_state(1) #this way the user is inflicted with death state when reaching 0 HP end end endendand then call it with
v[Y]=skill_dmg; fire_retaliation(a, b, v[Y]); v[Y]but you told me that calling it into the formula box isn't safe. Is this because I eventually apply death state to the user before the skill takes place?
Ok, now I am home and I ran few tests. What I wrote was wrong since I actually used $game_variables[30] and not $game_variables(30) so that part was correct.
I changed a.hp-=v[30] to a.hp-=v but it is still not working. No error message at all, It just deals 0 damage to both, user and target.
One other thing I just noticed: I don't think you can set a variable's value using v[Y] in your skill formula; you can only read the value with that shortcut. Use the full $game_variables[Y] in that first segment. v[Y] is fine in the final segment.
Besides that... not sure. You could run a common event as part of the skill to check the value of the variable and see if that's set correctly. You could also throw garbage like Audio.se_play('MakeItFail') inside parts of your code in the script editor - if your game throws an error, you'll know that part of the code is being hit. This can help you detect which parts of your code are being hit properly and which aren't.
v is the entire game variables array, not a single element.
a.hp -= v does not make sense. It should be a.hp -= v[30].
You also need it to RETURN a value. That's what a damage formula is all about - getting some input, doing some calculation, returning the damage amount. Because you're not returning anything, it's 0.
That won't work.
You should put this into your damage formula:
v[30]=50; a.fire_retaliation(a, b, v[30]); v[30]Notice the a. before your custom method, that is needed there.
The damage formula is calculated in an RPG::UsableItem:😀amage instance, and NOT in the Game_Battler instance, so without that a., your formula would crash the game if not for that 'rescue 0' line at the end of the formula eval.
Whenever you try to use a custom method made in Game_Battler in your damage formula, you must use the method on a Game_Battler instance, which will be the user here, I guess.
a -= v is correct in the method, since 'v[30]' is the argument passed for the method.
And yes, there should be a number returned, but I guess that will be the variable itself (v[30])
Another thing to note, if the user dies before the skill execution, the game will crash. At least that is what happened when I last tested it. You can simply leave at least 1 HP for the user all the time, so it can't die, but still damages the user if above 1 HP.
Ohh, and on a final note, why do you use a variable in the formula? You set it right at the start of the formula, so it will always be the same. You can simply put a 50 there instead of a variable value.
Yes, you only need to add that line in the damage formula (the 'a.fire_retaliation(a, b, Y)' line), where the 'Y' is the damage formula itself (or any simple numeric data).
You return the damage value at the end, so it will get a numeric data.
I just tested your custom method this way, and it works fine for me.
Well, then I really don't know where the problem is...I am still not able to run it correctly. The custom method is not being hit at all, and now I used the "a.fire_retaliation(a, b, Y)" line for the skill, using 50 as Y value.
As I said I am not using custom scripts so it should not be a compatibility related issue. Really, I am totally clueless...
EDIT: Shame on me...I forgot to save changes before testing...now it works. Thank you all for your help. This is solved for me
How do you know it's not running?
Add a:
p "something descriptive here"line in your custom method after each line.
Change that "something descriptive" to something... descriptive, so that you know on which line are you at the moment.
If you see all or some of them triggering on your console, than the damage formula is being executed, but the enemy can still neglect the damage.
Test it and see what happens.
I knew it was not running because I added a sound after each line. Anyway I just forgot to save changes, that's why it was not working. I saved them and now it works fine.