Jump to content

[LE] Script question: Cast spell to disable/enable object reference.


Thuggysmurf

Recommended Posts

I'm missing something basic. Trying to make a spell that upon casting, it will disable a building & its door, and then enable a ruined building in place of that.

 

The script below compiles, and when the player uses the spell in game, the projectile fires, but upon casting the spell, the spell doesn't do anything.

 

Any thoughts?

 

Event OnSpellCast(Form akSpell)
Spell spellCast = akSpell as Spell
If spellCast && spellCast == Spellname
DisableObject1.Disable() ; Disable Temple Structure
DisableObject2.Disable() ; Disable Temple Door
Utility.Wait(1.0)
EnableObject1.Enable() ; Enable Ruined Temple
EndIf
endEvent


ObjectReference Property DisableObject1 Auto

ObjectReference Property DisableObject2 Auto

ObjectReference Property EnableObject1 Auto

SPELL Property Spellname Auto

Link to comment
Share on other sites

First question:

Are the properties properly filled in the Creation Kit? <-- If properties are not filled, the script will not work correctly if at all.

 

Second question:

Are you testing on a new game or a game that has not had the location in question loaded? <-- If the area in question has already been loaded and stored in the save file, new changes may not take affect until the cell gets reset.

Link to comment
Share on other sites

Thanks IsharaMeradin for the reply:

 

Question 1: Yes, properties were filled.

 

Question 2: Location already visited and loaded.

 

I started over from scratch, using Fireball spell as a template, and then adding the following script to the fireball effect, and now everything works:

 

Event OnEffectStart(Actor akTarget, Actor akCaster)
DisableObject1.Disable(True) ; Disable Temple Structure
DisableObject2.Disable(True) ; Disable Temple Door
EnableObject1.Enable(True) ; Enable Ruined Temple
endEvent

ObjectReference Property DisableObject1 Auto

ObjectReference Property DisableObject2 Auto

ObjectReference Property EnableObject1 Auto

 

 

The next part I'm stuck on, in case anyone knows the answer, is how to advance the quest stage upon casting this spell. Like in MQ104, when the player has to use Unrelenting Force for the first time (couldn't find the mechanism to advance the quest stage in CK looking at MQ104 or Unrelenting Force). Thanks again!

Link to comment
Share on other sites

The reason the OnSpellCast probabaly didn't work is that has to be on an ObjectReference script (or a ReferenceAlias). If it was in your MagicEffect script it would never fire because that's not a valid event for a MagicEffect. Glad you found an alternative method that does work though.

 

As for advancing a quest stage, you can just add another property for your quest then use quest.SetStage(n). Optionally making n an int property for flexibility of the script.

 

I don't remember the details around the first shout thing to remember where to find the code. But I think it was triggered when a ref alias gets hit with the effect.

Link to comment
Share on other sites

The reason the OnSpellCast probabaly didn't work is that has to be on an ObjectReference script (or a ReferenceAlias). If it was in your MagicEffect script it would never fire because that's not a valid event for a MagicEffect. Glad you found an alternative method that does work though.

 

As for advancing a quest stage, you can just add another property for your quest then use quest.SetStage(n). Optionally making n an int property for flexibility of the script.

 

I don't remember the details around the first shout thing to remember where to find the code. But I think it was triggered when a ref alias gets hit with the effect.

 

ActiveMagicEffects can receive pretty much any event the Actor they are on can; things like OnSpellCast and so on get passed through to any attached aliases or magic effects. They can't do their jobs, otherwise.

Link to comment
Share on other sites

@foamyesque: Maybe you know more than me. At the moment I cannnot check OnSpellCast() will be triggered within scripts that extends ActiveMagicEffect.

I know that:

; Event received when a spell is cast by this object
Event OnSpellCast(Form akSpell)
EndEvent

Next are these vanilla scripts which have included the event we are discuss here.

; three class scripts

Scriptname ActiveMagicEffect Hidden
Scriptname ObjectReference extends Form Hidden
Scriptname ReferenceAlias extends Alias Hidden

; ten scripts that use the OnSpellcast() event

Scriptname DGIntimidatePlayerScript extends ReferenceAlias
Scriptname DLC1LD_ForgemasterBossBattle extends ReferenceAlias Conditional
Scriptname DLC1MistformManagerScript extends ReferenceAlias
Scriptname DLC1PlayerVampireScript extends ReferenceAlias
Scriptname DLC1ReflexesManagerScript extends ReferenceAlias
Scriptname DLC2dunFrostmoonPlayerScript extends ReferenceAlias
Scriptname MG01TolfdirScript extends ReferenceAlias
Scriptname MGBridgePlayerQuest extends ReferenceAlias
Scriptname MGRitual03EffectScript extends ReferenceAlias
Scriptname MQ104PlayerScript extends ReferenceAlias

