killthesun Posted April 22, 2020 Posted April 22, 2020 Hi, I'm making my first mod, Mutagens, it gives the player permanent buffs for drinking fortify potions. The way it works is I attached a script (mutTrackAndUpdate) to Player, it looks for potion drinking events with OnObjectEquipped, keeps count of how many potions were drunk for several different magic effects, and casts a spell (mutSpell) on the player, which gives a perma buff for each effect, with magnitude according to the total number of potions drunk for that effect. It works, but I'm concerned about good practice. For example, is it OK that I attach a script to Player? Any other problems you can see? Later I'm planning on making a mcm, and then making cool perk-like bonuses, like after x potions you get 5% spell vamp etc. I'll attach the zipped mod, and post the script below. I used SKSE functions so I guess it requires SKSE. If you want to test it, the supported potions so far are fire/frost/shock resist, fortifyealth/magicka/stamina, healthregen*/magickaregen/staminaregen, and carryweight. * for health regen perma buff, I had to create the magic effect because I couldn't find an existing one that granted healthratemult, like the regen potion does. Thanks! Scriptname mutTrackAndUpdate extends Actor {Track potion drinking and update mutSpell} import Math MagicEffect[] potionEffects Spell property mySpell auto ; set to mutSpell string[] alchEffectList int[] mutCounters Event OnInit() ;Debug.Trace("mutINIT") alchEffectList = New string[11] mutCounters = New int[11] alchEffectList[0] = "Resist Fire" alchEffectList[1] = "Resist Frost" alchEffectList[2] = "Resist Shock" alchEffectList[3] = "Resist Magic" alchEffectList[4] = "Fortify Health" alchEffectList[5] = "Fortify Magicka" alchEffectList[6] = "Fortify Stamina" alchEffectList[7] = "Regenerate Health" alchEffectList[8] = "Regenerate Magicka" alchEffectList[9] = "Regenerate Stamina" alchEffectList[10] = "Fortify Carry Weight" EndEvent Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Potion ;Debug.Trace("mutPOTION") potionEffects = (akBaseObject as Potion).GetMagicEffects() string listOfMagicEffects = "" int i while i < potionEffects.Length listOfMagicEffects += potionEffects[i].GetName() consume(potionEffects[i]) i += 1 endWhile ;Debug.MessageBox("effect names: "+listOfMagicEffects) endIf endEvent bool function consume(MagicEffect potionEffect) int j while j < alchEffectList.length if potionEffect.GetName() == alchEffectList[j] mutCounters[j] = mutCounters[j] + 1 ;Debug.MessageBox("j: "+j+", mutCounters[j]: "+mutCounters[j]+", alchEffectList[j] "+alchEffectList[j]) updateBuff() endIf j += 1 endWhile endFunction bool function updateBuff() int k while k < mutCounters.length mySpell.SetNthEffectMagnitude(k, 5*sqrt(mutCounters[k])) k += 1 endWhile self.RemoveSpell(mySpell) self.AddSpell(mySpell) ;Debug.Trace("mutDONE") endFunction Mutagens.zip
Recommended Posts
Archived
This topic is now archived and is closed to further replies.