I wanted to create a perk which refunds a little mana sometimes once I cast my destruction spells, I got help in Nexus forum by Sjogga (he is author of Psijic teleport spells!) who provided me the initial script to get me started. And I did get it to work and I'm very pleased of how it works! I also figured out how to restore 'flat' magicka and make it scale by level, so I will post both 2 versions here.
I want to thank Sjogga again for helping me out in the other forum! I didn't just want that thread to die there, and be forgotten. Instead I decided to post here what I have learned, as it might be useful to new Creation Kit users (just as myself) that are in need of a similar result
1. Create the perk.
2. Create the spell you want to trigger (or skip this step if you want to use the second script)
3. Create a Formlist of spells, which should trigger the perk.
4. Create a new quest, click on 'Quest Aliases' tab. Add the alias, set the 'Player' as reference, attach one of the scripts. And fill in the properties.
5. Open your perk again, add this quest as Perk Entry
6. Add the perk to your skill tree
Note: Don't forget to set Perk Property when adding the script in Quest Aliases, or your new effect will start proccing even if you haven't picked the Perk up at the skill tree in-game. It's the only way I found to stop it from happening, I tried to add a condition to Alias but it did not work.
CastChanceProcSpell
This one will proc a magic effect / spell when you cast your spells in-game has 30% chance.
Scriptname CastChanceProcSpell extends ReferenceAlias
{Gives spell casts a chance to trigger an additional effect}
Spell Property MagickaRegenSpell Auto
FormList Property TriggerSpells Auto
VisualEffect Property FX Auto
Perk Property SelectPerk Auto
Event OnSpellCast(Form akSpell)
If (Game.GetPlayer().HasPerk(SelectPerk))
If(TriggerSpells.hasForm(akSpell))
Int Chance = Utility.RandomInt(1,100)
If(Chance <= 30)
MagickaRegenSpell.cast(game.getPlayer())
FX.Play(game.getPlayer())
EndIf
EndIf
EndIf
EndEvent
CastChanceProcFixed
This one will give your spells a chance to restore a flat amount magicka, health or stamina which also scale by level (by 1) and got a 30% chance of happening.
Scriptname CastChanceProcFixed extends ReferenceAlias
{Gives spell casts a chance to trigger an additional effect}
FormList Property TriggerSpells Auto
VisualEffect Property FX Auto
Float Property MagickaAmount Auto
Perk Property SelectPerk Auto
Event OnSpellCast(Form akSpell)
If (Game.GetPlayer().HasPerk(SelectPerk))
If(TriggerSpells.hasForm(akSpell))
Int Chance = Utility.RandomInt(1,100)
If(Chance <= 30)
Float MagickaReplenished = MagickaAmount+(Game.GetPlayer().GetLevel())
Game.GetPlayer().RestoreActorValue("Magicka",MagickaReplenished)
FX.Play(game.getPlayer())
EndIf
EndIf
EndIf
EndEvent