I think there seems to be a good reason not using of OnSpellcast() within ActiveMagicEffect scripts. Is it useful for that kind of scripts?

Edited by ReDragon2013
Link to comment
Share on other sites

I think there seems to be a good reason not using of OnSpellcast() within ActiveMagicEffect scripts. Is it useful for that kind of scripts?

 

It could be, depending on what you're about; magic effects (spells, abilities, enchantments, etc) are useful ways to attach scripts to things without using quest aliases. If one of those things cares about casting spells, it could use it.

 

For example, you could create an enchanted piece of gear that copies any spell you cast.

Link to comment
Share on other sites

 

The reason the OnSpellCast probabaly didn't work is that has to be on an ObjectReference script (or a ReferenceAlias). If it was in your MagicEffect script it would never fire because that's not a valid event for a MagicEffect. Glad you found an alternative method that does work though.

 

As for advancing a quest stage, you can just add another property for your quest then use quest.SetStage(n). Optionally making n an int property for flexibility of the script.

 

I don't remember the details around the first shout thing to remember where to find the code. But I think it was triggered when a ref alias gets hit with the effect.

 

ActiveMagicEffects can receive pretty much any event the Actor they are on can; things like OnSpellCast and so on get passed through to any attached aliases or magic effects. They can't do their jobs, otherwise.

 

 

This isn't true. ActiveMagicEffect scripts will only receive their own events and those of ScriptObject. As ReDragon2013 noticed all the scripts mentioned that use OnSpellCast are ReferenceAlias which by design do get actor events *if* the reference it holds is an actor. I have been corrected below.

 

Fallout 4's papyrus allows for RemoteEvents which can sort of get around this limitation but since this question/thread is for Skyrim it seems irrelevant.

Edited by BigAndFlabby
Link to comment
Share on other sites

 

 

The reason the OnSpellCast probabaly didn't work is that has to be on an ObjectReference script (or a ReferenceAlias). If it was in your MagicEffect script it would never fire because that's not a valid event for a MagicEffect. Glad you found an alternative method that does work though.

 

As for advancing a quest stage, you can just add another property for your quest then use quest.SetStage(n). Optionally making n an int property for flexibility of the script.

 

I don't remember the details around the first shout thing to remember where to find the code. But I think it was triggered when a ref alias gets hit with the effect.

 

ActiveMagicEffects can receive pretty much any event the Actor they are on can; things like OnSpellCast and so on get passed through to any attached aliases or magic effects. They can't do their jobs, otherwise.

 

 

This isn't true. ActiveMagicEffect scripts will only receive their own events and those of ScriptObject. As ReDragon2013 noticed all the scripts mentioned that use OnSpellCast are ReferenceAlias which by design do get actor events *if* the reference it holds is an actor.

 

Fallout 4's papyrus allows for RemoteEvents which can sort of get around this limitation but since this question/thread is for Skyrim it seems irrelevant.

 

 

I have written and used extensively magic effects that make use of Actor and ObjectReference events, such as OnCellLoad(), OnObjectEquipped(), OnMagicEffectApply(), OnPlayerLoadGame(), and so on. I know these work. They're even in the bleedin' .psc for ActiveMagicEffect, if you want further proof, with the specific note that they are received from the actor the ActiveMagicEffect is applied to:

; The following events are received from the actor this effect is attached to:

; Event received when this reference is activated
Event OnActivate(ObjectReference akActionRef)
EndEvent

; Event received when this object has moved to an attached cell from a detached one
Event OnAttachedToCell()
EndEvent

; Event received when this object's parent cell is attached
Event OnCellAttach()
EndEvent

; Event received when this object's parent cell is detached
Event OnCellDetach()
EndEvent

; Event received when every object in this object's parent cell is loaded (TODO: Find restrictions)
Event OnCellLoad()
EndEvent

; Event received when this object is closed
Event OnClose(ObjectReference akActionRef)
EndEvent

; Event received when this object enters, exits, or changes containers
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
EndEvent

; Event received when this reference's destruction stage has changed
Event OnDestructionStageChanged(int aiOldStage, int aiCurrentStage)
EndEvent

; Event recieved when this object moves to a detached cell from an attached one
Event OnDetachedFromCell()
EndEvent

; Event received when this object is equipped by an actor
Event OnEquipped(Actor akActor)
EndEvent

; Event received when this object is grabbed by the player
Event OnGrab()
EndEvent

; Event received when this object is hit by a source (weapon, spell, explosion) or projectile attack
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
EndEvent

; Event received when an item is added to this object's inventory. If the item is a persistant reference, akItemReference will
; point at it - otherwise the parameter will be None
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
EndEvent

; Event received when an item is removed from this object's inventory. If the item is a persistant reference, akItemReference
; will point at it - otherwise the parameter will be None
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
EndEvent

; Event recieved when this object is completely loaded - will be fired every time this object is loaded
Event OnLoad()
EndEvent

