Tsukihime 1,489 Posted October 8, 2012 (edited) Effect: Mana Shield -Tsukihime This script adds "Mana Shield" effect to a state. When this effect is active, all damage will be directed to the battler's MP. If the battler has no MP, then HP damage will be inflicted as usual. This handles boundary cases where the amount of damage to be absorbed by MP is greater than the battler's current MP and the difference will be inflicted as HP damage. Download Script: Download here Required: Effect Manager (you will need the latest version that does not remove states upon death) Usage Tag your state with <eff: mana_shield x> Where x is the amount of damage absorbed by MP, as a percentage.By default it is 100%, which means you will try to use as much MP as you can. 50% means you will only use half your MP to absorb damage. 200% means each point of MP can absorb 2 points of damage. Edited February 28, 2016 by Tsukihime 2 Share this post Link to post Share on other sites
Ashern 8 Posted October 9, 2012 Thanks for this, nice script! Share this post Link to post Share on other sites
ZombieSchematic 0 Posted November 20, 2012 So I was trying to create skills like Lesser Shell and Major Shell. Lesser would only absorb 50% of the damage and Major would absorb 100% I just can't get the 50% to work I've tried <eff: mana_shield 0.5>, <eff: mana_shield 0.05>, <eff: mana_shield 0.50>, <eff: mana_shield 50> None of them seem to work it always absorbs 100%. Share this post Link to post Share on other sites
Tsukihime 1,489 Posted November 20, 2012 You need spaces after mana_shield. Share this post Link to post Share on other sites
ZombieSchematic 0 Posted November 20, 2012 Ha, wow, sorry that was a typing error on my part. I do put spaces <eff: mana_shield 0.5> it looks like that. Always uses 100% instead of 50% Share this post Link to post Share on other sites
Quack 34 Posted November 20, 2012 (edited) Ha, wow, sorry that was a typing error on my part. I do put spaces <eff: mana_shield 0.5> it looks like that. Always uses 100% instead of 50% You are probably not doing anything wrong. The problem is the script does not work like you think it does, which is understandable as it is a little confusing. The script does not work the way you figure it would from reading the description. If you replace the method state_effect_mana_shield_guard with the code I put below it should work the way you are expecting it to (though with this change you can no longer put values above 1.0 or you are gonna get weird behaviour. If you want to change how many hp are absorbed per mp it would be better to introduce a second parameter for that instead) def state_effect_mana_shield_guard(user, state, effect) return if user == self mod = eval(effect.value1[0]) rescue 1 if @mp < @result.hp_damage * mod mp_damage = @mp else; mp_damage = @result.hp_damage * mod; end mp_damage = mp_damage.to_i hp_damage = @result.hp_damage - mp_damage # actual HP damage # restore HP to value before damage, if any damage @hp = @result.old_hp if @result.hp_damage > 0 # now inflict damage @mp = [(@mp - mp_damage).to_i, 0].max @hp = [(@hp - hp_damage).to_i, 0].max if mp_damage > 0 @result.effect_results.push("%s's mana shield absorbed %d damage" %[self.name, mp_damage]) end @result.success = true end Edited November 21, 2012 by Quack Share this post Link to post Share on other sites
Tsukihime 1,489 Posted November 20, 2012 (edited) Ha, wow, sorry that was a typing error on my part. I do put spaces <eff: mana_shield 0.5> it looks like that. Always uses 100% instead of 50% Suppose you have 100 MP. By 100%, you mean the enemy does 100 damage, and you now have 0 MP? While because it is 50%, you expect to have 50 MP, and receive 50 HP damage? Edited November 20, 2012 by Tsukihime Share this post Link to post Share on other sites
Quack 34 Posted November 20, 2012 The thing is he was probably expecting the shield to absorb 50% of the damage. So if you have 100 mana and recieve 40 damage, that would be 20 damage absorbed by the shield and mana lost. And if the damage was 80, it would absorb 40 damage. However the way your shield works it would absorb 40 damage if you took 40 damage. And it would absorb 50 damage if you took 80. Share this post Link to post Share on other sites
Tsukihime 1,489 Posted November 20, 2012 I sort of overloaded the effect with a bunch of things and ended up not working out. If x is something like 2, then each point of MP absorbs 2 points of damage. However if x is something like 0.5, then you only absorb 50% of the damage and take the rest as HP. I guess I should separate them into two separate effects, since you could conceivably have a shield that loses 2 points of MP for each point of damage...so you're basically losing MP a whole lot faster than usual cause your shield is weak. Share this post Link to post Share on other sites
Quack 34 Posted November 20, 2012 (edited) Actually thats not completely it. I've checked you code and this is how it works: If X is 2 it can POTENTIALLY absorb 2 points per damage. However that is only if the damage is equal to or greater than your MP. If damage is less than MP it will absorb 1 damage per 1 MP. If damage is 150 and MP is 100 it will absorb 1,5 damage per MP. If X is 0.5 it will absorb damage UP TO 50% of your MP at a rate of 1 damage per 1 MP. Not 50% of the damage To me it seems like a really weird way of calculating absorbed damage and I think that you should do what I mentioned earlier and give the effect 2 parameters. One for percent of damage absorbed and one for damage absorbed per point of mana. Like this (only spent a minute on this code and have not tested it at all. Might have errors): def state_effect_mana_shield_guard(user, state, effect) return if user == self mod = eval(effect.value1[0]) rescue 1 dmg_per_mp = eval(effect.value1[1]) rescue 1 if @mp * dmg_per_mp < @result.hp_damage * mod mp_damage = @mp else; mp_damage = @result.hp_damage * mod / dmg_per_mp; end mp_damage = mp_damage.to_i hp_damage = @result.hp_damage - mp_damage * dmg_per_mp # actual HP damage # restore HP to value before damage, if any damage @hp = @result.old_hp if @result.hp_damage > 0 # now inflict damage @mp = [(@mp - mp_damage).to_i, 0].max @hp = [(@hp - hp_damage).to_i, 0].max if mp_damage > 0 @result.effect_results.push("%s's mana shield absorbed %d damage" %[self.name, mp_damage * dmg_per_mp]) end @result.success = true end edit: noticed and fix a small error and renamed a variable so code is easier to understand. Edited November 21, 2012 by Quack Share this post Link to post Share on other sites
+ lostboyrufio 0 Posted November 21, 2012 Not sure if this will help anyone with how the standard calculations for a mana shield would work but someone once wrote a Mana Shield snippet for me a long time ago. I honestly forget who it was so I'm sorry for not being able to give credit. Maybe this snippet can help solve some issues as it has worked perfectly for a project of mine without fail. module Z13 MANASHIELD = /<manashield>/i OVERFLOW = true # Will damage higher than mp carry over? end class RPG::State < RPG::BaseItem def mshield? self.note.scan(Z13::MANASHIELD){return true} return false end end class Game_Battler < Game_BattlerBase def mshield? for state in states return true if state.mshield? end return false end def dispell_mshield for state in states remove_state(state.id) if state.mshield? end end end class Game_ActionResult attr_reader :hp_mshield alias :z13md :make_damage def make_damage(value, item) z13md(value, item) if @battler.mshield? puts sprintf("Org HP DMG: %s", @hp_damage) puts sprintf("MP: %s", @battler.mp) @hp_mshield = [@hp_damage, @battler.mp].min @hp_damage = Z13::OVERFLOW ? @hp_damage - @hp_mshield : 0 @mp_damage += @hp_mshield @mp_drain = @mp_damage if item.damage.drain? @hp_drain = [@battler.hp, @hp_drain].min @battler.dispell_mshield unless @battler.mp - @mp_damage > 0 end puts sprintf("HP DMG: %s", @hp_damage) puts sprintf("HP ABS: %s", @hp_mshield) end alias :z13cdv :clear_damage_values def clear_damage_values z13cdv @hp_mshield = 0 end end class Window_BattleLog < Window_Selectable alias :z13dhpd :display_hp_damage def display_hp_damage(target, item) unless target.result.hp_mshield == 0 add_text(sprintf("%s absorbed %s damage!", target.name, target.result.hp_mshield)) wait end z13dhpd(target, item) end alias :z13dmpd :display_mp_damage def display_mp_damage(target, item) target.result.mp_damage -= target.result.hp_mshield z13dmpd(target, item) target.result.mp_damage += target.result.hp_mshield end end Share this post Link to post Share on other sites
ZombieSchematic 0 Posted November 21, 2012 Suppose you have 100 MP. By 100%, you mean the enemy does 100 damage, and you now have 0 MP? While because it is 50%, you expect to have 50 MP, and receive 50 HP damage? Yeah, You guys are amazing by the way. I unfortunately haven't gotten it to work. I a complete novice but I was messing with a few lines. I still got nothing. at one point it waited until MP was practically gone before only taking away 50% Share this post Link to post Share on other sites
Quack 34 Posted November 21, 2012 Yeah, You guys are amazing by the way. I unfortunately haven't gotten it to work. I a complete novice but I was messing with a few lines. I still got nothing. at one point it waited until MP was practically gone before only taking away 50% Did you try replacing the method state_effect_mana_shield_guard with either of the two ones I posted earlier? Because I tried that code myself now and it works (the way you want it to work). Share this post Link to post Share on other sites
estriole 326 Posted November 23, 2012 i modify my version mana shield calculation to this: def state_effect_mana_shield_guard(user, state, effect) return if user == self mod = eval(effect.value1[0]) rescue 1 # re-do the damage count. mp_damage = [@mp, @result.hp_damage / mod].min # damage absorbed #if mp is lower than the damage dealt then mp damage = mp else damage if mp_damage < 1 && mp_damage > 0 mp_damage = 1 #minimum mp is 1 there is damage end hp_damage = @result.hp_damage - mp_damage # actual HP damage #hp damage is damage min mp damage #if mp is higher than damage then hp damage = 0 (absorbed by mp only) check = @mp - @result.hp_damage / mod if check >= 0 hp_damage = 0 end # restore HP to value before damage, if any damage @hp = @result.old_hp if @result.hp_damage > 0 # now inflict damage @mp = [(@mp - mp_damage.to_i).to_i, 0].max @hp = [(@hp - hp_damage.to_i).to_i, 0].max if mp_damage > 0 @result.effect_results.push("%s's absorbed %d damage using %d mp" %[self.name, @result.hp_damage.to_i, mp_damage.to_i]) end @result.success = true end haven't test it intensively. but i think the logic already correct. Share this post Link to post Share on other sites
Quack 34 Posted November 23, 2012 i modify my version mana shield calculation to this: def state_effect_mana_shield_guard(user, state, effect) return if user == self mod = eval(effect.value1[0]) rescue 1 # re-do the damage count. mp_damage = [@mp, @result.hp_damage / mod].min # damage absorbed #if mp is lower than the damage dealt then mp damage = mp else damage if mp_damage < 1 && mp_damage > 0 mp_damage = 1 #minimum mp is 1 there is damage end hp_damage = @result.hp_damage - mp_damage # actual HP damage #hp damage is damage min mp damage #if mp is higher than damage then hp damage = 0 (absorbed by mp only) check = @mp - @result.hp_damage / mod if check >= 0 hp_damage = 0 end # restore HP to value before damage, if any damage @hp = @result.old_hp if @result.hp_damage > 0 # now inflict damage @mp = [(@mp - mp_damage.to_i).to_i, 0].max @hp = [(@hp - hp_damage.to_i).to_i, 0].max if mp_damage > 0 @result.effect_results.push("%s's absorbed %d damage using %d mp" %[self.name, @result.hp_damage.to_i, mp_damage.to_i]) end @result.success = true end haven't test it intensively. but i think the logic already correct. Well, it doesn't look like it would throw any errors, but the calculation is either incorrect or weird (depending on what your goal were). You didn't mention how your mana shield is supposed to work but from looking at it, it seems like your shield absorbs all damage where mod is the damage absorbed per point of mana. If that is the case I'm pretty sure the line hp_damage =@result.hp_damage - mp_damage is wrong. It should be hp_damage =@result.hp_damage - mp_damage * mod instead. Share this post Link to post Share on other sites
estriole 326 Posted November 24, 2012 @quack: yes i didn't explain what i want with my mana shield . what i want is when tagging the object with mana shield: 2 means = for every 1 mp it could absorb 2 hp damage. and if the mp is sufficient then no hp damage at all (not like medusa from warcraft mp shield which still get damaged but rather like energy shield from some anime ). so if there's still mp then this character is immortal . but if the mp is not sufficient. the rest of damage dealt to hp damage. so if we have 100 hp damage. then we have 20 mp. then the character will lose 20 mp and 60 hp. but i also add some protection to at lest dealt 1 mp damage if there's damage. (for those 1 mp = 10 hp damage ) thx for the advice quack. you're right about multiplying with mod. i think we could share what mana shield we develop here and seek advice how to correct the calculation if there's something wrong . Share this post Link to post Share on other sites
SirCumferance 28 Posted April 29, 2013 Hey, I tried replacing all mentions of mp with tp, so that the shield uses TP instead. However, it does not work...any ideas as to why not? Share this post Link to post Share on other sites
SirCumferance 28 Posted September 29, 2013 (edited) Bump? EDIT: On the serious tip, how can I get it to go off of TP instead of Mana, I use TP as the primary fuel for abilities (Energy or NRG) and use MP as a form of ammo, the numbers are small. Any help here? Edited September 30, 2013 by SirCumferance Share this post Link to post Share on other sites
SirCumferance 28 Posted July 30, 2014 No love? I dabbled into Necromancy and would enjoy some feedback/help Share this post Link to post Share on other sites