Jump to content

Creation Kit: Detect the Player Cast and Equip Spells with Script


IronDusk33

Recommended Posts

I'm attempting to create a mod that allows the player to research spells and spell archetypes by casting them, among other methods. However, I have not figured out how to implement a few crucial parts of my mod.

 

Here is what I have yet to figure out:

-Detect what spells the player has equipped

-Detect when the player casts said spells

-Detect when the player equips a new spell

 

I have attempted to look at TaichiKid's Spell Crafting, (found here: http://www.nexusmods.com/skyrim/mods/33598/?) but I wasn't able to fully figure out how his mod detects spells.

 

I would really appreciate someone explaining how to do this.

Link to comment
Share on other sites

I'll help you.



-Detect what spells the player has equipped


This one's from the Actor script. So you have to initialize the actor first (or the player, in this case) as such:



Actor Property wiseman Auto


wiseman = Game.GetPlayer()



Initialize your spell, too:


Spell Property equippedSpell Auto



Then check if the equipped item on hand is a spell:


if(wiseman.GetEquippedItemType(0) == 9) ; Use GetEquippedItemType(1) for right hand; 9 pertains to the magic spell item type


equippedSpell = wiseman.GetEquippedSpell(0) ;Use GetEquippedSpell(1) for right hand or GetEquippedSpell(2) for voice slot


else


Debug.Trace("It's not a spell!")


endif


equippedSpell is now the spell that you have on-hand



-Detect when the player casts said spells


You can use an event listener for this.


Event OnSpellCast(Form akSpell)


if(akSpell == equippedSpell)


; essentially means the spell you cast was the equipped spell from a while ago, so do something here


endif


endEvent



-Detect when the player equips a new spell


Again, you can use an event listener for this.



Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)


if(akBaseObject as Spell) ;essentially checks whether the thing you just equipped is a spell


equippedSpell = akBaseObject as Spell ;essentially sets your equipped spell as the spell that was just equipped by the player


endif


endEvent



Hope it helps!


Link to comment
Share on other sites

  • 2 years later...
  • Recently Browsing   0 members

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