How do I do the following?

I need help finding out how to do the following:

1. have a character gain a stat buff when an opponent has a certain ailment, ex: DEF up when enemy is paralyzed.

2. day and night cycle.

3. stacking ailment effect, ex: when an enemy is hit by a poison-llike ailment, the ailment stacks like a debuff but deals more damage each turn the more it stacks.
2) you can event it or use a script
For the first one, you need to check if the enemy has a particular state, then add the buff, then do whatever damage you want.  So, using state 7 (paralysis) the damage formula would look like this.

b.state ? (7) ? a.add_buff(x, y); a.atk * 4 - b.def * 2

x is the param id; y is the number of turns that the buff should last.  I have used the default damage formula as an example, but you do whatever you want.

EDIT

In case you are unsure about the param ids, here they are

0 = mhp
1 = mmp
2 = atk
3 = def
4 = mat
5 = mdf
6 = agi
7 = luk
@ksjp17

how exactly do I apply that buff formula? do I have to apply it through a skill? or common events?
3) Just use a stacking states script?

Here's one: http://forums.rpgmakerweb.com/index.php?/topic/14110-stacking-states/ but there are others.
That goes in the damage formula of your skill, so that when the character with that skill attacks an enemy, the skill checks to see if the enemy is afflicted with paralysis.  So as you want a DEF up buff, this is what it would look like.  I am using the example of the buff lasting 2 turns.

b.state ? (7) ? a.add_buff(3, 2); a.atk * 4 - b.def * 2
That goes in the damage formula of your skill, so that when the character with that skill attacks an enemy, the skill checks to see if the enemy is afflicted with paralysis.  So as you want a DEF up buff, this is what it would look like.  I am using the example of the buff lasting 2 turns.

b.state ? (7) ? a.add_buff(3, 2); a.atk * 4 - b.def * 2
I was gonna do it like a passive effect, you know, like the game detects the state then just triggers the buff automatically.
*bump*
MonkeyWrench, 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.
1. You can do what Ksjp17 reccommended but that will apply to one skills formula field. Is you want the buff to occur every time paralyzed is used I would look for a script or you could make a common event and insert it in to the battle script of each fight that will assign a variable to the state and then check for it and assign a buff upon a positive check of the variable. Maybe like a rework of Hime Skill Link script that is works on states so when one is applied it would run <link state: ID> instead of skill.

2. Basic Game Time + Night/Day v1.6.2 by Script by: V.M of D.T, http://daimonioustails.weebly.com/, or a nice tutorial on this is here.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-do-the-following.43205/