Yanfly's Lunatic Damage: Apply State to Self

Hey guys.


Quick question here.... I want to apply a state to user when using an attacking skill.


On the script, I used something like this:


when /customdamage/i
          value+=a.add_state(7);(120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1);


But everytime the skill hits, it says "Nil cannot be coerced into Fixnum"


Is it possible to do this? Thanks.
That "value+=" at the beginning is the problem, because it makes absolutely no sense. The damage formula should begin with a.add_state, then it should work(haven't checkedit for other problems however)


The reason is 1) a.add_state() doesn't return a value to be added to a number and


2) += adds numbers to the variable in front of it, but if that variable doesn't exist yet it cannot work.
Hey guys.


Quick question here.... I want to apply a state to user when using an attacking skill.


On the script, I used something like this:


when /customdamage/i
          value+=a.add_state(7);(120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1);


But everytime the skill hits, it says "Nil cannot be coerced into Fixnum"


Is it possible to do this? Thanks.



Try this:

Code:
when /customdamage/i
          a.add_state(7)
          value+= (120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)
That "value+=" at the beginning is the problem, because it makes absolutely no sense. The damage formula should begin with a.add_state, then it should work(haven't checkedit for other problems however)


The reason is 1) a.add_state() doesn't return a value to be added to a number and


2) += adds numbers to the variable in front of it, but if that variable doesn't exist yet it cannot work.

So I should eliminate the " value+= "  ?
Try this:



when /customdamage/i
a.add_state(7)
value+= (120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)

Totally worked!! Thanks for helping me again, xdan! You earned another like from me!


Can you teach me how to write "if" command/ conditional branch for damage formula, please?


Its like..


when /customdamage/i


set variable x= rand (1 until 4)


if(x==1)


{


a.add_state(7)
value+= (120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)



}


else


{


value+= (120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)


}


I have zero experience in Ruby...
Spoiler
Totally worked!! Thanks for helping me again, xdan! You earned another like from me!


Can you teach me how to write "if" command/ conditional branch for damage formula, please?


Its like..


when /customdamage/i


set variable x= rand (1 until 4)


if(x==1)


{


a.add_state(7)
value+= (120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)



}


else


{



value+= (120 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)


}


I have zero experience in Ruby...



I tested your script and the game crashed, so I started changing little things until it stopped crashing. But I can't assure you it does what it should, since I don't know what it should do:

Code:
when /customdamage/i
        x = rand (4)
        if(x==1)
          a.add_state(7)
          value+= (10 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)
        else
          value+= (10 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)
        end
I tested your script and the game crashed, so I started changing little things until it stopped crashing. But I can't assure you it does what it should, since I don't know what it should do:



when /customdamage/i
x = rand (4)
if(x==1)
a.add_state(7)
value+= (10 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)
else
value+= (10 + a.atk * 4 - b.def * 2)*(b.state?(9) ? 0 : 1)*(b.state?(32) ? 0 : 1)
end

That wasn't really a script XD That's just an example of how I want it to work lol


And yes!! Your script seems to work! Thank you! I wanted the state to apply 25% of the time
That wasn't really a script XD That's just an example of how I want it to work lol


And yes!! Your script seems to work! Thank you! I wanted the state to apply 25% of the time



Then there's something about it you should know: rand (4) doesn't give 1, 2, 3 or 4, instead it gives 0, 1, 2 or 3. The script still works cause it gives 1 in 25% of the cases in both.
Then there's something about it you should know: rand (4) doens't give 1, 2, 3 or 4, instead it gives 0, 1, 2 or 3. The script still works cause it gives 1 in 25% of the cases in both.

Alright, cool! It's like array kind of thing, right?


if we declare int a[4] means a[0] until a[3] available

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-lunatic-damage-apply-state-to-self.68030/