Jump to content

Add Spells from formlist?


xcafe

Recommended Posts

Title says it all, I've got a formlist full of spells that I want added to the player. Anyone know how? (Also, formlists are global right? As in, if I fill a formlist property in one script I should be able to access it from another?)

Edited by xcafe
Link to comment
Share on other sites

Very similar to the array method you asked about earlier. This assumes that your formlist is called MyList and that the player has been stored in a variable called PlayerRef

Int ListSize = MyList.GetSize()
Int Index = 0
While Index < ListSize
  Form Entry = MyList.GetAt(Index)
  If (Entry as Spell)
    PlayerRef.AddSpell(Entry as Spell)
  EndIf
  Index += 1
EndWhile

Should be able to access a formlist from one script on another. Test to make sure.

Link to comment
Share on other sites

Hm, so I've tested it, and I don't know what the problem is.

FormList Property GrimoireSpellList Auto
Actor Property PlayerRef Auto

Event OnRead()
Int ListSize = GrimoireSpellList.GetSize()
Int Index = 0
While Index < ListSize
  Form Entry = GrimoireSpellList.GetAt(Index)
  If (Entry as Spell)
      PlayerRef.AddSpell(Entry as Spell)
  EndIf
  Index += 1
EndWhile
EndEvent

It compiles just fine, and in theory it should work, but it doesn't do anything. I've tried both the OnRead and OnEquipped events for this one, and nothing either time.

Link to comment
Share on other sites

What objects are each of the scripts attached to? The ones with the OnRead and/or OnEquipped events should be extending ObjectReference at the very least. If they do not extend the correct script, then they do not have access to the correct events that you are trying to listen to. Without being able to listen for the events, those portions of the script will not run.

Link to comment
Share on other sites

Are there any spells in the formlist to start with? If not, the while loop will not run since the index is 0 and the size is 0. That would prevent the notification statement from showing on that script.

 

Where are you attaching the script that has the formlist property? Is that on the same object? If so, move it to a more permanent object. Perhaps a quest that is intended to be 'active' for the life of your mod.

 

It is a bit hard to explain but I have discovered that for a formlist's changes to be recognized by other scripts the formlist needs to be a property on a script on a object that will be active for the duration that you want the changes to be noticed. If not, when an object with the formlist is first loaded it will get the formlist as-is from the plugin rather than with any changes you intended.

 

I'm guessing that you are applying all these scripts to the spell tomes themselves. That is fine except for where the formlist is actually a property. That should be on something more permanent like a long running quest.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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