Jump to content

[LE] Need Help Casting A Spell From A Script (New to CK)


Recommended Posts

Note: This is a mod worked on in SSE, but as the solution would remain almost, if not entirely the same, I decided to post here too for help.

 

Hey, I'm new to the creation kit and so far I've been working on a mod that changes the Bloodskal Blade from the Dragonborn DLC.

I'm done about 80% of the mod but I'm stuck on this last part because I think I need scripting to do it.

My goal is to cast a spell on the player that I made called DLC2BloodskalBladeHealthDrain whenever the beam attack is cast (DLC2BloodskalBladeSpellHoriz and/or DLC2BloodskalBladeSpellVert).

My first guess would be to add it to the DLC2BloodskalBladeScript which I tried but I either did wrong or it didn't work:

Scriptname DLC2BloodskalbladeScriptV2 extends referenceAlias

Actor property selfRef auto hidden
Spell Property DLC2BloodskalBladeSpellHoriz auto
Spell Property DLC2BloodskalBladeSpellVert auto
Spell Property DLC2BloodskalBladeHealthDrain auto [ADDED]
weapon property selfWeapon auto hidden hidden
ammo property DLC2BloodskalAmmo auto
ReferenceAlias Property BloodskalBlade auto
objectReference Property ObjSelf auto hidden


Event OnEquipped(Actor akActor)

;objSelf = self.getReference()
; debug.trace(self + " has recieved OnEquipped")
selfRef = akActor
; ;debug.Trace("SelfRef = " + SelfRef)
if (selfref == Game.GetPlayer())
;registerForAnimationEvent(selfRef, "PowerAttack_Start_End")
registerForAnimationEvent(akActor, "AttackPowerStanding_FXstart")
registerForAnimationEvent(akActor, "AttackPowerRight_FXstart")
registerForAnimationEvent(akActor, "AttackPowerLeft_FXstart")
registerForAnimationEvent(akActor, "AttackPowerBackward_FXstart")
registerForAnimationEvent(akActor, "AttackPowerForward_FXstart")
else
;registerForAnimationEvent(selfRef, "PowerAttack_Start_End")
registerForAnimationEvent(akActor, "AttackPowerStanding_FXstart")
registerForAnimationEvent(akActor, "AttackPowerRight_FXstart")
registerForAnimationEvent(akActor, "AttackPowerLeft_FXstart")
registerForAnimationEvent(akActor, "AttackPowerBackward_FXstart")
registerForAnimationEvent(akActor, "AttackPowerForward_FXstart")
endif
; ;debug.trace("Registering for Single Update")

;RegisterforSingleUpdate(0)
endEvent

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
if akNewContainer as Actor
selfWeapon = (self.getReference().getBaseObject() as weapon)
utility.wait(0.1)
if (akNewContainer as Actor).isEquipped(selfWeapon)
OnEquipped(akNewContainer as Actor)
endif
endif
BloodskalBlade.ForceRefTo(objSelf)
endEvent

Event OnUnequipped(Actor akActor)
; debug.trace(self + " has recieved onEffectFinish")
;unregisterForAnimationEvent(selfRef, "PowerAttack_Start_End")
unregisterForAnimationEvent(akActor, "AttackPowerStanding_FXstart")
unregisterForAnimationEvent(akActor, "AttackPowerRight_FXstart")
unregisterForAnimationEvent(akActor, "AttackPowerLeft_FXstart")
unregisterForAnimationEvent(akActor, "AttackPowerBackward_FXstart")
unregisterForAnimationEvent(akActor, "AttackPowerForward_FXstart")
ENDEVENT

Event OnAnimationEvent(ObjectReference akSource, string EventName)
; debug.trace(self + " has recieved AnimationEvent ")
; debug.trace(">>>>>>>>>>>>> AnimationEvent Name: " + EventName)
; debug.trace(">>>>>>>>>>>>> AkSource: " + akSource)
if (selfref == Game.GetPlayer())
if (eventName == "AttackPowerRight_FXstart") || \
(eventName == "AttackPowerLeft_FXstart") || \
(eventName == "AttackPowerBackward_FXstart")
weapon SwordWeapon = selfRef.GetEquippedWeapon()
DLC2BloodskalBladeSpellHoriz.cast(selfRef)

elseif (eventName == "AttackPowerStanding_FXstart") || \
(eventName == "AttackPowerForward_FXstart")
weapon SwordWeapon = selfRef.GetEquippedWeapon()
DLC2BloodskalBladeSpellVert.cast(selfRef)
endif

DLC2BloodskalBladeHealthDrain.cast(selfRef)[ADDED]

endif

endEVENT

 

I also tried attaching a script dynamically to the player through a quest (I think?) but that didn't work:

Scriptname DLC2BloodskalBladePlayerHealthCost extends ReferenceAlias