; Event received when the lock on this object changes
Event OnLockStateChanged()
EndEvent

; Event received when a magic affect is being applied to this object
Event OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect)
EndEvent

; Event received when this object is opened
Event OnOpen(ObjectReference akActionRef)
EndEvent

; Event received when this actor finishes changing its race
Event OnRaceSwitchComplete()
EndEvent

; Event received when this object, if a book, is read
Event OnRead()
EndEvent

; Event received when this object is released by the player
Event OnRelease()
EndEvent

; Event received when this reference is reset
Event OnReset()
EndEvent

; Event received when this reference is sold by an actor
Event OnSell(Actor akSeller)
EndEvent

; Event received when a spell is cast by this object
Event OnSpellCast(Form akSpell)
EndEvent

; Event received when translation is complete (from a call to TranslateTo)
Event OnTranslationComplete()
EndEvent

; Event received when translation is aborted (from a call to StopTranslateTo)
Event OnTranslationFailed()
EndEvent

; Event recieved when this reference hits a target
Event OnTrapHit(ObjectReference akTarget, float afXVel, float afYVel, float afZVel, float afXPos, float afYPos, float afZPos, \
    int aeMaterial, bool abInitialHit, int aeMotionType)
EndEvent

; Event recieved when this starts hitting a target
Event OnTrapHitStart(ObjectReference akTarget, float afXVel, float afYVel, float afZVel, float afXPos, float afYPos, float afZPos, \
    int aeMaterial, bool abInitialHit, int aeMotionType)
EndEvent

; Event recieved when this stops hitting a target
Event OnTrapHitStop(ObjectReference akTarget)
EndEvent

; Event received when a this trigger is tripped
Event OnTrigger(ObjectReference akActionRef)
EndEvent

; Event received when this trigger volume is entered
Event OnTriggerEnter(ObjectReference akActionRef)
EndEvent

; Event received when this trigger volume is left
Event OnTriggerLeave(ObjectReference akActionRef)
EndEvent

; Event received when this object is unequipped by an actor
Event OnUnequipped(Actor akActor)
EndEvent

; Event recieved when this object is being unloaded - will be fired every time this object is unloaded
Event OnUnload()
EndEvent

; Event that is triggered when this actor's combat state against the target changes
; State is as follows:
; 0 - not in combat
; 1 - in combat
; 2 - searching
Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
EndEvent

; Event that is triggered when this actor sits in the furniture
Event OnSit(ObjectReference akFurniture)
EndEvent

; Event that is triggered when this actor leaves the furniture
Event OnGetUp(ObjectReference akFurniture)
EndEvent

; Event that is triggered when this actor finishes dying
Event OnDeath(Actor akKiller)
EndEvent

; Event that is triggered when this actor begins dying
Event OnDying(Actor akKiller)
EndEvent

; Event that is triggered when this actor changes from one location to another
Event OnLocationChange(Location akOldLoc, Location akNewLoc)
EndEvent

; Event received when this actor equips something - akReference may be None if object is not persistent
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
EndEvent

; Event received when this actor unequips something - akReference may be None if object is not persistent
Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
EndEvent

; Event received when this actor starts a new package
Event OnPackageStart(Package akNewPackage)
EndEvent

; Event received when this actor's package changes
Event OnPackageChange(Package akOldPackage)
EndEvent

; Event received when this actor's package ends
Event OnPackageEnd(Package akOldPackage)
EndEvent

; Event received when this object's Ward is hit by a spell
Event OnWardHit(ObjectReference akCaster, Spell akSpell, int aiStatus)
EndEvent

; Received when the player fires a bow. akWeapon will be a bow, akAmmo is the ammo or None,
; afPower will be 1.0 for a full-power shot, less for a dud, and abSunGazing will be true if the player is looking at the sun.
Event OnPlayerBowShot(Weapon akWeapon, Ammo akAmmo, float afPower, bool abSunGazing)
EndEvent

; Received immediately after the player has loaded a save game. A good time to check for additional content.
Event OnPlayerLoadGame()
EndEvent

(And yes, OnSpellCast() is among these.)

 

The CK wiki also notes this, at the bottom of this page: https://www.creationkit.com/index.php?title=ActiveMagicEffect_Script

 

And so did ReDragon, if you reread their post. I don't know where you got the idea that ActiveMagicEffects can't get Actor events, but it's wrong.

Edited by foamyesque
Link to comment
Share on other sites

 

-snip-

(And yes, OnSpellCast() is among these.)

 

The CK wiki also notes this, at the bottom of this page: https://www.creationkit.com/index.php?title=ActiveMagicEffect_Script

 

And so did ReDragon, if you reread their post. I don't know where you got the idea that ActiveMagicEffects can't get Actor events, but it's wrong.

 

 

I stand corrected. I have no idea why I was thinking that it didn't.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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