Jump to content

Need help with script for spell


Recommended Posts

Hi there!
So, I am in the process of creating a mod with my very limited scripting knowledge and would like to ask if anyone here is kind enough and has the knowledge to help me out with this script.
Essentially, I want to make a script that makes it so that upon casting a specific spell, it will consume a Soul Gem and without having a Soul Gem, you can't cast this specific spell.
Any help is appreciated!

Link to comment
Share on other sites

Here's how I would do it. Make a new formlist in the Creation Kit under miscellaneous / formlist and drag and drop all of the soul gems you want to check for to the list. Let's say you name the list AllSoulGems. In your spell when adding the magic effect, put the condition GetItemCount AllSoulGems > 0 . If the spell is not cast on Self, check the Swap subject and target box in the condition and it will run on the caster of the spell. This makes sure you have at least one soul gem in your inventory, otherwise you can't cast the spell.

 

Then in your script, you can use a while loop to iterate through all the forms in the list, checking item count and remove one soul gem from the caster:

 

Scriptname TM_MagicEffectScript extends ActiveMagicEffect 

Formlist Property AllSoulGems Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)    
    Int Index = AllSoulGems.GetSize()                   ;get how many forms are in the list 
    While Index > 0                                     ;while loop repeats until Index equals 0. Iterating through all forms in the list.
        Index -= 1                                      ;Subract 1 from Index, moving on to the next form. 
        Form CurrentSoulGem = AllSoulGems.GetAt(Index)  ;Get current soul gem form from the list. 
        If akCaster.GetItemCount(CurrentSoulGem) > 0    ;Does the caster of this spell have at least 1 of the CurrentSoulGem in their inventory?
            akCaster.RemoveItem(CurrentSoulGem, 1)      ;Remove 1 of the CurrentSoulGem from casters inventory.
            Index = 0                                   ;stop the While loop so only 1 soul gem is removed. 
        Endif 
        
    EndWhile
EndEvent

Name the script something different and don't forget to fill properties after compiling / attaching your script.

Here's a good beginner tutorial for scripts if interested: http://www.cipscis.com/skyrim/tutorials/beginners.aspx

And here you can find more about properties: http://tesalliance.org/forums/index.php?/topic/5039-class-2-properties/

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...