Jump to content

[LE] Casting random spell from a formlist


Recommended Posts

I am making a circlet which gives it's wearer the ability to equip a random spell contained in a formlist. to achieve this I have attached this script to the circlet.

 

 

Scriptname DA_SRPT_RandEnch extends ObjectReference

Formlist Property SpellToEquip Auto
Event OnEquipped(Actor akActor)
Debug.Notification("Event Fired.")
int cbstate = akActor.GetCombatState()
if cbstate == 1
int n = SpellToEquip.GetSize() - 1
n = Utility.RandomInt(0, n)
akActor.EquipSpell(SpellToEquip.GetAt(n))
EndIf
EndEvent

 

I get an error at akActor.EquipSpell line "akspell and the argument passed to it are incompatible types."

 

Some one please help me understand how do I make it work?

 

Link to comment
Share on other sites

type casting like this:

akActor.EquipSpell(SpellToEquip.GetAt(n) as Spell)

But imho your way does not really work, have a look to next code for improvement.

 

DA_SRPT_RandEnch

 

Scriptname DA_SRPT_RandEnch extends ObjectReference  
; https://forums.nexusmods.com/index.php?/topic/8997658-casting-random-spell-from-a-formlist/

  Formlist PROPERTY SpellToEquip auto

  Actor caster            ; temp holder to use in OnUpdate() event
  Spell mySpell           ; temp holder for random spell


; -- EVENTs -- 3
 
EVENT OnEquipped(Actor akActor)
    caster = akActor    ; make actor persistent
    RegisterForSingleUpdate(1.0)                    ; start update chain to detect combat
ENDEVENT


EVENT OnUnEquipped(Actor akActor)
    UnRegisterForUpdate()
    caster = None        ; remove persistence

IF ( mySpell )
    IF     (akActor.GetEquippedSpell(0) == mySpell)        ; left hand
        akActor.UnEquipSpell(mySpell, 0)

    ELSEIF (akActor.GetEquippedSpell(1) == mySpell)        ; right hand
        akActor.UnEquipSpell(mySpell, 1)

    ELSEIF (akActor.GetEquippedSpell(2) == mySpell)        ; other
        akActor.UnEquipSpell(mySpell, 2)
    ENDIF
    mySpell = None
ENDIF    
ENDEVENT


EVENT OnUpdate()
IF ( caster )
;;;    caster.GetCombatState()
;;;    IF (caster.GetCombatState() == 1)        ; https://www.creationkit.com/index.php?title=GetCombatState_-_Actor
    IF caster.IsInCombat()
        myF_Action()
        RegisterForSingleUpdate(10.0)               ; spell has been set, 10 sec delay
    ELSE
        RegisterForSingleUpdate(1.0)                ; not in combat, 1 sec delay
    ENDIF
ENDIF
ENDEVENT


; -- FUNCTION --

;--------------------
FUNCTION myF_Action()
;--------------------
    Debug.Notification("spell has been equipped.")

    int i = SpellToEquip.GetSize() - 1            ; get max entry of formlist
    i = Utility.RandomInt(0, i)                   ; get random spell entry
    mySpell = SpellToEquip.GetAt(i) as Spell      ; store this spell            

    ; https://www.creationkit.com/index.php?title=EquipSpell_-_Actor
    caster.EquipSpell(mySpell, 1)                 ; equip this spell
ENDFUNCTION

 


Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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