Jump to content

[LE] How do you add a leveled spell list to an NPC?


JobVanDam

Recommended Posts

I tried AddSpell and it doesn't seem to work.
When trying to compile the script I get the following error :

JVD_DefaultAddSpell.psc(10,9): type mismatch on parameter 1 (did you forget a cast?)


Here is my script:

Scriptname JVD_DefaultAddSpell extends Actor
{Adds the selected spell OnCellAttach()}

LeveledSpell Property mySpell Auto
{Spell that will get added to this actor OnCellAttached()}

Event OnCellAttach()
    utility.Wait(3)
;   debug.Trace("Adding Spell to " + self)
    self.AddSpell(mySpell)
EndEvent

This script is basically copied from a Dragonborn script which adds a spell to an NPC. Only changes I made were the name of the script and the variable is now a leveledspell.

Reason I'm doing this, I'm not sure if its common knowledge, but if you add a leveled spell to an actor that is copied by another actor the leveled spell list won't return anything. I'm hoping a script will remedy this.

Link to comment
Share on other sites

Hmm, this compiled for me:

 

LeveledSpell Property mySpell Auto
{Spell that will get added to this actor OnCellAttached()}

Event OnCellAttach()
    utility.Wait(3)
;   debug.Trace("Adding Spell to " + self)
    self.AddItem(mySpell)
EndEvent

I do have skse installed but I'm not sure if you need it for this.

Link to comment
Share on other sites

You need to first obtain the npc's level and then add the corresponding spell, the spell is not added because the game does not know the level.

Which function do I use then?

AddSpell does not work at all with LeveledSpell properties.

AddItem accepts a Count integer not a Level integer.

Link to comment
Share on other sites

According to the wiki: https://www.creationkit.com/index.php?title=LeveledSpell leveled spells can only be used in an actors spell list. So for a script, you'll have to do it manually.

Example:

 

Spell Property Firebolt Auto 
Spell Property Flames Auto

Event OnCellAttach()
    Int Level = Game.GetPlayer().Getlevel() 
    
    If Level > 15 
        Self.AddSpell(Firebolt) 
    Elseif Level > 10 
        Self.AddSpell(Flames) 
    Endif
EndEvent

You could also put the spells in a formlist or array if there's a lot in the leveledSpell to make it easier.

Link to comment
Share on other sites

According to the wiki: https://www.creationkit.com/index.php?title=LeveledSpell leveled spells can only be used in an actors spell list. So for a script, you'll have to do it manually.

Example:

 

Spell Property Firebolt Auto 
Spell Property Flames Auto

Event OnCellAttach()
    Int Level = Game.GetPlayer().Getlevel() 
    
    If Level > 15 
        Self.AddSpell(Firebolt) 
    Elseif Level > 10 
        Self.AddSpell(Flames) 
    Endif
EndEvent

You could also put the spells in a formlist or array if there's a lot in the leveledSpell to make it easier.

Thank you very much dylbill.

 

The lists I have much more varied. I wanted to use them like a leveled list where the game randomly selects 1 out of a myriad of options tp keep things random.

I guess I'm going to have code the same functionality as the flag "Calculate from all levels <= PC level" except I base it off the actor's level.

 

Thanks for the help guys.

Link to comment
Share on other sites

No problem. If that's the case, I would use a formlist. Put your spells in order in the list from lowest level to highest level. Then you can keep track of the index of leveled spells in the script. Example

 

Formlist Property MyLeveledSpells Auto

Event OnCellAttach()
    Int Level = self.Getlevel()
    Int Max = 5 
    
    If Level > 10
        Max = 15 ;use first 15 spells in list to pull from
    Elseif Level > 5
        Max = 10 ;use first 10 spells in list to pull from
    Endif
    
    Spell SpellToAdd = MyLeveledSpells.GetAt(Utility.RandomInt(0, Max)) as Spell 
    
    Self.AddSpell(SpellToAdd)
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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