Hibernation skill

Hello. I have a skill called "Hibernation", and it's supposed to make the user fall asleep for 3 turns. If any amount of damage is dealt to him during his sleep, he will wake up and receive the Stun and Disoriented debuffs. However, if he manages to finish his hibernation successfully, all of his basic stats (ATK, DEF, MAT... all of them except HP, MP, EVA and HIT) will be boosted by +50% for 4 turns.


How can this be done? I have no idea how to do it. Thanks in advance.
I think that in order to pull this off, you'll need Yanfly's Buff and States Core.  Start by adding a new state, which we'll call Hibernating.  It can't be the same as a generic sleep state, since that would function differently, but you can use similar qualities in the database.  Fading after 3 turns is important for this to work correctly.  Also, DON'T remove on damage in the database; we'll do that another way.


You'll also need a second state, which for our purposes, we'll call Well-rested.  This state should contain traits that buff your stats once the Hibernation fades.  You'll probably want it to fade after battle, as well as have a turn fade.


The skill itself should simply add the Hibernation state to the user.


The key is going to be what you put in the Hibernation state's note box.  It should look something like this:


<Custom Respond Effect>


if (value > 0) {


   target.addState(Stun ID);


   target.addState(Disoriented ID);


   target.removeState(Hibernation ID);


}


</Custom Respond Effect>


<Custom Leave Effect>


user.addState(Well-rested State ID);


</Custom Leave Effect>


The respond effect will trigger if damage occurs on the target.  The value conditional will ensure that the code will ONLY work if damage is taken.


The leave effect will ONLY trigger if the Hibernation state expires from time, NOT from taking damage.


EDIT:  I just now realized that you're using VX Ace, not MV.  Unfortunately, I didn't use that version enough to know of a script that could accomplish this.  Sorry about that...
Hello there. There are few ways to achieve this. One is scripting, the other one is using troop events (of course you can achieve it mixing the two methods as well).


Explaination: why the script works the way it does.


Read this if you're interested in the logic behind the script. It doesn't explain everything but it is still something.

Spoiler
You'll also need a second state, which for our purposes, we'll call Well-rested.  This state should contain traits that buff your stats once the Hibernation fades.  You'll probably want it to fade after battle, as well as have a turn fade.



As @shockra said this part will stay the same for VX Ace, you need that state to boost your actor stats. Also, the part where you DO NOT remove the state when damage is taken stays the same.


The tricky part comes when you have to handle the Hybernation state itself. If you want to do it using a script then you have to add a check for that state to the method used to evaluate attacks. This way you can remove the Hybernation state and add stun and disoriented states. The following one should do the trick but since it's late here and I am quite tired I couldn't test it. It is now tested and working.



The script is in the spoiler.

Spoiler
module HHS

HIBERNATION = 26 #change this to be the id of your Hibernation state.
# Default is 26.
STUN = 8 #change this to be the id of your Stun state.
# Default is 8.
DISORIENTED = 27 #change this to be the id of your Disoriented state.
# Default is 27.
WELL_RESTED = 28 #change this to be the id of your Well-rested state.
# Default is 28.
HIBERNATION_CNT = 5 #change this to be the duration of the Hibernation state
# in turns. Default is 5.
# NOTE:
# When writing your state IDs remember to NOT use leading zeroes.

end

#===============================================================================
# WARNING: DO NO CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU'RE DOING!
#===============================================================================

class Game_Battler < Game_BattlerBase

attr_reader :hibernation_cnt

alias hhs_execute_damage_old execute_damage
alias hhs_add_state_old add_state
alias hhs_on_turn_end_old on_turn_end

def execute_damage(user)
hhs_execute_damage_old(user)
check_hibernation
end

def check_hibernation
if state?(HHS::HIBERNATION)
remove_state(HHS::HIBERNATION)
add_state(HHS::STUN)
add_state(HHS:😀ISORIENTED)
end
end

def add_state(state_id)
hhs_add_state_old(state_id)
if (state_id == HHS::HIBERNATION)
@hibernation_cnt = 0
end
end

def on_turn_end
state?(HHS::HIBERNATION) ? (@hibernation_cnt += 1) : (reset_hibernation)
hhs_on_turn_end_old
if (!state?(HHS::HIBERNATION)&&(@hibernation_cnt == HHS::HIBERNATION_CNT))
add_state(HHS::WELL_RESTED)
reset_hibernation
end
end