Spell Property DLC2BloodskalBladeHealthDrain Auto
Spell Property DLC2BloodskalBladeSpellVert Auto
Actor Property PlayerRef Auto

Event OnSpellCast(Form DLC2BloodskalBladeSpellVert) [This is only Vertical/I don't know how to add both horiz and/or vert]
DLC2BloodskalBladeHealthDrain.cast(PlayerRef) [Feels like I have to specify the object or player casting something? But I don't know how]
EndEvent

 

For reference the mod makes the Bloodskal Blade steal health based on how low the player's health % is (Lower health=More life steal) and it makes the beam attack do more damage based on how high the players health % is (Beam does more damage the higher health the player is at). The only part I have to add is integrating this DLC2BloodskalBladeHealthDrain spell which damages the player based on how high their health % is (More damage when player is higher health). I hope to cast this spell whenever the Bloodskal Blade beams are cast that way it looks like you are fueling the beam with more power from your health.

I'm kind of out of idea's and I'm very new to modding and the creation kit. Any ideas/help would be greatly appreciated.

Link to comment
Share on other sites

Yeah, scripting is the same in normal and SSE, and use code tags for the scripts within the spoilers, helps reading then.

 

On the bloodskal script itself it should work, the spell DLC2BloodskalBladeHealthDrain is a "fire and forget" & "self" spell?

 

Regarding you second script, events don't work that way, you shouldn't change the event line but instead compare those variables/parameters to what you want them to be, for lack of better ways of explaining it, do this instead:

Event OnSpellCast(Form akSpell) 
 Spell Spellcast = akSpell as Spell ;cast form as spell
 If (Spellcast) && (Spell == DLC2BloodskalBladeSpellVert || Spell == DLC2BloodskalBladeSpellHoriz) ; check its valid and compare it
  DLC2BloodskalBladeHealthDrain.cast(PlayerRef)
 Endif
EndEvent

The first thing is casting the form as spell type, in order to compare it to other spells later.

 

But still the first way should work just fine so check the actual spell.

Link to comment
Share on other sites

Thanks for the reply, but I still can't seem to get it to work.

I have checked that my spell is "fire and forget" and "self": Which it is, but no spell seems to be cast when I launch a Bloodskal beam attack in game.

 

Whats even more interesting is the testing I did to see if it was the spell at fault. I tried changing the effect from AlchDamageHealth to a FortifySneak just to see if that would make a difference: same outcome, no spell cast.

I then thought: "Is the script even running?" so I tried removing the DLC2BloodskalBladesScript from DLC2BloodskalBladeEffect (Which it was found in Vanilla) and I found the script present in a reference to the BloodskalBlade in a DLC2BloodskalBladeQST, so I removed the script from that too. (Up until then I have been replacing those scripts with the one that is to cast the effect "DLC2BloodskalbladeScriptV2")

 

It would make sense that the blade in game wouldn't cast its effect sense the script telling it to do that is gone, but the blade still works perfectly with its scripts removed (?).

I made sure that the esp was saved and loaded, and its also the last in my load order so I don't think there is any overwrites, considering all my current changes to the blade worked up until this point.

I set the spell to have no cost and no requirements so is the script even running?

 

I tried the player reference idea too with the script example shown, adding in the other spell references but it still didn't work. I set the quest it was tied to to reference the player in any cell and run on game start but no luck.

Although I had to change the script to this to get it to compile successfully:

 

 


Scriptname DLC2BloodskalBladePlayerHealthCost extends ReferenceAlias



Spell Property DLC2BloodskalBladeSpellVert Auto

Spell Property DLC2BloodskalBladeSpellHoriz Auto

Spell Property DLC2BloodskalBladeHealthDrain Auto

Actor Property PlayerRef Auto



Event OnSpellCast(Form akSpell)

Spell Spellcast = akSpell as Spell 

If (Spellcast) && (akSpell == DLC2BloodskalBladeSpellVert || akSpell == DLC2BloodskalBladeSpellHoriz) ; Had to change Spell to akSpell

DLC2BloodskalBladeHealthDrain.cast(PlayerRef)

Endif

EndEvent

 

 

 

Maybe my change screwed it up but I thought I was just showing the script what it was looking for:

[if spell is "akSpell" > If "akSpell" is DLC2BloodskalBladeSpellVert or DLC2BloodskalBladeSpellHoriz] correct?

 

Either way it seems that the script i'm trying to get to run isn't running at all, is being overwrited, or the original DLC2BloodskalBladeScript is still being ran and checked somewhere else, even though

I thought the only place I thought it was being used was the DLCBloodskalBladeEffect and DLC2BloodskalBladeQST. Has a quest trigger hard wired the original script somewhere?

I have also tripped checked for spelling errors in the spell references.

 

TLDR: I think i'm changing the script in the wrong location because the blade still works with its original scripts gone from there, but where could it be? I looked at everything with *Bloodskal in it.

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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