porroone Posted August 5, 2012 Share Posted August 5, 2012 (edited) Hello and thanks for reading, I am currently working on a function to get the cost of magicka using papyrus, taking into consideration perks and enchants and using the Cast() function to cast the spell. The problem I am having is the function is way too long and whenever I trigger it, the whole script freezes for like 2 seconds, so I was looking for a way to optimize it and I thought maybe you guys could lend me some input on this one, I would really appreciate it.Here is the function: Function GetRLCost() Notification("hello there folks") curLeft = Player.GetEquippedSpell(0) curRight = Player.GetEquippedSpell(1) SpellPerkL = curLeft.GetPerk() SpellPerkR = curRight.GetPerk() magickacostl = curLeft.GetMagickaCost() magickacostr = curRight.GetMagickaCost() chestEnchant = (Player.GetWornForm(4) as armor).GetEnchantment() bootsEnchant = (Player.GetWornForm(80) as armor).GetEnchantment() handsEnchant = (Player.GetWornForm(8) as armor).GetEnchantment() helmetEnchant = (Player.GetWornForm(2) as armor).GetEnchantment() AmuletEnchant = (Player.GetWornForm(20) as armor).GetEnchantment() numenchants = chestEnchant.GetNumEffects() + bootsEnchant.GetNumEffects() + handsEnchant.GetNumEffects() + helmetEnchant.GetNumEffects() + AmuletEnchant.GetNumEffects() if Player.HasPerk(SpellPerkL) magickacostl = magickacostl / 2 endIf if Player.HasPerk(SpellPerkR) magickacostr = magickacostr / 2 endIf while i < numenchants i += 1 if chestEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostr = magickacostr - ((magickacostr*chestEnchant.GetNthEffectMagnitude(i))/100) elseif chestEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostl = magickacostl - ((magickacostl*chestEnchant.GetNthEffectMagnitude(i))/100) elseif chestEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostr = magickacostr - ((magickacostr*chestEnchant.GetNthEffectMagnitude(i))/100) elseif chestEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostl = magickacostl - ((magickacostl*chestEnchant.GetNthEffectMagnitude(i))/100) elseif bootsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostr = magickacostr - ((magickacostr*bootsEnchant.GetNthEffectMagnitude(i))/100) elseif bootsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostl = magickacostl - ((magickacostl*bootsEnchant.GetNthEffectMagnitude(i))/100) elseif BootsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostr = magickacostr - ((magickacostr*bootsEnchant.GetNthEffectMagnitude(i))/100) elseif BootsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostl = magickacostl - ((magickacostl*bootsEnchant.GetNthEffectMagnitude(i))/100) elseif handsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostr = magickacostr - ((magickacostr*HandsEnchant.GetNthEffectMagnitude(i))/100) elseif handsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostl = magickacostl - ((magickacostl*HandsEnchant.GetNthEffectMagnitude(i))/100) elseif handsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostr = magickacostr - ((magickacostr*handsEnchant.GetNthEffectMagnitude(i))/100) elseif handsEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostl = magickacostl - ((magickacostl*handsEnchant.GetNthEffectMagnitude(i))/100) elseif HelmetEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostr = magickacostr - ((magickacostr*HelmetEnchant.GetNthEffectMagnitude(i))/100) elseif HelmetEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostl = magickacostl - ((magickacostl*HelmetEnchant.GetNthEffectMagnitude(i))/100) elseif HelmetEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostr = magickacostr - ((magickacostr*HelmetEnchant.GetNthEffectMagnitude(i))/100) elseif HelmetEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostl = magickacostl - ((magickacostl*HelmetEnchant.GetNthEffectMagnitude(i))/100) elseif AmuletEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction" ) magickacostr = magickacostr - ((magickacostr*AmuletEnchant.GetNthEffectMagnitude(i))/100) elseif AmuletEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Destruction" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction") magickacostl = magickacostl - ((magickacostl*AmuletEnchant.GetNthEffectMagnitude(i))/100) elseif AmuletEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curRight.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostr = magickacostr - ((magickacostr*AmuletEnchant.GetNthEffectMagnitude(i))/100) elseif AmuletEnchant.GetNthEffectMagicEffect(i).GetName() == "Fortify Restoration" && (curLeft.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration") magickacostl = magickacostl - ((magickacostl*AmuletEnchant.GetNthEffectMagnitude(i))/100) endIf endWhile endFunction Edited August 5, 2012 by porroone Link to comment Share on other sites More sharing options...
Recommended Posts