def reset_hibernation
@hibernation_cnt = nil
end

end

class Scene_Battle < Scene_Base

alias hhs_terminate_old terminate

def terminate
hhs_terminate_old
all_battle_members.each do |battler|
battler.reset_hibernation if battler.alive?
end
end

end



INSTRUCTIONS:


Paste this code in your project below "Material" then follow the instructions at the beginning of the script.


COMPATIBILITY:


It is tested and works with YEA Battle Engine. Other compatibility issues are unknown.


Here is a very boring way to add disoriented and stun state. Since the script works it is now in the spoiler. This part is boring and unfinished. If you can please avoid using it.

Spoiler
If you are not familiar with scripts and you want to achieve it using troop events then you should do something like this:

  1. Let your skill store current hp value in a variable (you can do it using the skill formula or a common event, up to you).
  2. Create a battle event that runs at the beginning of each turn and compares current hp values of the battler with the hybernation state with the stored one. If the current value is lower than the stored one that means your battler took damage and then you should remove the hybernation state and add the stun and disoriented states.

However, even if this may sound easier, it is not. At least not if you don't want to use ruby at all. Achieving something like that using event commands is incredibly long and tedious. If you can go the script way then go for it, if you can't then try to use a script call, if you can't then use the long and boring way.



I hope this helps you.


P.S. Let me know if the script works. If it doesn't I can correct it when I have time and send you a working one.


I will modify this post if I have to fix this code. This means the code displayed in this post is the last version.
 @shockra  No matter, thanks anyway.


@Heirukichi, sorry but that script isn't working... I changed the ID to the according ones in the database, I added a skill that gives the user the Hibernation state, and the state Well-rested was also added, but when he gets hit he just wakes up, not receiving the Stun and Disoriented states. Also, for some reason it conflicts with other scripts; I'm using Yanfly's Battle System, and when I install your script all attacks result in a NULL popup, without the attack sound nor the screen shaking, even though the damage is still dealt.


Also, I still don't know how to give the user the Well-rested state after he finishes hibernating. I mean, even if the script worked well, and he woke up after receiving damage and suffered the Stun and Disoriented debuffs, he would still not receive the buff even if he finished his hibernation successfully.


I'm thankful for your help, but if a skill of this nature is sorta complicated to implement, then I guess I will have to create another one...
@Uzi_Man I tested it with YEA Battle Engine and it works for me in a clean project. It does both: removing the hibernation state AND adding the stun and disoriented states. In a clean project with just that one and YEA Battle engine it also shoes proper popups.


About the Well-rested state it is my fault, I totally forgot about that. However here is a tested and working version of the script. I changed few things so that it has less compatibility issues with other scripts.

Spoiler
module HHS

HIBERNATION = 26 #change this to be the id of your Hibernation state.
# Default is 26.
STUN = 8 #change this to be the id of your Stun state.
# Default is 8.
DISORIENTED = 27 #change this to be the id of your Disoriented state.
# Default is 27.
WELL_RESTED = 28 #change this to be the id of your Well-rested state.
# Default is 28.
HIBERNATION_CNT = 5 #change this to be the duration of the Hibernation state
# in turns. Default is 5.
# NOTE:
# When writing your state IDs remember to NOT use leading zeroes.

end

#===============================================================================
# WARNING: DO NO CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU'RE DOING!
#===============================================================================

class Game_Battler < Game_BattlerBase

attr_reader :hibernation_cnt

alias hhs_execute_damage_old execute_damage
alias hhs_add_state_old add_state
alias hhs_on_turn_end_old on_turn_end

def execute_damage(user)
hhs_execute_damage_old(user)
check_hibernation
end

def check_hibernation
if state?(HHS::HIBERNATION)
remove_state(HHS::HIBERNATION)
add_state(HHS::STUN)
add_state(HHS:😀ISORIENTED)
end
end

def add_state(state_id)
hhs_add_state_old(state_id)
if (state_id == HHS::HIBERNATION)
@hibernation_cnt = 0
end
end

def on_turn_end
state?(HHS::HIBERNATION) ? (@hibernation_cnt += 1) : (reset_hibernation)
hhs_on_turn_end_old
if (!state?(HHS::HIBERNATION)&&(@hibernation_cnt == HHS::HIBERNATION_CNT))
add_state(HHS::WELL_RESTED)
reset_hibernation
end
end

def reset_hibernation
@hibernation_cnt = nil
end

end

class Scene_Battle < Scene_Base

alias hhs_terminate_old terminate

def terminate
hhs_terminate_old
all_battle_members.each do |battler|
battler.reset_hibernation if battler.alive?
end
end

end



I tested it while having this script BEFORE YEA Battle Engine.


Of course since I tested it in a fresh project with just that one and YEA Battle Engine I cannot guarantee that there are no compatibility issues with other scripts you're using.
I tested it, and now there are no compatibility problems with YEA Battle Engine. Maybe it was conflicting with another script, but it doesn't anymore. I also figured that he wasn't receiving the Stun and Disoriented states when he received damage while hibernating because "Remove on Damage" on the Hibernation state was marked. Should've read that part better, sorry. After unmarking it, he wakes up after being hit and receives the debuffs correctly.


However, when he finishes hibernating, the user does receive the Well-rested state, but it keeps being added to him indefinitely... what I mean is that the message "wakes up feeling stronger" keeps looping in each turn, and the state never wears off.


I tried the script on a clean project and the same thing occurred. Here are some pics in case it helps:


1.png


2.png


3.png


4.png
That was also a mistake I made while writing the script. However while I was going to correct that part I also found another mistake that could create situations where, after succesfully reciving the Well-rested state once, every time your character was going to use the Hibernation skill again it would immediatly trigger the Well-rested state.


Here is the final result:

Spoiler
module HHS

HIBERNATION = 26 #change this to be the id of your Hibernation state.
# Default is 26.
STUN = 8 #change this to be the id of your Stun state.
# Default is 8.
DISORIENTED = 27 #change this to be the id of your Disoriented state.
# Default is 27.
WELL_RESTED = 28 #change this to be the id of your Well-rested state.
# Default is 28.
HIBERNATION_CNT = 5 #change this to be the duration of the Hibernation state
# in turns. Default is 5.
# NOTE:
# When writing your state IDs remember to NOT use leading zeroes.

end

#===============================================================================
# WARNING: DO NO CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU'RE DOING!
#===============================================================================

class Game_Battler < Game_BattlerBase

attr_reader :hibernation_cnt

alias hhs_execute_damage_old execute_damage
alias hhs_add_state_old add_state
alias hhs_on_turn_end_old on_turn_end

def execute_damage(user)
hhs_execute_damage_old(user)
check_hibernation
end

def check_hibernation
if state?(HHS::HIBERNATION)
remove_state(HHS::HIBERNATION)
add_state(HHS::STUN)
add_state(HHS:😀ISORIENTED)
end
end

def add_state(state_id)
hhs_add_state_old(state_id)
if (state_id == HHS::HIBERNATION)
@hibernation_cnt = 0
end
end

def on_turn_end
state?(HHS::HIBERNATION) ? (@hibernation_cnt += 1) : (reset_hibernation)
hhs_on_turn_end_old
if (!state?(HHS::HIBERNATION)&&(@hibernation_cnt == HHS::HIBERNATION_CNT))
add_state(HHS::WELL_RESTED)
reset_hibernation
end
end

def reset_hibernation
@hibernation_cnt = nil
end

end

class Scene_Battle < Scene_Base

alias hhs_terminate_old terminate

def terminate
hhs_terminate_old
all_battle_members.each do |battler|
battler.reset_hibernation if battler.alive?
end
end

end



I edited my first post so it is easier to find for people who come here looking for a similar script.
That works perfectly, thanks!


Just one more question... can use it for multiple skills? For example, there is equipment in the game that adds new skills, and one of them is an improved version of Hibernation, which makes him sleep for 2 turns instead of 3. So there would be two versions of Hibernation states in the game: the normal one which lasts 3 turns, and the bonus one which lasts 2 turns. Using your script, is there a way to differenciate between these two skills? This part is secondary though. You already helped me a lot.
Well, that script doesn't allow something like that because when I wrote it you didn't mention something like that. However I can write a bigger version of the script that allows multiple skills to do something like that. I'll post here when it's ready.
I understand. I completely forgot to mention that I needed it for multiple skills.

Original thread: https://forums.rpgmakerweb.com/threads/hibernation-skill.73330/